update api

This commit is contained in:
2024-11-24 15:12:05 +07:00
parent ccfe7bf1f1
commit 675460c39c
12 changed files with 234 additions and 45 deletions

View File

@@ -0,0 +1,121 @@
import { Inject, Injectable } from '@nestjs/common'
import {
Pothos,
PothosRef,
PothosSchema,
SchemaBuilderToken,
} from '@smatch-corp/nestjs-pothos'
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'
@Injectable()
export class CollaborationSessionSchema extends PothosSchema {
constructor(
@Inject(SchemaBuilderToken) private readonly builder: Builder,
private readonly prisma: PrismaService,
// private readonly liveKitRoomService: LiveKitRoomService,
) {
super()
}
@PothosRef()
collaborationSession() {
return this.builder.prismaObject('CollaborationSession', {
description: 'A collaboration session in the system.',
fields: (t) => ({
id: t.exposeID('id', {
description: 'The ID of the collaboration session.',
}),
chatRoomId: t.exposeString('chatRoomId', {
description: 'The ID of the chat room.',
}),
chatRoom: t.relation('chatRoom', {
description: 'The chat room.',
}),
meetingRoom: t.relation('meetingRoom', {
description: 'The meeting room.',
}),
scheduleDate: t.relation('scheduleDate', {
description: 'The schedule date.',
}),
activeDocumentId: t.exposeString('activeDocumentId', {
description: 'The ID of the active document.',
}),
activeDocument: t.relation('activeDocument', {
description: 'The active document.',
}),
createdAt: t.expose('createdAt', {
type: 'DateTime',
description: 'The creation date of the collaboration session.',
}),
updatedAt: t.expose('updatedAt', {
type: 'DateTime',
description: 'The update date of the collaboration session.',
}),
}),
})
}
@Pothos()
init(): void {
this.builder.queryFields((t) => ({
collaborationSession: t.prismaField({
type: this.collaborationSession(),
args: this.builder.generator.findUniqueArgs('CollaborationSession'),
description:
'Retrieve a single collaboration session by its unique identifier.',
resolve: async (query, _root, args, _ctx, _info) => {
return await this.prisma.collaborationSession.findUnique({
...query,
where: args.where,
})
},
}),
collaborationSessions: t.prismaField({
type: [this.collaborationSession()],
args: this.builder.generator.findManyArgs('CollaborationSession'),
description:
'Retrieve a list of collaboration sessions with optional filtering, ordering, and pagination.',
resolve: async (query, _root, args, _ctx, _info) => {
return await this.prisma.collaborationSession.findMany({
...query,
skip: args.skip ?? undefined,
take: args.take ?? undefined,
orderBy: args.orderBy ?? undefined,
where: args.filter ?? undefined,
})
},
}),
}))
this.builder.mutationFields((t) => ({
createCollaborationSession: t.prismaField({
type: this.collaborationSession(),
args: {
input: t.arg({
type: this.builder.generator.getCreateInput('CollaborationSession'),
required: true,
}),
},
description: 'Create a new collaboration session.',
resolve: async (query, _root, args, _ctx, _info) => {
// for test only !!!
if (args.input.chatRoom.create) {
args.input.chatRoom.create.id = uuidv4()
}
// call livekit room service to create room
// this.liveKitRoomService.createServiceMeetingRoom(
// args.input.chatRoom.create?.id ?? '',
// )
return await this.prisma.collaborationSession.create({
...query,
data: args.input,
})
},
}),
}))
}
}