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,8 @@
import { Module } from '@nestjs/common'
import { CollaborationSessionSchema } from './collaborationsession.schema'
@Module({
providers: [CollaborationSessionSchema],
exports: [CollaborationSessionSchema],
})
export class CollaborationSessionModule {}

View File

@@ -1,12 +1,17 @@
import { Inject, Injectable } from '@nestjs/common'
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
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 ServiceMeetingRoomSchema extends PothosSchema {
export class CollaborationSessionSchema extends PothosSchema {
constructor(
@Inject(SchemaBuilderToken) private readonly builder: Builder,
private readonly prisma: PrismaService,
@@ -16,9 +21,9 @@ export class ServiceMeetingRoomSchema extends PothosSchema {
}
@PothosRef()
serviceMeetingRoom() {
collaborationSession() {
return this.builder.prismaObject('CollaborationSession', {
description: 'A service meeting room in the system.',
description: 'A collaboration session in the system.',
fields: (t) => ({
id: t.exposeID('id', {
description: 'The ID of the collaboration session.',
@@ -29,6 +34,26 @@ export class ServiceMeetingRoomSchema extends PothosSchema {
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.',
}),
}),
})
}
@@ -36,10 +61,11 @@ export class ServiceMeetingRoomSchema extends PothosSchema {
@Pothos()
init(): void {
this.builder.queryFields((t) => ({
serviceMeetingRoom: t.prismaField({
type: this.serviceMeetingRoom(),
collaborationSession: t.prismaField({
type: this.collaborationSession(),
args: this.builder.generator.findUniqueArgs('CollaborationSession'),
description: 'Retrieve a single collaboration session by its unique identifier.',
description:
'Retrieve a single collaboration session by its unique identifier.',
resolve: async (query, _root, args, _ctx, _info) => {
return await this.prisma.collaborationSession.findUnique({
...query,
@@ -47,10 +73,11 @@ export class ServiceMeetingRoomSchema extends PothosSchema {
})
},
}),
serviceMeetingRooms: t.prismaField({
type: [this.serviceMeetingRoom()],
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.',
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,
@@ -64,15 +91,15 @@ export class ServiceMeetingRoomSchema extends PothosSchema {
}))
this.builder.mutationFields((t) => ({
createServiceMeetingRoom: t.prismaField({
type: this.serviceMeetingRoom(),
createCollaborationSession: t.prismaField({
type: this.collaborationSession(),
args: {
input: t.arg({
type: this.builder.generator.getCreateInput('CollaborationSession'),
required: true,
}),
},
description: 'Create a new service meeting room.',
description: 'Create a new collaboration session.',
resolve: async (query, _root, args, _ctx, _info) => {
// for test only !!!
if (args.input.chatRoom.create) {

View File

@@ -1,5 +1,10 @@
import { Inject, Injectable, Logger } from '@nestjs/common'
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
import {
Pothos,
PothosRef,
PothosSchema,
SchemaBuilderToken,
} from '@smatch-corp/nestjs-pothos'
import { Builder, SchemaContext } from '../Graphql/graphql.builder'
import { PrismaService } from '../Prisma/prisma.service'
import { DocumentEvent } from './document.event'
@@ -84,6 +89,20 @@ export class DocumentSchema extends PothosSchema {
@Pothos()
init(): void {
this.builder.queryFields((t) => ({
myDocuments: t.prismaField({
type: [this.document()],
args: this.builder.generator.findManyArgs('Document'),
resolve: async (query, _parent, _args, ctx: SchemaContext) => {
if (ctx.isSubscription) throw new Error('Not allowed')
if (!ctx.http?.me?.id) throw new Error('User not found')
return await this.prisma.document.findMany({
...query,
where: {
ownerId: ctx.http?.me?.id,
},
})
},
}),
document: t.prismaField({
type: this.document(),
args: this.builder.generator.findUniqueArgs('Document'),
@@ -115,7 +134,11 @@ export class DocumentSchema extends PothosSchema {
if (ctx.isSubscription) throw new Error('Not allowed')
const userId = ctx.http?.me?.id
if (!userId) throw new Error('User not found')
const fileUrl = await this.minio.getFileUrl('document', 'document', 'document')
const fileUrl = await this.minio.getFileUrl(
'document',
'document',
'document',
)
if (!fileUrl) throw new Error('File not found')
const document = await this.prisma.document.create({
...query,
@@ -134,20 +157,36 @@ export class DocumentSchema extends PothosSchema {
createDocument: t.prismaField({
type: this.document(),
args: {
data: t.arg({
type: this.builder.generator.getCreateInput('Document'),
required: true,
input: t.arg({
type: this.builder.generator.getCreateInput('Document', [
'id',
'ownerId',
'createdAt',
'updatedAt',
'collaborators',
'owner',
'fileUrl',
'previewImageUrl',
'name',
]),
required: false,
}),
},
resolve: async (query, _root, args, ctx: SchemaContext) => {
resolve: async (query, _parent, args, ctx: SchemaContext) => {
if (ctx.isSubscription) throw new Error('Not allowed')
const userId = ctx.http?.me?.id
if (!userId) throw new Error('User not found')
return await this.prisma.document.create({
...query,
data: {
...args.data,
// ownerId: userId,
...args.input,
name: args.input?.name ?? 'Untitled',
fileUrl: '',
owner: {
connect: {
id: userId,
},
},
},
})
},
@@ -168,7 +207,10 @@ export class DocumentSchema extends PothosSchema {
delta,
senderId: ctx.http?.me?.id,
}
ctx.http.pubSub.publish(`${DocumentEvent.CHANGED}.${args.documentId}`, documentDelta)
ctx.http.pubSub.publish(
`${DocumentEvent.CHANGED}.${args.documentId}`,
documentDelta,
)
return documentDelta
},
}),
@@ -210,7 +252,8 @@ export class DocumentSchema extends PothosSchema {
where: { id: args.documentId },
})
if (!document) throw new Error('Document not found')
if (document.ownerId !== ctx.http?.me?.id) throw new Error('User is not owner of document')
if (document.ownerId !== ctx.http?.me?.id)
throw new Error('User is not owner of document')
return await this.prisma.documentCollaborator.create({
data: {
documentId: args.documentId,

View File

@@ -4,6 +4,7 @@ import Delta, { Op } from 'quill-delta'
import { MinioService } from '../Minio/minio.service'
import { DocumentDelta } from './document.type'
import { JSDOM } from 'jsdom'
import { Logger } from '@nestjs/common'
@Injectable()
export class DocumentService {
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
@@ -32,11 +33,34 @@ export class DocumentService {
this.quill = Quill
}
// TODO: maybe never do :)
async handleOnChange(delta: DocumentDelta) {}
async handleOnChange(documentId: string, delta: DocumentDelta) {}
async handleOnSave() {}
async handleOnSave(documentId: string) {}
async handleOnSync() {}
async handleOnSync(documentId: string) {}
async requestSync() {}
async requestSync(documentId: string, page?: number) {
// using pubsub to broadcast to all clients
// this.pubSub.publish(`document:sync:${documentId}`, {
// documentId,
// page,
// })
}
async clientRequestSave(documentId: string) {
// using pubsub to broadcast to all clients
// this.pubSub.publish(`document:save:${documentId}`, {
// documentId,
// })
}
async serverRequestSave(documentId: string) {}
async generatePreviewImage(documentId: string) {}
async allPageToDelta(documentId: string) {}
async toDocx(documentId: string) {}
}
// epess/documents/<id>/<page>

View File

@@ -30,7 +30,7 @@ import { ResumeModule } from '../Resume/resume.module'
import { ScheduleModule } from '../Schedule/schedule.module'
import { ServiceAndCategoryModule } from '../ServiceAndCategory/serviceandcategory.module'
import { ServiceFeedbackModule } from '../ServiceFeedback/servicefeedback.module'
import { ServiceMeetingRoomModule } from '../ServiceMeetingRoom/servicemeetingroom.module'
import { CollaborationSessionModule } from '../CollaborationSession/collaborationsession.module'
import { ServiceModule } from '../Service/service.module'
import { UploadedFileModule } from '../UploadedFile/uploadedfile.module'
import { UserModule } from '../User/user.module'
@@ -43,6 +43,7 @@ import { RedisPubSub } from 'graphql-redis-subscriptions'
import { DocumentModule } from 'src/Document/document.module'
import { Context } from 'graphql-ws'
import { FinanceModule } from 'src/Finance/finance.module'
import { MeetingRoomModule } from 'src/MeetingRoom/meetingroom.module'
@Global()
@Module({
@@ -72,13 +73,14 @@ import { FinanceModule } from 'src/Finance/finance.module'
MilestoneModule,
ScheduleModule,
MessageModule,
ServiceMeetingRoomModule,
CollaborationSessionModule,
UploadedFileModule,
ManagedServiceModule,
WorkshopMeetingRoomModule,
AdminNoteModule,
DocumentModule,
FinanceModule,
MeetingRoomModule,
PothosModule.forRoot({
builder: {
inject: [PrismaService],

View File

@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common'
import { MeetingRoomSchema } from './meetingroom.schema'
@Module({
providers: [MeetingRoomSchema],
exports: [MeetingRoomSchema],
})
export class MeetingRoomModule {}

View 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,
})
},
}),
}))
}
}

View File

@@ -14,6 +14,7 @@ import {
ChatRoomType,
OrderStatus,
PaymentStatus,
ScheduleDateStatus,
ScheduleStatus,
} from '@prisma/client'
export type CreatePaymentBody = CheckoutRequestType

View File

@@ -7,7 +7,7 @@ import {
} from '@smatch-corp/nestjs-pothos'
import { Builder } from '../Graphql/graphql.builder'
import { PrismaService } from '../Prisma/prisma.service'
import { ScheduleStatus } from '@prisma/client'
import { ScheduleDateStatus, ScheduleStatus } from '@prisma/client'
import { ScheduleService } from './schedule.service'
import { AppConfigService } from '../AppConfig/appconfig.service'
import { ScheduleConfigType } from './schedule'
@@ -130,6 +130,10 @@ export class ScheduleSchema extends PothosSchema {
type: 'DateTime',
nullable: false,
}),
status: t.expose('status', {
type: ScheduleDateStatus,
nullable: false,
}),
dayOfWeek: t.exposeInt('dayOfWeek', {
nullable: false,
}),

View File

@@ -1,8 +0,0 @@
import { Module } from '@nestjs/common'
import { ServiceMeetingRoomSchema } from './servicemeetingroom.schema'
@Module({
providers: [ServiceMeetingRoomSchema],
exports: [ServiceMeetingRoomSchema],
})
export class ServiceMeetingRoomModule {}

File diff suppressed because one or more lines are too long