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.
This commit is contained in:
2024-12-07 16:28:44 +07:00
parent 77e3526564
commit d59df7d2ab
2 changed files with 25 additions and 20 deletions

View File

@@ -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