Merge branch 'main' of https://github.com/EPESS/epess-web-backend
This commit is contained in:
@@ -7,14 +7,12 @@ import { Document } from '@prisma/client'
|
|||||||
import { DocumentDelta } from './document.type'
|
import { DocumentDelta } from './document.type'
|
||||||
import Delta from 'quill-delta'
|
import Delta from 'quill-delta'
|
||||||
import { MinioService } from 'src/Minio/minio.service'
|
import { MinioService } from 'src/Minio/minio.service'
|
||||||
import { OpenaiService } from 'src/OpenAI/openai.service'
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DocumentSchema extends PothosSchema {
|
export class DocumentSchema extends PothosSchema {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||||
private readonly prisma: PrismaService,
|
private readonly prisma: PrismaService,
|
||||||
private readonly minio: MinioService,
|
private readonly minio: MinioService,
|
||||||
private readonly openaiService: OpenaiService,
|
|
||||||
) {
|
) {
|
||||||
super()
|
super()
|
||||||
}
|
}
|
||||||
@@ -162,12 +160,8 @@ export class DocumentSchema extends PothosSchema {
|
|||||||
if (!ctx.http?.me?.id) throw new Error('User not found')
|
if (!ctx.http?.me?.id) throw new Error('User not found')
|
||||||
if (!args.documentId) throw new Error('Document id not found')
|
if (!args.documentId) throw new Error('Document id not found')
|
||||||
if (args.pageIndex === undefined || args.pageIndex === null) throw new Error('Page index not found')
|
if (args.pageIndex === undefined || args.pageIndex === null) throw new Error('Page index not found')
|
||||||
let delta
|
const delta = await this.minio.getDocumentPage(args.documentId, args.pageIndex)
|
||||||
try {
|
if (!delta) throw new Error('Delta not found')
|
||||||
delta = await this.minio.getDocumentPage(args.documentId, args.pageIndex)
|
|
||||||
} catch (_error) {
|
|
||||||
delta = null
|
|
||||||
}
|
|
||||||
const totalPage = await this.minio.countDocumentPages(args.documentId)
|
const totalPage = await this.minio.countDocumentPages(args.documentId)
|
||||||
return {
|
return {
|
||||||
documentId: args.documentId,
|
documentId: args.documentId,
|
||||||
@@ -176,7 +170,6 @@ export class DocumentSchema extends PothosSchema {
|
|||||||
totalPage,
|
totalPage,
|
||||||
senderId: ctx.http?.me?.id,
|
senderId: ctx.http?.me?.id,
|
||||||
eventType: DocumentEvent.CLIENT_REQUEST_SYNC,
|
eventType: DocumentEvent.CLIENT_REQUEST_SYNC,
|
||||||
requestSync: false,
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -205,7 +198,7 @@ export class DocumentSchema extends PothosSchema {
|
|||||||
if (ctx.isSubscription) throw new Error('Not allowed')
|
if (ctx.isSubscription) throw new Error('Not allowed')
|
||||||
const userId = ctx.http?.me?.id
|
const userId = ctx.http?.me?.id
|
||||||
if (!userId) throw new Error('User not found')
|
if (!userId) throw new Error('User not found')
|
||||||
const document = await this.prisma.document.create({
|
return await this.prisma.document.create({
|
||||||
...query,
|
...query,
|
||||||
data: {
|
data: {
|
||||||
...args.input,
|
...args.input,
|
||||||
@@ -218,9 +211,6 @@ export class DocumentSchema extends PothosSchema {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
// create document in minio
|
|
||||||
await this.minio.createDocumentFolder(document.id)
|
|
||||||
return document
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@@ -244,18 +234,6 @@ export class DocumentSchema extends PothosSchema {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
testSuggestEditDocument: t.field({
|
|
||||||
type: 'Delta',
|
|
||||||
args: {
|
|
||||||
documentDelta: t.arg({ type: this.documentDeltaInput(), required: true }),
|
|
||||||
},
|
|
||||||
resolve: async (_root, args, ctx: SchemaContext) => {
|
|
||||||
if (ctx.isSubscription) throw new Error('Not allowed')
|
|
||||||
if (!args.documentDelta.delta) throw new Error('Delta not found')
|
|
||||||
return await this.openaiService.documentSuggestEditDelta(args.documentDelta.delta)
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
|
|
||||||
eventDocumentChanged: t.field({
|
eventDocumentChanged: t.field({
|
||||||
type: this.documentDelta(),
|
type: this.documentDelta(),
|
||||||
args: {
|
args: {
|
||||||
@@ -334,7 +312,6 @@ export class DocumentSchema extends PothosSchema {
|
|||||||
})
|
})
|
||||||
if (!document) throw new Error('Document not found')
|
if (!document) throw new Error('Document not found')
|
||||||
if (
|
if (
|
||||||
document.ownerId !== ctx.http?.me?.id &&
|
|
||||||
!document.isPublic &&
|
!document.isPublic &&
|
||||||
!document.collaborators.some((c) => c.userId === ctx.http?.me?.id && c.writable)
|
!document.collaborators.some((c) => c.userId === ctx.http?.me?.id && c.writable)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user