From f38a7aef70a7fa02803ddfb53236da89c2d63a35 Mon Sep 17 00:00:00 2001 From: Neo Ryo Date: Tue, 23 Apr 2024 15:57:43 +0200 Subject: [PATCH] + --- server/controllers/student.ts | 6 +++++- src/components/accueil/Accueil.tsx | 4 ++-- src/pages/familles/1.tsx | 11 +++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/server/controllers/student.ts b/server/controllers/student.ts index 53fc9fd3b..2569d10e7 100644 --- a/server/controllers/student.ts +++ b/server/controllers/student.ts @@ -2,6 +2,7 @@ import type { JSONSchemaType } from 'ajv'; import type { NextFunction, Request, Response } from 'express'; import { UserType } from '../../types/user.type'; +import { Classroom } from '../entities/classroom'; import { Student } from '../entities/student'; import { User } from '../entities/user'; import { UserToStudent } from '../entities/userToStudent'; @@ -119,7 +120,10 @@ studentController.post({ path: '', userType: UserType.TEACHER }, async (req: Req throw new AppError('Forbidden', ErrorCode.UNKNOWN); } const student = new Student(); - student.classroom = data.classroomId; + const classroomFound = await AppDataSource.getRepository(Classroom).findOne({ where: { id: data.classroomId } }); + if (classroomFound) { + student.classroom = classroomFound; + } student.firstname = data.firstname ?? null; student.lastname = data.lastname ?? null; student.hashedCode = inviteCodeGenerator(10); diff --git a/src/components/accueil/Accueil.tsx b/src/components/accueil/Accueil.tsx index 3cdd15111..fc0c83c16 100644 --- a/src/components/accueil/Accueil.tsx +++ b/src/components/accueil/Accueil.tsx @@ -28,7 +28,7 @@ export const Accueil = () => { if (!village || (selectedPhase === 1 && !isMediator)) { return user?.country ? [user?.country] : []; } else { - return village.countries; + return village.countries ?? []; } }, [selectedPhase, village, user, isMediator]); @@ -40,7 +40,7 @@ export const Accueil = () => { selectedPhase: 0, types: 'all', status: 0, - countries: filterCountries.reduce<{ [key: string]: boolean }>((acc, c) => { + countries: filterCountries?.reduce<{ [key: string]: boolean }>((acc, c) => { acc[c.isoCode] = true; return acc; }, {}), diff --git a/src/pages/familles/1.tsx b/src/pages/familles/1.tsx index 5a25e9e7c..69456f2c6 100644 --- a/src/pages/familles/1.tsx +++ b/src/pages/familles/1.tsx @@ -114,10 +114,13 @@ const ClassroomParamStep1 = () => { user !== null && (user.type === UserType.MEDIATOR || user.type === UserType.ADMIN || user.type === UserType.SUPER_ADMIN || user.type === UserType.FAMILY); - const filterCountries: Country[] = React.useMemo( - () => (!village || (selectedPhase === 1 && !isMediatorOrFamily) ? (user && user.country !== null ? [user.country] : []) : village.countries), - [selectedPhase, village, user, isMediatorOrFamily], - ); + const filterCountries: Country[] = React.useMemo(() => { + if (!village || (selectedPhase === 1 && !isMediatorOrFamily)) { + return user && user.country && user.country !== null ? [user.country] : []; + } else { + return village.countries; + } + }, [selectedPhase, village, user, isMediatorOrFamily]); const [filters, setFilters] = React.useState({ selectedType: 0,