Skip to content

Commit

Permalink
+
Browse files Browse the repository at this point in the history
  • Loading branch information
Neo-Ryo committed Apr 23, 2024
1 parent 14af65a commit f38a7ae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 5 additions & 1 deletion server/controllers/student.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/components/accueil/Accueil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand All @@ -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;
}, {}),
Expand Down
11 changes: 7 additions & 4 deletions src/pages/familles/1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<FilterArgs>({
selectedType: 0,
Expand Down

0 comments on commit f38a7ae

Please sign in to comment.