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 Delta from 'quill-delta'
|
||||
import { MinioService } from 'src/Minio/minio.service'
|
||||
import { OpenaiService } from 'src/OpenAI/openai.service'
|
||||
@Injectable()
|
||||
export class DocumentSchema extends PothosSchema {
|
||||
constructor(
|
||||
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly minio: MinioService,
|
||||
private readonly openaiService: OpenaiService,
|
||||
) {
|
||||
super()
|
||||
}
|
||||
@@ -162,12 +160,8 @@ export class DocumentSchema extends PothosSchema {
|
||||
if (!ctx.http?.me?.id) throw new Error('User 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')
|
||||
let delta
|
||||
try {
|
||||
delta = await this.minio.getDocumentPage(args.documentId, args.pageIndex)
|
||||
} catch (_error) {
|
||||
delta = null
|
||||
}
|
||||
const delta = await this.minio.getDocumentPage(args.documentId, args.pageIndex)
|
||||
if (!delta) throw new Error('Delta not found')
|
||||
const totalPage = await this.minio.countDocumentPages(args.documentId)
|
||||
return {
|
||||
documentId: args.documentId,
|
||||
@@ -176,7 +170,6 @@ export class DocumentSchema extends PothosSchema {
|
||||
totalPage,
|
||||
senderId: ctx.http?.me?.id,
|
||||
eventType: DocumentEvent.CLIENT_REQUEST_SYNC,
|
||||
requestSync: false,
|
||||
}
|
||||
},
|
||||
}),
|
||||
@@ -205,7 +198,7 @@ export class DocumentSchema extends PothosSchema {
|
||||
if (ctx.isSubscription) throw new Error('Not allowed')
|
||||
const userId = ctx.http?.me?.id
|
||||
if (!userId) throw new Error('User not found')
|
||||
const document = await this.prisma.document.create({
|
||||
return await this.prisma.document.create({
|
||||
...query,
|
||||
data: {
|
||||
...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({
|
||||
type: this.documentDelta(),
|
||||
args: {
|
||||
@@ -334,7 +312,6 @@ export class DocumentSchema extends PothosSchema {
|
||||
})
|
||||
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)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user