diff --git a/src/Cron/cron.service.ts b/src/Cron/cron.service.ts index 5068085..f833c57 100644 --- a/src/Cron/cron.service.ts +++ b/src/Cron/cron.service.ts @@ -165,7 +165,7 @@ export class CronService { Logger.log(`Found ${schedules.length} schedules to check`, 'taskCheckScheduleDateStart') for (const schedule of schedules) { await this.prisma.scheduleDate.updateMany({ - where: { scheduleId: schedule.id, start: { lt: DateTimeUtils.now().plus({ minutes: 30 }).toJSDate() } }, + where: { scheduleId: schedule.id }, data: { status: ScheduleDateStatus.EXPIRED }, }) // update schedule status to expired @@ -183,7 +183,7 @@ export class CronService { 'Lịch hướng dẫn của bạn đã hết hạn', `Lịch hướng dẫn với ngày bắt đầu: ${DateTimeUtils.format( DateTimeUtils.fromDate(schedule.scheduleStart), - 'DD/MM/YYYY', + 'D', )}, slot: ${schedule.slots.map((s) => s).join(', ')} của bạn đã hết hạn do không có học viên đăng ký, vui lòng tạo lịch hướng dẫn mới`, ) } diff --git a/src/Document/document.schema.ts b/src/Document/document.schema.ts index baf30d4..0117cd0 100644 --- a/src/Document/document.schema.ts +++ b/src/Document/document.schema.ts @@ -162,8 +162,12 @@ export class DocumentSchema extends PothosSchema { if (!ctx.http?.me?.id) throw new Error('User not found') if (!args.documentId) throw new Error('Document id not found') if (args.pageIndex === undefined || args.pageIndex === null) throw new Error('Page index not found') - const delta = await this.minio.getDocumentPage(args.documentId, args.pageIndex) - if (!delta) throw new Error('Delta not found') + let delta + try { + delta = await this.minio.getDocumentPage(args.documentId, args.pageIndex) + } catch (_error) { + delta = null + } const totalPage = await this.minio.countDocumentPages(args.documentId) return { documentId: args.documentId, @@ -172,6 +176,7 @@ export class DocumentSchema extends PothosSchema { totalPage, senderId: ctx.http?.me?.id, eventType: DocumentEvent.CLIENT_REQUEST_SYNC, + requestSync: false, } }, }), diff --git a/src/Schedule/schedule.schema.ts b/src/Schedule/schedule.schema.ts index 12df40d..bb3c243 100644 --- a/src/Schedule/schedule.schema.ts +++ b/src/Schedule/schedule.schema.ts @@ -220,10 +220,32 @@ export class ScheduleSchema extends PothosSchema { type: this.schedule(), description: 'Retrieve a single schedule by its unique identifier.', args: this.builder.generator.findUniqueArgs('Schedule'), - resolve: async (query, _root, args, _ctx, _info) => { + resolve: async (query, _root, args, ctx, _info) => { + if (ctx.isSubscription) { + throw new Error('Cannot retrieve schedule in subscription') + } + if (!ctx.http?.me?.id) { + throw new Error('User not found') + } + // only return schedule belong to center + const center = await this.prisma.center.findFirst({ + where: { + centerMentors: { + some: { + mentorId: ctx.http.me.id, + }, + }, + }, + }) + if (!center) { + throw new Error('Center not found') + } return await this.prisma.schedule.findUnique({ ...query, - where: args.where, + where: { + id: args.where?.id, + managedService: { service: { centerId: center.id } }, + }, }) }, }), @@ -300,6 +322,10 @@ d72a864e-2f41-45ab-9c9b-bf0512a31883,e9be51fd-2382-4e43-9988-74e76fde4b56,2024-1 throw new Error('Cannot create schedule in subscription') } Logger.log('args.schedule', args.schedule) + // reject schedule if start date is today or in the past + if (DateTimeUtils.fromDate(args.schedule.scheduleStart as Date).day <= DateTimeUtils.now().day) { + throw new Error('Start date is in the past or today') + } // generate preview and check if there is any overlapping with other schedules date in same service const previewSchedule = await this.scheduleService.createSchedulePreviewForCenter({ startDate: args.schedule.scheduleStart as string,