diff --git a/src/Document/document.schema.ts b/src/Document/document.schema.ts index b781d68..7a20655 100644 --- a/src/Document/document.schema.ts +++ b/src/Document/document.schema.ts @@ -333,6 +333,25 @@ export class DocumentSchema extends PothosSchema { }) }, }), + removeCollaborator: t.prismaField({ + type: this.documentCollaborator(), + args: { + documentId: t.arg({ type: 'String', required: true }), + userId: t.arg({ type: 'String', required: true }), + }, + resolve: async (_, __, args, ctx: SchemaContext) => { + if (ctx.isSubscription) throw new Error('Not allowed') + // check if ctx user is owner of document + const document = await this.prisma.document.findUnique({ + 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') + return await this.prisma.documentCollaborator.delete({ + where: { documentId_userId: { documentId: args.documentId, userId: args.userId } }, + }) + }, + }), })) this.builder.subscriptionFields((t) => ({