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 --------- */ /* ---------- use case 1 : customer get collaboration session by id --------- */
if (ctx.http.me?.role === Role.CUSTOMER && collaborationSession) { 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 // check if user is participant
if (!collaborationSession.collaboratorsIds.includes(ctx.http.me.id)) throw new Error('User not allowed') 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 return collaborationSession
} }
/* ---------- use case 2 : center mentor get collaboration session by schedule date id --------- */ /* ---------- use case 2 : center mentor get collaboration session by schedule date id --------- */
@@ -150,6 +146,15 @@ export class CollaborationSessionSchema extends PothosSchema {
collaboratorsIds: [...scheduleDate.participantIds], 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 // case after start time and before end time, mark as late
if (now > startTime && now < endTime) { if (now > startTime && now < endTime) {
// mark as late // mark as late

View File

@@ -20,7 +20,7 @@ export class CronService {
const schedules = await this.prisma.scheduleDate.findMany({ const schedules = await this.prisma.scheduleDate.findMany({
where: { where: {
end: { end: {
lt: DateTimeUtils.now().toJSDate(), lt: DateTimeUtils.now().toJSDate(), // past
}, },
status: { status: {
notIn: [ScheduleDateStatus.COMPLETED, ScheduleDateStatus.MISSING_MENTOR, ScheduleDateStatus.MISSING_CUSTOMER], notIn: [ScheduleDateStatus.COMPLETED, ScheduleDateStatus.MISSING_MENTOR, ScheduleDateStatus.MISSING_CUSTOMER],
@@ -48,12 +48,12 @@ export class CronService {
} }
} }
if (collaborationSession.collaboratorsIds.length === 1) { // if (collaborationSession.collaboratorsIds.length === 1) {
return { // return {
id: schedule.id, // id: schedule.id,
status: ScheduleDateStatus.MISSING_CUSTOMER, // status: ScheduleDateStatus.MISSING_CUSTOMER,
} // }
} // }
if (collaborationSession.collaboratorsIds.length === 2) { if (collaborationSession.collaboratorsIds.length === 2) {
return { return {