bling bling

This commit is contained in:
2024-11-25 19:46:23 +07:00
parent c063f1a10e
commit 84a09375da
6 changed files with 152 additions and 39 deletions

View File

@@ -91,10 +91,21 @@ export class CollaborationSessionSchema extends PothosSchema {
})
/* ---------- use case 1 : customer get collaboration session by id --------- */
if (ctx.http.me?.role === Role.CUSTOMER && collaborationSession) {
if (scheduleDate.participantIds.includes(ctx.http.me?.id)) {
return collaborationSession
// if collaboratorsIds not include current user id, add it
if (
!collaborationSession.collaboratorsIds.includes(ctx.http.me?.id)
) {
collaborationSession.collaboratorsIds.push(ctx.http.me?.id)
await this.prisma.collaborationSession.update({
where: {
id: collaborationSession.id,
},
data: {
collaboratorsIds: collaborationSession.collaboratorsIds,
},
})
}
throw new Error('User not allowed')
return collaborationSession
}
/* ---------- use case 2 : center mentor get collaboration session by schedule date id --------- */
if (
@@ -144,6 +155,7 @@ export class CollaborationSessionSchema extends PothosSchema {
scheduleDateId: scheduleDate.id,
// assign chat room
chatRoomId: chatRoom.id,
collaboratorsIds: [ctx.http.me.id],
},
})
// case after start time and before end time, mark as late
@@ -182,28 +194,49 @@ export class CollaborationSessionSchema extends PothosSchema {
}))
this.builder.mutationFields((t) => ({
createCollaborationSession: t.prismaField({
// update active document id
updateActiveDocumentId: t.prismaField({
type: this.collaborationSession(),
args: {
input: t.arg({
type: this.builder.generator.getCreateInput('CollaborationSession'),
activeDocumentId: t.arg.string({
description: 'The ID of the active document.',
required: true,
}),
collaborationSessionId: t.arg.string({
description: 'The ID of the collaboration session.',
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,
description:
'Update the active document ID for a collaboration session.',
resolve: async (_query, _root, args, ctx, _info) => {
if (ctx.isSubscription) throw new Error('Not allowed')
if (!ctx.http.me) throw new Error('Cannot get your info')
// check permission
const collaborationSession =
await this.prisma.collaborationSession.findUnique({
where: {
id: args.collaborationSessionId,
},
include: {
scheduleDate: true,
},
})
if (!collaborationSession)
throw new Error('Collaboration session not found')
if (
!collaborationSession.scheduleDate.participantIds.includes(
ctx.http.me.id,
)
)
throw new Error('User not allowed')
return await this.prisma.collaborationSession.update({
where: {
id: args.collaborationSessionId,
},
data: {
activeDocumentId: args.activeDocumentId,
},
})
},
}),