Skip to content

Commit

Permalink
[Faculties] Only send relevant fields to frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
rikurauhala committed Dec 2, 2024
1 parent 32cf9ed commit ec9b0b2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions services/backend/src/routes/faculties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getDegreeProgrammesOfFaculty, getFacultyCodeById } from '../services/fa
import { combineFacultyBasics } from '../services/faculty/facultyBasics'
import { getFacultyCredits } from '../services/faculty/facultyCredits'
import { countGraduationTimes } from '../services/faculty/facultyGraduationTimes'
import { getSortedFaculties } from '../services/faculty/facultyHelpers'
import { getFacultiesForFacultyList } from '../services/faculty/facultyHelpers'
import {
getBasicStats,
setBasicStats,
Expand All @@ -31,7 +31,7 @@ import logger from '../util/logger'
const router = Router()

router.get('/', async (_req: Request, res: Response) => {
const faculties = await getSortedFaculties()
const faculties = await getFacultiesForFacultyList()
res.json(faculties)
})

Expand Down
9 changes: 9 additions & 0 deletions services/backend/src/services/faculty/facultyHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ export const getSortedFaculties = async () => {
return nameA.localeCompare(nameB)
})
}

export const getFacultiesForFacultyList = async () => {
const faculties = await getSortedFaculties()
return faculties.map(faculty => ({
code: faculty.code,
id: faculty.id,
name: faculty.name,
}))
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Box } from '@mui/material'

import { AllGraduationStatsResponse } from '@/shared/types'
import { GetAllGraduationStatsResponse } from '@/shared/types/api/university'
import { GraduationTimes } from './GraduationTimes'

export const FacultyGraduations = ({
Expand All @@ -11,7 +11,7 @@ export const FacultyGraduations = ({
showMedian,
universityMode,
}: {
data: AllGraduationStatsResponse | undefined
data: GetAllGraduationStatsResponse | undefined
isError: boolean
isLoading: boolean
faculty?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { calculateStats, sortProgrammeKeys } from '@/components/FacultyStatistic
import { FacultyBarChart } from '@/components/material/FacultyBarChart'
import { FacultyProgressTable } from '@/components/material/FacultyProgressTable'
import { Section } from '@/components/material/Section'
import { AllProgressStatsResponse } from '@/shared/types/api/faculty'
import { GetAllProgressStatsResponse } from '@/shared/types/api/faculty'

export const FacultyProgress = ({
faculty,
Expand All @@ -16,7 +16,7 @@ export const FacultyProgress = ({
faculty: string
isError: boolean
isLoading: boolean
progressStats: AllProgressStatsResponse | undefined
progressStats: GetAllProgressStatsResponse | undefined
}) => {
const creditCounts = progressStats?.creditCounts

Expand Down
14 changes: 9 additions & 5 deletions services/frontend/src/redux/facultyStats.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { RTKApi } from '@/apiConnection'
import { AllProgressStatsRequest, AllProgressStatsResponse } from '@/shared/types/api/faculty'
import { AllGraduationStatsResponse } from '@/shared/types/api/university'
import {
GetAllProgressStatsRequest,
GetAllProgressStatsResponse,
GetFacultiesResponse,
} from '@/shared/types/api/faculty'
import { GetAllGraduationStatsResponse } from '@/shared/types/api/university'

const facultystatsApi = RTKApi.injectEndpoints({
endpoints: builder => ({
getFaculties: builder.query({
getFaculties: builder.query<GetFacultiesResponse[], void>({
query: () => '/faculties',
keepUnusedDataFor: 24 * 60 * 60, // 24 hours
}),
Expand All @@ -27,11 +31,11 @@ const facultystatsApi = RTKApi.injectEndpoints({
query: ({ id, specialGroups, graduated }) =>
`/faculties/${id}/progressstats?special_groups=${specialGroups}&graduated=${graduated}`,
}),
getAllFacultiesProgressStats: builder.query<AllProgressStatsResponse, AllProgressStatsRequest>({
getAllFacultiesProgressStats: builder.query<GetAllProgressStatsResponse, GetAllProgressStatsRequest>({
query: ({ graduated, includeSpecials }) =>
`/university/allprogressstats?graduated=${graduated}&specialsIncluded=${includeSpecials}`,
}),
getAllFacultiesGraduationStats: builder.query<AllGraduationStatsResponse, void>({
getAllFacultiesGraduationStats: builder.query<GetAllGraduationStatsResponse, void>({
query: () => '/university/allgraduationstats',
}),
getFacultyStudentStats: builder.query({
Expand Down
3 changes: 0 additions & 3 deletions services/shared/types/api/faculty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import { Name, NameWithCode } from '../name'

export interface GetFacultiesResponse {
code: string
createdAt: string
id: string
name: Name
parent_id: string
updatedAt: string
}

export interface GetAllProgressStatsRequest {
Expand Down

0 comments on commit ec9b0b2

Please sign in to comment.