Refactor CollaborationSession and Document schemas to improve code clarity and functionality. Enhance error handling in collaboration session retrieval and update logic. Introduce new request sync events in Document schema and update Minio service for document page management. Adjust cron job to use current date for future schedule date checks. Update user schema for better error handling and improve service descriptions in order schema. Remove global decorators from Workshop modules for better module encapsulation.

This commit is contained in:
2024-11-27 06:48:49 +07:00
parent 51bafcfe29
commit 77f44a891f
11 changed files with 176 additions and 113 deletions

View File

@@ -1,10 +1,11 @@
import { Inject, Injectable, Logger } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { FileUpload } from 'graphql-upload/processRequest.js'
import { Client } from 'minio'
import { Client, BucketItem } from 'minio'
import { MINIO_CONNECTION } from 'nestjs-minio'
import { DateTimeUtils } from 'src/common/utils/datetime.utils'
import { v4 as uuidv4 } from 'uuid'
import Delta from 'quill-delta'
@Injectable()
export class MinioService {
constructor(
@@ -85,13 +86,30 @@ export class MinioService {
return await this.minioClient.putObject(this.configService.get('BUCKET_NAME') ?? 'epess', `documents/${id}`, '')
}
async upsertDocumentFolder(id: string, page: string) {
async upsertDocumentPage(id: string, page: number, delta: Delta) {
return await this.minioClient.putObject(
this.configService.get('BUCKET_NAME') ?? 'epess',
`documents/${id}/${page}`,
'',
JSON.stringify(delta),
)
}
async getDocumentPage(id: string, page: number) {
const delta = (await this.minioClient.getObject(
this.configService.get('BUCKET_NAME') ?? 'epess',
`documents/${id}/${page}`,
)) as unknown as Delta
return delta
}
async countDocumentPages(id: string): Promise<number> {
return new Promise<number>((resolve, reject) => {
const stream = this.minioClient.listObjects(this.configService.get('BUCKET_NAME') ?? 'epess', `documents/${id}`)
const items: BucketItem[] = []
stream.on('data', (item) => items.push(item))
stream.on('end', () => resolve(items.length))
stream.on('error', (err) => reject(err))
})
}
// export document to docx format by get all pages and convert to docx
async exportDocument(id: string) {
// get all pages