bling bling

This commit is contained in:
2024-11-25 19:46:23 +07:00
parent c063f1a10e
commit 84a09375da
6 changed files with 152 additions and 39 deletions

View File

@@ -30,33 +30,43 @@ export class CronService {
`Found ${schedules.length} schedules to update`,
'checkScheduleDateStatus',
)
// get all collaboration sessions
const collaborationSessions =
await this.prisma.collaborationSession.findMany({
where: {
collaboratorsIds: {
hasEvery: schedules.map((s) => s.id),
},
},
})
const updates = schedules
.map((schedule) => {
if (schedule.status === ScheduleDateStatus.NOT_STARTED) {
const collaborationSession = collaborationSessions.find(
(session) => session.scheduleDateId === schedule.id,
)
if (!collaborationSession) {
return {
id: schedule.id,
status: ScheduleDateStatus.MISSING_MENTOR,
}
}
if (
schedule.status === ScheduleDateStatus.IN_PROGRESS &&
schedule.participantIds.length === 1
) {
if (collaborationSession.collaboratorsIds.length === 1) {
return {
id: schedule.id,
status: ScheduleDateStatus.MISSING_CUSTOMER,
}
}
if (
schedule.status === ScheduleDateStatus.IN_PROGRESS &&
schedule.participantIds.length === 2
) {
if (collaborationSession.collaboratorsIds.length === 2) {
return {
id: schedule.id,
status: ScheduleDateStatus.COMPLETED,
}
}
return null
})
.filter((update) => update !== null)