database bi kiet pha banh roi

This commit is contained in:
2024-11-25 14:17:32 +07:00
parent 9515a3d9b3
commit 28d0374435
6 changed files with 55 additions and 60 deletions

View File

@@ -9,7 +9,7 @@ import { Builder } from '../Graphql/graphql.builder'
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 { CollaborationSession, Role } from '@prisma/client'
import { DateTimeUtils } from 'src/common/utils/datetime.utils'
@Injectable()
export class CollaborationSessionSchema extends PothosSchema {
@@ -75,35 +75,31 @@ export class CollaborationSessionSchema extends PothosSchema {
'Retrieve a single collaboration session by its unique identifier.',
resolve: async (_query, _root, args, ctx, _info) => {
if (ctx.isSubscription) throw new Error('Not allowed')
/* ---------- use case 1 : customer get collaboration session by id --------- */
if (args.scheduleDateId && ctx.http.me?.role === Role.CUSTOMER) {
if (!args.scheduleDateId)
throw new Error('Schedule date ID is required')
return await this.prisma.collaborationSession.findUniqueOrThrow({
where: {
scheduleDateId: args.scheduleDateId,
},
})
}
/* ---------- use case 2 : center mentor get collaboration session by schedule date id --------- */
if (!args.scheduleDateId)
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.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')
const collaborationSession =
await this.prisma.collaborationSession.findUnique({
let collaborationSession: CollaborationSession | null = null
collaborationSession =
await this.prisma.collaborationSession.findUniqueOrThrow({
where: {
scheduleDateId: scheduleDate.id,
},
})
/* ---------- use case 1 : customer get collaboration session by id --------- */
if (ctx.http.me?.role === Role.CUSTOMER && collaborationSession) {
if (scheduleDate.participantIds.includes(ctx.http.me?.id)) {
return collaborationSession
}
throw new Error('User not allowed')
}
/* ---------- use case 2 : center mentor get collaboration session by schedule date id --------- */
if (ctx.http.me?.role !== Role.CENTER_MENTOR)
throw new Error('Mentor does not created collaboration session yet')
// check if order is exist in schedule date
if (!scheduleDate.orderId) throw new Error('Order not found')
const order = await this.prisma.order.findUnique({
where: {
id: scheduleDate.orderId,