From ec9b0b22b0a92536fdfeea95788d2f9d91d7b527 Mon Sep 17 00:00:00 2001 From: Riku Rauhala Date: Mon, 2 Dec 2024 10:41:02 +0200 Subject: [PATCH] [Faculties] Only send relevant fields to frontend --- services/backend/src/routes/faculties.ts | 4 ++-- .../backend/src/services/faculty/facultyHelpers.ts | 9 +++++++++ .../material/FacultyGraduations/index.tsx | 4 ++-- .../components/material/FacultyProgress/index.tsx | 4 ++-- services/frontend/src/redux/facultyStats.ts | 14 +++++++++----- services/shared/types/api/faculty.ts | 3 --- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/services/backend/src/routes/faculties.ts b/services/backend/src/routes/faculties.ts index e086654428..127c80b113 100644 --- a/services/backend/src/routes/faculties.ts +++ b/services/backend/src/routes/faculties.ts @@ -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, @@ -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) }) diff --git a/services/backend/src/services/faculty/facultyHelpers.ts b/services/backend/src/services/faculty/facultyHelpers.ts index cdee6b0507..98f1d0244e 100644 --- a/services/backend/src/services/faculty/facultyHelpers.ts +++ b/services/backend/src/services/faculty/facultyHelpers.ts @@ -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, + })) +} diff --git a/services/frontend/src/components/material/FacultyGraduations/index.tsx b/services/frontend/src/components/material/FacultyGraduations/index.tsx index c80ceba9fa..1f0c2d69ae 100644 --- a/services/frontend/src/components/material/FacultyGraduations/index.tsx +++ b/services/frontend/src/components/material/FacultyGraduations/index.tsx @@ -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 = ({ @@ -11,7 +11,7 @@ export const FacultyGraduations = ({ showMedian, universityMode, }: { - data: AllGraduationStatsResponse | undefined + data: GetAllGraduationStatsResponse | undefined isError: boolean isLoading: boolean faculty?: string diff --git a/services/frontend/src/components/material/FacultyProgress/index.tsx b/services/frontend/src/components/material/FacultyProgress/index.tsx index b02b914f7a..30bebfd708 100644 --- a/services/frontend/src/components/material/FacultyProgress/index.tsx +++ b/services/frontend/src/components/material/FacultyProgress/index.tsx @@ -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, @@ -16,7 +16,7 @@ export const FacultyProgress = ({ faculty: string isError: boolean isLoading: boolean - progressStats: AllProgressStatsResponse | undefined + progressStats: GetAllProgressStatsResponse | undefined }) => { const creditCounts = progressStats?.creditCounts diff --git a/services/frontend/src/redux/facultyStats.ts b/services/frontend/src/redux/facultyStats.ts index 393ee48798..bf17ca9639 100644 --- a/services/frontend/src/redux/facultyStats.ts +++ b/services/frontend/src/redux/facultyStats.ts @@ -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({ query: () => '/faculties', keepUnusedDataFor: 24 * 60 * 60, // 24 hours }), @@ -27,11 +31,11 @@ const facultystatsApi = RTKApi.injectEndpoints({ query: ({ id, specialGroups, graduated }) => `/faculties/${id}/progressstats?special_groups=${specialGroups}&graduated=${graduated}`, }), - getAllFacultiesProgressStats: builder.query({ + getAllFacultiesProgressStats: builder.query({ query: ({ graduated, includeSpecials }) => `/university/allprogressstats?graduated=${graduated}&specialsIncluded=${includeSpecials}`, }), - getAllFacultiesGraduationStats: builder.query({ + getAllFacultiesGraduationStats: builder.query({ query: () => '/university/allgraduationstats', }), getFacultyStudentStats: builder.query({ diff --git a/services/shared/types/api/faculty.ts b/services/shared/types/api/faculty.ts index 49a2fe020d..d6f1571238 100644 --- a/services/shared/types/api/faculty.ts +++ b/services/shared/types/api/faculty.ts @@ -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 {