From d59df7d2ab034892b82e3a7fef4dd2b827436336 Mon Sep 17 00:00:00 2001 From: Ly Tuan Kiet Date: Sat, 7 Dec 2024 16:28:44 +0700 Subject: [PATCH] feat: update collaboration session handling and schedule date status - Removed redundant code for adding current user ID to collaborators in collaboration sessions. - Implemented updates to schedule date status based on collaboration session conditions, enhancing the workflow for both customers and mentors. - Improved error handling to ensure only authorized users can access collaboration sessions, maintaining data integrity and user experience. --- .../collaborationsession.schema.ts | 31 +++++++++++-------- src/Cron/cron.service.ts | 14 ++++----- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/CollaborationSession/collaborationsession.schema.ts b/src/CollaborationSession/collaborationsession.schema.ts index edb48ac..649b007 100644 --- a/src/CollaborationSession/collaborationsession.schema.ts +++ b/src/CollaborationSession/collaborationsession.schema.ts @@ -89,21 +89,17 @@ export class CollaborationSessionSchema extends PothosSchema { }) /* ---------- use case 1 : customer get collaboration session by id --------- */ if (ctx.http.me?.role === Role.CUSTOMER && collaborationSession) { - // if collaboratorsIds not include current user id, add it - // if (!collaborationSession.collaboratorsIds.includes(ctx.http.me?.id)) { - // collaborationSession.collaboratorsIds.push(ctx.http.me?.id) - // await this.prisma.collaborationSession.update({ - // where: { - // id: collaborationSession.id, - // }, - // data: { - // collaboratorsIds: collaborationSession.collaboratorsIds, - // }, - // }) - // } - // check if user is participant if (!collaborationSession.collaboratorsIds.includes(ctx.http.me.id)) throw new Error('User not allowed') + // update schedule date status + await this.prisma.scheduleDate.update({ + where: { + id: scheduleDate.id, + }, + data: { + status: ScheduleDateStatus.IN_PROGRESS, + }, + }) return collaborationSession } /* ---------- use case 2 : center mentor get collaboration session by schedule date id --------- */ @@ -150,6 +146,15 @@ export class CollaborationSessionSchema extends PothosSchema { collaboratorsIds: [...scheduleDate.participantIds], }, }) + // update schedule date status + await this.prisma.scheduleDate.update({ + where: { + id: scheduleDate.id, + }, + data: { + status: ScheduleDateStatus.MISSING_CUSTOMER, + }, + }) // case after start time and before end time, mark as late if (now > startTime && now < endTime) { // mark as late diff --git a/src/Cron/cron.service.ts b/src/Cron/cron.service.ts index 7f650a1..8e8628b 100644 --- a/src/Cron/cron.service.ts +++ b/src/Cron/cron.service.ts @@ -20,7 +20,7 @@ export class CronService { const schedules = await this.prisma.scheduleDate.findMany({ where: { end: { - lt: DateTimeUtils.now().toJSDate(), + lt: DateTimeUtils.now().toJSDate(), // past }, status: { notIn: [ScheduleDateStatus.COMPLETED, ScheduleDateStatus.MISSING_MENTOR, ScheduleDateStatus.MISSING_CUSTOMER], @@ -48,12 +48,12 @@ export class CronService { } } - if (collaborationSession.collaboratorsIds.length === 1) { - return { - id: schedule.id, - status: ScheduleDateStatus.MISSING_CUSTOMER, - } - } + // if (collaborationSession.collaboratorsIds.length === 1) { + // return { + // id: schedule.id, + // status: ScheduleDateStatus.MISSING_CUSTOMER, + // } + // } if (collaborationSession.collaboratorsIds.length === 2) { return {