database bi kiet pha banh roi
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -85,6 +85,9 @@ export class PayosService {
|
||||
status: ScheduleStatus.IN_PROGRESS,
|
||||
},
|
||||
})
|
||||
if (!schedule) {
|
||||
throw new Error('Schedule not found')
|
||||
}
|
||||
// get mentor id from managed service
|
||||
const managedService = await tx.managedService.findUniqueOrThrow({
|
||||
where: { id: schedule?.managedServiceId },
|
||||
@@ -111,13 +114,18 @@ export class PayosService {
|
||||
chatRoomId: chatRoom.id,
|
||||
},
|
||||
})
|
||||
// update orderId for schedule dates
|
||||
// add participants to schedule dates where customer and mentor are
|
||||
const customerId = order.userId
|
||||
|
||||
// update orderId
|
||||
await tx.scheduleDate.updateMany({
|
||||
where: { scheduleId: schedule?.id },
|
||||
where: { scheduleId: schedule.id },
|
||||
data: {
|
||||
orderId: order.id,
|
||||
participantIds: [customerId, mentorId],
|
||||
},
|
||||
})
|
||||
|
||||
/* --------------- send first message from mentor to customer --------------- */
|
||||
await tx.message.create({
|
||||
data: {
|
||||
|
||||
1
src/Schedule/schedule.d.ts
vendored
1
src/Schedule/schedule.d.ts
vendored
@@ -5,6 +5,7 @@ export interface ScheduleDateInput {
|
||||
dayOfWeek: number
|
||||
slot: number
|
||||
serviceId: string
|
||||
participants: string[]
|
||||
orderId: string | null
|
||||
}
|
||||
|
||||
|
||||
@@ -146,6 +146,20 @@ export class ScheduleSchema extends PothosSchema {
|
||||
orderId: t.exposeID('orderId', {
|
||||
nullable: true,
|
||||
}),
|
||||
participantIds: t.exposeStringList('participantIds', {
|
||||
nullable: false,
|
||||
}),
|
||||
maxParticipants: t.exposeInt('maxParticipants', {
|
||||
nullable: false,
|
||||
}),
|
||||
lateStart: t.expose('lateStart', {
|
||||
type: 'DateTime',
|
||||
nullable: true,
|
||||
}),
|
||||
collaborationSession: t.relation('CollaborationSession', {
|
||||
description: 'The collaboration session of the schedule date.',
|
||||
nullable: true,
|
||||
}),
|
||||
schedule: t.relation('schedule', {
|
||||
description: 'The schedule the schedule date belongs to.',
|
||||
}),
|
||||
|
||||
@@ -68,7 +68,7 @@ export class ScheduleService {
|
||||
const scheduleEnd = DateTime.fromJSDate(schedule.scheduleEnd)
|
||||
const slotDuration = parseInt(config.slotDuration)
|
||||
const slotBreakDuration = parseInt(config.slotBreakDuration)
|
||||
|
||||
// add participants to schedule dates
|
||||
const scheduleDates: ScheduleDateInput[] = []
|
||||
|
||||
// loop each day from scheduleStart to scheduleEnd
|
||||
@@ -96,6 +96,7 @@ export class ScheduleService {
|
||||
end: endTime.toISO() ?? '',
|
||||
dayOfWeek: date.weekday,
|
||||
slot: slot,
|
||||
participants: [],
|
||||
serviceId: schedule.managedServiceId,
|
||||
orderId: schedule.orderId,
|
||||
})
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user