update some complex logic
This commit is contained in:
@@ -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,
|
||||
},
|
||||
})
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user