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 { LiveKitRoomService } from 'src/LiveKit/livekit.room.service'
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
import { Role } from '@prisma/client' import { Role } from '@prisma/client'
import { DateTimeUtils } from 'src/common/utils/datetime.utils'
@Injectable() @Injectable()
export class CollaborationSessionSchema extends PothosSchema { export class CollaborationSessionSchema extends PothosSchema {
constructor( constructor(
@@ -89,13 +90,11 @@ export class CollaborationSessionSchema extends PothosSchema {
throw new Error('Schedule date ID is required') throw new Error('Schedule date ID is required')
if (ctx.http.me?.role !== Role.CENTER_MENTOR) if (ctx.http.me?.role !== Role.CENTER_MENTOR)
throw new Error('User not allowed') throw new Error('User not allowed')
const scheduleDate = await this.prisma.scheduleDate.findUniqueOrThrow( const scheduleDate = await this.prisma.scheduleDate.findUnique({
{ where: {
where: { id: args.scheduleDateId,
id: args.scheduleDateId,
},
}, },
) })
if (!scheduleDate) throw new Error('Schedule date not found') if (!scheduleDate) throw new Error('Schedule date not found')
// check if order is exist in schedule date // check if order is exist in schedule date
if (!scheduleDate.orderId) throw new Error('Order not found') 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) throw new Error('Order not found')
if (!order.chatRoomId) throw new Error('Order chat room 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) { if (!collaborationSession) {
const chatRoom = await this.prisma.chatRoom.findUnique({ const chatRoom = await this.prisma.chatRoom.findUnique({
where: { where: {
@@ -128,6 +138,18 @@ export class CollaborationSessionSchema extends PothosSchema {
chatRoomId: order.chatRoomId, 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 newCollaborationSession // if not exist use case
} }
return collaborationSession // if exist use case return collaborationSession // if exist use case

View File

@@ -104,7 +104,7 @@ export class PayosService {
mentorId: mentorId, mentorId: mentorId,
}, },
}) })
// update order chatRoomId /* ------------------------- update order chatRoomId ------------------------ */
await tx.order.update({ await tx.order.update({
where: { id: order.id }, where: { id: order.id },
data: { data: {
@@ -118,7 +118,7 @@ export class PayosService {
orderId: order.id, orderId: order.id,
}, },
}) })
// send first message from mentor to customer /* --------------- send first message from mentor to customer --------------- */
await tx.message.create({ await tx.message.create({
data: { data: {
content: content: