update some complex logic

This commit is contained in:
2024-11-24 22:25:14 +07:00
parent edcd340d0b
commit 68dabd186a
6 changed files with 141 additions and 24 deletions

View File

@@ -46,14 +46,34 @@ export class MeetingRoomSchema extends PothosSchema {
@Pothos()
init(): void {
this.builder.queryFields((t) => ({
// get meeting room by collaboration session id if exist or create new one
meetingRoom: t.prismaField({
type: this.meetingRoom(),
args: this.builder.generator.findUniqueArgs('MeetingRoom'),
resolve: async (query, _parent, args, ctx: SchemaContext) => {
args: {
scheduleDateId: t.arg.string({
required: true,
}),
},
resolve: async (_query, _parent, args, ctx: SchemaContext) => {
if (ctx.isSubscription) throw new Error('Not allowed')
return await this.prisma.meetingRoom.findUnique({
...query,
where: args.where,
const collaborationSession =
await this.prisma.collaborationSession.findUnique({
where: {
scheduleDateId: args.scheduleDateId,
},
})
if (!collaborationSession)
throw new Error('Collaboration session not found')
const meetingRoom = await this.prisma.meetingRoom.findUnique({
where: {
collaborationSessionId: collaborationSession.id,
},
})
if (meetingRoom) return meetingRoom
return await this.prisma.meetingRoom.create({
data: {
collaborationSessionId: collaborationSession.id,
},
})
},
}),