From 9515a3d9b314e0ae3fba2da32fa9ce5b9949621a Mon Sep 17 00:00:00 2001 From: Ly Tuan Kiet Date: Mon, 25 Nov 2024 12:18:33 +0700 Subject: [PATCH] so can tell me sth? --- .../collaborationsession.schema.ts | 34 +++++++++++++++---- src/Payos/payos.service.ts | 4 +-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/CollaborationSession/collaborationsession.schema.ts b/src/CollaborationSession/collaborationsession.schema.ts index 9f0af79..2eeaf32 100644 --- a/src/CollaborationSession/collaborationsession.schema.ts +++ b/src/CollaborationSession/collaborationsession.schema.ts @@ -10,6 +10,7 @@ import { PrismaService } from '../Prisma/prisma.service' // import { LiveKitRoomService } from 'src/LiveKit/livekit.room.service' import { v4 as uuidv4 } from 'uuid' import { Role } from '@prisma/client' +import { DateTimeUtils } from 'src/common/utils/datetime.utils' @Injectable() export class CollaborationSessionSchema extends PothosSchema { constructor( @@ -89,13 +90,11 @@ export class CollaborationSessionSchema extends PothosSchema { throw new Error('Schedule date ID is required') if (ctx.http.me?.role !== Role.CENTER_MENTOR) throw new Error('User not allowed') - const scheduleDate = await this.prisma.scheduleDate.findUniqueOrThrow( - { - where: { - id: args.scheduleDateId, - }, + const scheduleDate = await this.prisma.scheduleDate.findUnique({ + where: { + id: args.scheduleDateId, }, - ) + }) if (!scheduleDate) throw new Error('Schedule date not found') // check if order is exist in schedule date if (!scheduleDate.orderId) throw new Error('Order not found') @@ -112,6 +111,17 @@ export class CollaborationSessionSchema extends PothosSchema { }) if (!order) throw new Error('Order not found') if (!order.chatRoomId) throw new Error('Order chat room not found') + // only in time before 10 minutes from start time or less and not after end time can create new collaboration session + const now = DateTimeUtils.now() + const startTime = DateTimeUtils.fromDate(scheduleDate.start) + const endTime = DateTimeUtils.fromDate(scheduleDate.end) + /* ----------------------- disabled in development mode ---------------------- */ + // if ( + // now.diff(startTime, 'minutes').minutes > 10 || // before start time 10 minutes + // now > endTime // after end time + // ) { + // throw new Error('Collaboration session not allowed in this time') + // } if (!collaborationSession) { const chatRoom = await this.prisma.chatRoom.findUnique({ where: { @@ -128,6 +138,18 @@ export class CollaborationSessionSchema extends PothosSchema { chatRoomId: order.chatRoomId, }, }) + // case after start time and before end time, mark as late + if (now > startTime && now < endTime) { + // mark as late + await this.prisma.scheduleDate.update({ + where: { + id: scheduleDate.id, + }, + data: { + lateStart: DateTimeUtils.now().toJSDate(), + }, + }) + } return newCollaborationSession // if not exist use case } return collaborationSession // if exist use case diff --git a/src/Payos/payos.service.ts b/src/Payos/payos.service.ts index d900c71..fa51596 100644 --- a/src/Payos/payos.service.ts +++ b/src/Payos/payos.service.ts @@ -104,7 +104,7 @@ export class PayosService { mentorId: mentorId, }, }) - // update order chatRoomId + /* ------------------------- update order chatRoomId ------------------------ */ await tx.order.update({ where: { id: order.id }, data: { @@ -118,7 +118,7 @@ export class PayosService { orderId: order.id, }, }) - // send first message from mentor to customer + /* --------------- send first message from mentor to customer --------------- */ await tx.message.create({ data: { content: