feat: add removeCollaborator mutation to DocumentSchema
- Introduced a new mutation to allow document owners to remove collaborators from a document. - Implemented authorization checks to ensure only the document owner can perform this action. - Enhanced error handling for cases where the document is not found or the user is not the owner.
This commit is contained in:
@@ -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) => ({
|
this.builder.subscriptionFields((t) => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user