feat: add scheduled quiz notification task and enhance Quiz schema with scheduleId

- Introduced a new cron job in CronService to check for schedules with status WAITING_QUIZ and notify customers to complete their quizzes.
- Enhanced the Quiz schema by adding an optional 'scheduleId' argument to facilitate quiz retrieval based on specific schedules, improving user experience and data association.
- Updated role-based access control logic to ensure proper handling of quiz queries for customers and center mentors.
This commit is contained in:
2024-12-09 18:35:01 +07:00
parent 5ab89d5cfa
commit e3a06f1ba9
2 changed files with 62 additions and 14 deletions

View File

@@ -219,4 +219,28 @@ export class CronService {
Logger.log(`Service ${service.id} has been disabled`, 'CronService')
}
}
@Cron(CronExpression.EVERY_4_HOURS)
async taskCheckQuiz() {
// check all schedule have status WAITING_QUIZ and notify customer to do quiz
Logger.log('Checking quiz', 'CronService')
const schedules = await this.prisma.schedule.findMany({
where: {
status: ScheduleStatus.WAITING_QUIZ,
},
})
for (const schedule of schedules) {
if (!schedule.customerId) {
continue
}
await this.notificationService.sendNotification(
schedule.customerId,
'Bạn có lịch hướng dẫn cần hoàn thành bài kiểm tra',
`Lịch hướng dẫn với ngày bắt đầu: ${DateTimeUtils.format(
DateTimeUtils.fromDate(schedule.scheduleStart),
'D',
)}, slot: ${schedule.slots.map((s) => s).join(', ')} của bạn đã được đăng ký, vui lòng hoàn thành bài kiểm tra để tiếp tục`,
)
}
}
}