bling bling
This commit is contained in:
Submodule epess-database updated: aa79d56d50...103bee2c60
@@ -91,10 +91,21 @@ export class CollaborationSessionSchema extends PothosSchema {
|
|||||||
})
|
})
|
||||||
/* ---------- use case 1 : customer get collaboration session by id --------- */
|
/* ---------- use case 1 : customer get collaboration session by id --------- */
|
||||||
if (ctx.http.me?.role === Role.CUSTOMER && collaborationSession) {
|
if (ctx.http.me?.role === Role.CUSTOMER && collaborationSession) {
|
||||||
if (scheduleDate.participantIds.includes(ctx.http.me?.id)) {
|
// if collaboratorsIds not include current user id, add it
|
||||||
return collaborationSession
|
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 --------- */
|
/* ---------- use case 2 : center mentor get collaboration session by schedule date id --------- */
|
||||||
if (
|
if (
|
||||||
@@ -144,6 +155,7 @@ export class CollaborationSessionSchema extends PothosSchema {
|
|||||||
scheduleDateId: scheduleDate.id,
|
scheduleDateId: scheduleDate.id,
|
||||||
// assign chat room
|
// assign chat room
|
||||||
chatRoomId: chatRoom.id,
|
chatRoomId: chatRoom.id,
|
||||||
|
collaboratorsIds: [ctx.http.me.id],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
// case after start time and before end time, mark as late
|
// case after start time and before end time, mark as late
|
||||||
@@ -182,28 +194,49 @@ export class CollaborationSessionSchema extends PothosSchema {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
this.builder.mutationFields((t) => ({
|
this.builder.mutationFields((t) => ({
|
||||||
createCollaborationSession: t.prismaField({
|
// update active document id
|
||||||
|
updateActiveDocumentId: t.prismaField({
|
||||||
type: this.collaborationSession(),
|
type: this.collaborationSession(),
|
||||||
args: {
|
args: {
|
||||||
input: t.arg({
|
activeDocumentId: t.arg.string({
|
||||||
type: this.builder.generator.getCreateInput('CollaborationSession'),
|
description: 'The ID of the active document.',
|
||||||
|
required: true,
|
||||||
|
}),
|
||||||
|
collaborationSessionId: t.arg.string({
|
||||||
|
description: 'The ID of the collaboration session.',
|
||||||
required: true,
|
required: true,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
description: 'Create a new collaboration session.',
|
description:
|
||||||
resolve: async (query, _root, args, _ctx, _info) => {
|
'Update the active document ID for a collaboration session.',
|
||||||
// for test only !!!
|
resolve: async (_query, _root, args, ctx, _info) => {
|
||||||
if (args.input.chatRoom.create) {
|
if (ctx.isSubscription) throw new Error('Not allowed')
|
||||||
args.input.chatRoom.create.id = uuidv4()
|
if (!ctx.http.me) throw new Error('Cannot get your info')
|
||||||
}
|
// check permission
|
||||||
|
const collaborationSession =
|
||||||
// call livekit room service to create room
|
await this.prisma.collaborationSession.findUnique({
|
||||||
// this.liveKitRoomService.createServiceMeetingRoom(
|
where: {
|
||||||
// args.input.chatRoom.create?.id ?? '',
|
id: args.collaborationSessionId,
|
||||||
// )
|
},
|
||||||
return await this.prisma.collaborationSession.create({
|
include: {
|
||||||
...query,
|
scheduleDate: true,
|
||||||
data: args.input,
|
},
|
||||||
|
})
|
||||||
|
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,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -30,33 +30,43 @@ export class CronService {
|
|||||||
`Found ${schedules.length} schedules to update`,
|
`Found ${schedules.length} schedules to update`,
|
||||||
'checkScheduleDateStatus',
|
'checkScheduleDateStatus',
|
||||||
)
|
)
|
||||||
|
// get all collaboration sessions
|
||||||
|
const collaborationSessions =
|
||||||
|
await this.prisma.collaborationSession.findMany({
|
||||||
|
where: {
|
||||||
|
collaboratorsIds: {
|
||||||
|
hasEvery: schedules.map((s) => s.id),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const updates = schedules
|
const updates = schedules
|
||||||
.map((schedule) => {
|
.map((schedule) => {
|
||||||
if (schedule.status === ScheduleDateStatus.NOT_STARTED) {
|
const collaborationSession = collaborationSessions.find(
|
||||||
|
(session) => session.scheduleDateId === schedule.id,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!collaborationSession) {
|
||||||
return {
|
return {
|
||||||
id: schedule.id,
|
id: schedule.id,
|
||||||
status: ScheduleDateStatus.MISSING_MENTOR,
|
status: ScheduleDateStatus.MISSING_MENTOR,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (
|
|
||||||
schedule.status === ScheduleDateStatus.IN_PROGRESS &&
|
if (collaborationSession.collaboratorsIds.length === 1) {
|
||||||
schedule.participantIds.length === 1
|
|
||||||
) {
|
|
||||||
return {
|
return {
|
||||||
id: schedule.id,
|
id: schedule.id,
|
||||||
status: ScheduleDateStatus.MISSING_CUSTOMER,
|
status: ScheduleDateStatus.MISSING_CUSTOMER,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (
|
|
||||||
schedule.status === ScheduleDateStatus.IN_PROGRESS &&
|
if (collaborationSession.collaboratorsIds.length === 2) {
|
||||||
schedule.participantIds.length === 2
|
|
||||||
) {
|
|
||||||
return {
|
return {
|
||||||
id: schedule.id,
|
id: schedule.id,
|
||||||
status: ScheduleDateStatus.COMPLETED,
|
status: ScheduleDateStatus.COMPLETED,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
.filter((update) => update !== null)
|
.filter((update) => update !== null)
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ export enum DocumentEvent {
|
|||||||
PAGE_CREATED = 'document_page_created',
|
PAGE_CREATED = 'document_page_created',
|
||||||
PAGE_DELETED = 'document_page_deleted',
|
PAGE_DELETED = 'document_page_deleted',
|
||||||
DOCUMENT_CREATED = 'document_created',
|
DOCUMENT_CREATED = 'document_created',
|
||||||
|
ACTIVE_DOCUMENT_ID_CHANGED = 'document_active_document_id_changed',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,13 +92,17 @@ export class DocumentSchema extends PothosSchema {
|
|||||||
myDocuments: t.prismaField({
|
myDocuments: t.prismaField({
|
||||||
type: [this.document()],
|
type: [this.document()],
|
||||||
args: this.builder.generator.findManyArgs('Document'),
|
args: this.builder.generator.findManyArgs('Document'),
|
||||||
resolve: async (query, _parent, _args, ctx: SchemaContext) => {
|
resolve: async (query, _parent, args, ctx: SchemaContext) => {
|
||||||
if (ctx.isSubscription) throw new Error('Not allowed')
|
if (ctx.isSubscription) throw new Error('Not allowed')
|
||||||
if (!ctx.http?.me?.id) throw new Error('User not found')
|
if (!ctx.http?.me?.id) throw new Error('User not found')
|
||||||
return await this.prisma.document.findMany({
|
return await this.prisma.document.findMany({
|
||||||
...query,
|
...query,
|
||||||
|
orderBy: args.orderBy ?? undefined,
|
||||||
where: {
|
where: {
|
||||||
ownerId: ctx.http?.me?.id,
|
OR: [
|
||||||
|
{ ownerId: ctx.http.me.id },
|
||||||
|
{ collaborators: { some: { userId: ctx.http.me.id } } },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -215,7 +219,7 @@ export class DocumentSchema extends PothosSchema {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
updateDocument: t.field({
|
eventUpdateDocument: t.field({
|
||||||
type: this.documentDelta(),
|
type: this.documentDelta(),
|
||||||
args: {
|
args: {
|
||||||
data: t.arg({
|
data: t.arg({
|
||||||
@@ -237,6 +241,52 @@ export class DocumentSchema extends PothosSchema {
|
|||||||
return args.data
|
return args.data
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
updateDocument: t.prismaField({
|
||||||
|
type: this.document(),
|
||||||
|
args: {
|
||||||
|
documentId: t.arg({ type: 'String', required: true }),
|
||||||
|
data: t.arg({
|
||||||
|
type: this.builder.generator.getUpdateInput('Document', [
|
||||||
|
'id',
|
||||||
|
'ownerId',
|
||||||
|
'createdAt',
|
||||||
|
'updatedAt',
|
||||||
|
'collaborationSessionId',
|
||||||
|
'collaborationSession',
|
||||||
|
'owner',
|
||||||
|
'fileUrl',
|
||||||
|
'previewImageUrl',
|
||||||
|
]),
|
||||||
|
required: true,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
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')
|
||||||
|
// check if user is owner or collaborator
|
||||||
|
const document = await this.prisma.document.findUnique({
|
||||||
|
where: { id: args.documentId },
|
||||||
|
include: {
|
||||||
|
collaborators: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if (!document) throw new Error('Document not found')
|
||||||
|
if (
|
||||||
|
document.ownerId !== ctx.http?.me?.id &&
|
||||||
|
!document.isPublic &&
|
||||||
|
!document.collaborators.some(
|
||||||
|
(c) => c.userId === ctx.http?.me?.id && c.writable,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
throw new Error('User is not owner or collaborator of document')
|
||||||
|
return await this.prisma.document.update({
|
||||||
|
...query,
|
||||||
|
where: { id: args.documentId },
|
||||||
|
data: args.data,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}),
|
||||||
addCollaborator: t.prismaField({
|
addCollaborator: t.prismaField({
|
||||||
type: this.documentCollaborator(),
|
type: this.documentCollaborator(),
|
||||||
args: {
|
args: {
|
||||||
@@ -275,16 +325,35 @@ export class DocumentSchema extends PothosSchema {
|
|||||||
required: true,
|
required: true,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
subscribe: (_, args, ctx: SchemaContext) => {
|
subscribe: async (_, args, ctx: SchemaContext) => {
|
||||||
if (!ctx.isSubscription) throw new Error('Not allowed')
|
if (!ctx.isSubscription) throw new Error('Not allowed')
|
||||||
const {
|
const {
|
||||||
websocket: { pubSub },
|
websocket: { pubSub },
|
||||||
} = ctx
|
} = ctx
|
||||||
|
const documentId = args.documentId
|
||||||
|
// check user permission
|
||||||
|
const document = await this.prisma.document.findUnique({
|
||||||
|
where: { id: documentId },
|
||||||
|
include: {
|
||||||
|
collaborators: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if (!document) throw new Error('Document not found')
|
||||||
|
if (!document.isPublic) {
|
||||||
|
if (
|
||||||
|
document.ownerId !== ctx.websocket?.me?.id &&
|
||||||
|
!document.collaborators.some(
|
||||||
|
(c) => c.userId === ctx.websocket?.me?.id && c.writable,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
throw new Error('User is not owner or collaborator of document')
|
||||||
|
}
|
||||||
return pubSub.asyncIterator([
|
return pubSub.asyncIterator([
|
||||||
`${DocumentEvent.CHANGED}.${args.documentId}`,
|
`${DocumentEvent.CHANGED}.${documentId}`,
|
||||||
`${DocumentEvent.CREATED}.${args.documentId}`,
|
`${DocumentEvent.CREATED}.${documentId}`,
|
||||||
`${DocumentEvent.DELETED}.${args.documentId}`,
|
`${DocumentEvent.DELETED}.${documentId}`,
|
||||||
`${DocumentEvent.SAVED}.${args.documentId}`,
|
`${DocumentEvent.SAVED}.${documentId}`,
|
||||||
|
`${DocumentEvent.ACTIVE_DOCUMENT_ID_CHANGED}.${documentId}`,
|
||||||
]) as unknown as AsyncIterable<DocumentDelta>
|
]) as unknown as AsyncIterable<DocumentDelta>
|
||||||
},
|
},
|
||||||
resolve: async (payload: DocumentDelta, _args, ctx: SchemaContext) => {
|
resolve: async (payload: DocumentDelta, _args, ctx: SchemaContext) => {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user