so can tell me sth?

This commit is contained in:
2024-11-25 12:18:33 +07:00
parent 68dabd186a
commit 9515a3d9b3
2 changed files with 30 additions and 8 deletions

View File

@@ -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