From 29413f1930088665ffe5636c50f9fd5b2a473c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikolas=20G=C3=B6rlitz?= Date: Wed, 16 Aug 2023 20:25:51 +0200 Subject: [PATCH] more suitable solution & fixes to course withdrawal --- .../course/CourseInformationController.ts | 2 +- .../TrainingRequestAdminController.ts | 10 +++++----- .../training-session/TrainingSessionController.ts | 12 +++++++++++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/controllers/course/CourseInformationController.ts b/src/controllers/course/CourseInformationController.ts index 880ab6c..bcd7eee 100644 --- a/src/controllers/course/CourseInformationController.ts +++ b/src/controllers/course/CourseInformationController.ts @@ -104,7 +104,7 @@ async function getCourseTrainingInformationByUUID(request: Request, response: Re { association: User.associations.training_sessions, through: { - as: 'single_user_through', + as: "training_session_belongs_to_users", attributes: ["passed", "log_id"], where: { user_id: user.id, diff --git a/src/controllers/training-request/TrainingRequestAdminController.ts b/src/controllers/training-request/TrainingRequestAdminController.ts index d83ec67..2f45ac4 100644 --- a/src/controllers/training-request/TrainingRequestAdminController.ts +++ b/src/controllers/training-request/TrainingRequestAdminController.ts @@ -67,7 +67,7 @@ async function getPlanned(request: Request, response: Response) { where: { [Op.or]: { mentor_id: user.id, - cpt_examiner_id: user.id + cpt_examiner_id: user.id, }, }, include: [ @@ -75,9 +75,9 @@ async function getPlanned(request: Request, response: Response) { TrainingSession.associations.training_type, { association: TrainingSession.associations.training_session_belongs_to_users, - attributes: ['passed'] - } - ] + attributes: ["passed"], + }, + ], }); /* @@ -98,7 +98,7 @@ async function getPlanned(request: Request, response: Response) { } return hasOneNonPassed; - }) + }); response.send(trainingSession); } diff --git a/src/controllers/training-session/TrainingSessionController.ts b/src/controllers/training-session/TrainingSessionController.ts index ceb6f96..223f9d1 100644 --- a/src/controllers/training-session/TrainingSessionController.ts +++ b/src/controllers/training-session/TrainingSessionController.ts @@ -47,7 +47,17 @@ async function getByUUID(request: Request, response: Response) { return; } - response.send(session); + const requestingUserPassed = await TrainingSessionBelongsToUsers.findOne({ + where: { + user_id: user.id, + training_session_id: session.id, + }, + }); + + response.send({ + ...session.toJSON(), + user_passed: requestingUserPassed == null ? null : requestingUserPassed.passed, + }); } async function withdrawFromSessionByUUID(request: Request, response: Response) {