update api
This commit is contained in:
80
src/MeetingRoom/meetingroom.schema.ts
Normal file
80
src/MeetingRoom/meetingroom.schema.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { Inject, Injectable } from '@nestjs/common'
|
||||
import {
|
||||
Pothos,
|
||||
PothosRef,
|
||||
PothosSchema,
|
||||
SchemaBuilderToken,
|
||||
} from '@smatch-corp/nestjs-pothos'
|
||||
import { Builder, SchemaContext } from 'src/Graphql/graphql.builder'
|
||||
import { PrismaService } from 'src/Prisma/prisma.service'
|
||||
|
||||
@Injectable()
|
||||
export class MeetingRoomSchema extends PothosSchema {
|
||||
constructor(
|
||||
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||
private readonly prisma: PrismaService,
|
||||
) {
|
||||
super()
|
||||
}
|
||||
@PothosRef()
|
||||
meetingRoom() {
|
||||
return this.builder.prismaObject('MeetingRoom', {
|
||||
fields: (t) => ({
|
||||
id: t.exposeID('id'),
|
||||
collaborationSessionId: t.exposeString('collaborationSessionId'),
|
||||
collaborationSession: t.relation('collaborationSession'),
|
||||
collaborators: t.relation('collaborators'),
|
||||
createdAt: t.expose('createdAt', { type: 'DateTime' }),
|
||||
updatedAt: t.expose('updatedAt', { type: 'DateTime' }),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
meetingRoomCollaborator() {
|
||||
return this.builder.prismaObject('MeetingRoomCollaborator', {
|
||||
fields: (t) => ({
|
||||
id: t.exposeID('id'),
|
||||
meetingRoomId: t.exposeString('meetingRoomId'),
|
||||
meetingRoom: t.relation('meetingRoom'),
|
||||
userId: t.exposeString('userId'),
|
||||
user: t.relation('user'),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
@Pothos()
|
||||
init(): void {
|
||||
this.builder.queryFields((t) => ({
|
||||
meetingRoom: t.prismaField({
|
||||
type: this.meetingRoom(),
|
||||
args: this.builder.generator.findUniqueArgs('MeetingRoom'),
|
||||
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,
|
||||
})
|
||||
},
|
||||
}),
|
||||
}))
|
||||
this.builder.mutationFields((t) => ({
|
||||
createMeetingRoom: t.prismaField({
|
||||
type: this.meetingRoom(),
|
||||
args: {
|
||||
input: t.arg({
|
||||
type: this.builder.generator.getCreateInput('MeetingRoom'),
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
resolve: async (query, _parent, args, ctx: SchemaContext) => {
|
||||
if (ctx.isSubscription) throw new Error('Not allowed')
|
||||
return await this.prisma.meetingRoom.create({
|
||||
...query,
|
||||
data: args.input,
|
||||
})
|
||||
},
|
||||
}),
|
||||
}))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user