Enhance DocumentSchema and MinioService to support document folder creation. Update document creation logic to include folder setup in Minio after document creation. Refactor createDocumentFolder method to initialize a default page in the document folder. This improves document management and organization within the Minio storage system.
This commit is contained in:
@@ -198,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')
|
||||||
return await this.prisma.document.create({
|
const document = await this.prisma.document.create({
|
||||||
...query,
|
...query,
|
||||||
data: {
|
data: {
|
||||||
...args.input,
|
...args.input,
|
||||||
@@ -211,6 +211,9 @@ export class DocumentSchema extends PothosSchema {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
// create document in minio
|
||||||
|
await this.minio.createDocumentFolder(document.id)
|
||||||
|
return document
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|||||||
@@ -81,9 +81,15 @@ export class MinioService {
|
|||||||
async deleteFile(id: string, category: string) {
|
async deleteFile(id: string, category: string) {
|
||||||
return await this.minioClient.removeObject(this.configService.get('BUCKET_NAME') ?? 'epess', `${category}/${id}`)
|
return await this.minioClient.removeObject(this.configService.get('BUCKET_NAME') ?? 'epess', `${category}/${id}`)
|
||||||
}
|
}
|
||||||
// create a folder for a document pattern epess/documents/<id>/<page>
|
// create a folder for a document pattern epess/documents/<id>/<page> and add page 0 to default
|
||||||
async createDocumentFolder(id: string) {
|
async createDocumentFolder(id: string) {
|
||||||
return await this.minioClient.putObject(this.configService.get('BUCKET_NAME') ?? 'epess', `documents/${id}`, '')
|
const emptyDelta = JSON.stringify(new Delta().insert('\n'))
|
||||||
|
const result = await this.minioClient.putObject(
|
||||||
|
this.configService.get('BUCKET_NAME') ?? 'epess',
|
||||||
|
`documents/${id}/0`,
|
||||||
|
emptyDelta,
|
||||||
|
)
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
async upsertDocumentPage(id: string, page: number, delta: Delta) {
|
async upsertDocumentPage(id: string, page: number, delta: Delta) {
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
import { Inject, Injectable, Logger } from '@nestjs/common'
|
import { Inject, Injectable, Logger } from '@nestjs/common'
|
||||||
import {
|
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
|
||||||
Pothos,
|
|
||||||
PothosRef,
|
|
||||||
PothosSchema,
|
|
||||||
SchemaBuilderToken,
|
|
||||||
} from '@smatch-corp/nestjs-pothos'
|
|
||||||
import { Builder } from '../Graphql/graphql.builder'
|
import { Builder } from '../Graphql/graphql.builder'
|
||||||
import { PrismaService } from '../Prisma/prisma.service'
|
import { PrismaService } from '../Prisma/prisma.service'
|
||||||
import { ScheduleDateStatus, ScheduleStatus } from '@prisma/client'
|
import { ScheduleDateStatus, ScheduleStatus } from '@prisma/client'
|
||||||
@@ -236,8 +231,7 @@ export class ScheduleSchema extends PothosSchema {
|
|||||||
schedules: t.prismaField({
|
schedules: t.prismaField({
|
||||||
type: [this.schedule()],
|
type: [this.schedule()],
|
||||||
args: this.builder.generator.findManyArgs('Schedule'),
|
args: this.builder.generator.findManyArgs('Schedule'),
|
||||||
description:
|
description: 'Retrieve a list of schedules with optional filtering, ordering, and pagination.',
|
||||||
'Retrieve a list of schedules with optional filtering, ordering, and pagination.',
|
|
||||||
resolve: async (query, _root, args, _ctx, _info) => {
|
resolve: async (query, _root, args, _ctx, _info) => {
|
||||||
return await this.prisma.schedule.findMany({
|
return await this.prisma.schedule.findMany({
|
||||||
...query,
|
...query,
|
||||||
@@ -259,9 +253,7 @@ export class ScheduleSchema extends PothosSchema {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
resolve: async (_parent, args, _context, _info) => {
|
resolve: async (_parent, args, _context, _info) => {
|
||||||
return await this.scheduleService.createSchedulePreviewForCenter(
|
return await this.scheduleService.createSchedulePreviewForCenter(args.scheduleConfigInput)
|
||||||
args.scheduleConfigInput,
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@@ -276,17 +268,13 @@ export class ScheduleSchema extends PothosSchema {
|
|||||||
resolve: async (_parent, args, _context, _info) => {
|
resolve: async (_parent, args, _context, _info) => {
|
||||||
// if no scheduleConfig, use default config
|
// if no scheduleConfig, use default config
|
||||||
if (!args.scheduleConfig) {
|
if (!args.scheduleConfig) {
|
||||||
args.scheduleConfig = (
|
args.scheduleConfig = (await this.appConfigService.getVisibleConfigs()).reduce((acc, curr) => {
|
||||||
await this.appConfigService.getVisibleConfigs()
|
|
||||||
).reduce((acc, curr) => {
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
acc[curr.key] = curr.value
|
acc[curr.key] = curr.value
|
||||||
return acc
|
return acc
|
||||||
}, {} as ScheduleConfigType)
|
}, {} as ScheduleConfigType)
|
||||||
}
|
}
|
||||||
return await this.scheduleService.createSchedulePreviewForSingleDay(
|
return await this.scheduleService.createSchedulePreviewForSingleDay(args.scheduleConfig)
|
||||||
args.scheduleConfig,
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
}))
|
}))
|
||||||
@@ -303,13 +291,7 @@ d72a864e-2f41-45ab-9c9b-bf0512a31883,e9be51fd-2382-4e43-9988-74e76fde4b56,2024-1
|
|||||||
description: 'Create a new schedule.',
|
description: 'Create a new schedule.',
|
||||||
args: {
|
args: {
|
||||||
schedule: t.arg({
|
schedule: t.arg({
|
||||||
type: this.builder.generator.getCreateInput('Schedule', [
|
type: this.builder.generator.getCreateInput('Schedule', ['id', 'status', 'customerId', 'orderId', 'dates']),
|
||||||
'id',
|
|
||||||
'status',
|
|
||||||
'customerId',
|
|
||||||
'orderId',
|
|
||||||
'dates',
|
|
||||||
]),
|
|
||||||
required: true,
|
required: true,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
@@ -319,20 +301,17 @@ d72a864e-2f41-45ab-9c9b-bf0512a31883,e9be51fd-2382-4e43-9988-74e76fde4b56,2024-1
|
|||||||
}
|
}
|
||||||
Logger.log('args.schedule', args.schedule)
|
Logger.log('args.schedule', args.schedule)
|
||||||
// generate preview and check if there is any overlapping with other schedules date in same service
|
// generate preview and check if there is any overlapping with other schedules date in same service
|
||||||
const previewSchedule =
|
const previewSchedule = await this.scheduleService.createSchedulePreviewForCenter({
|
||||||
await this.scheduleService.createSchedulePreviewForCenter({
|
startDate: args.schedule.scheduleStart as string,
|
||||||
startDate: args.schedule.scheduleStart as string,
|
endDate: args.schedule.scheduleEnd as string,
|
||||||
endDate: args.schedule.scheduleEnd as string,
|
slots: args.schedule.slots as number[],
|
||||||
slots: args.schedule.slots as number[],
|
days: args.schedule.daysOfWeek as number[],
|
||||||
days: args.schedule.daysOfWeek as number[],
|
})
|
||||||
})
|
const existingScheduleDates = await this.prisma.scheduleDate.findMany({
|
||||||
const existingScheduleDates = await this.prisma.scheduleDate.findMany(
|
where: {
|
||||||
{
|
serviceId: args.schedule.managedService.connect?.id,
|
||||||
where: {
|
|
||||||
serviceId: args.schedule.managedService.connect?.id,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
)
|
})
|
||||||
// check if there is any overlapping with existing schedule dates in same service using DateTimeUtils
|
// check if there is any overlapping with existing schedule dates in same service using DateTimeUtils
|
||||||
const isOverlapping = DateTimeUtils.isOverlaps(
|
const isOverlapping = DateTimeUtils.isOverlaps(
|
||||||
previewSchedule.slots.map((slot) => ({
|
previewSchedule.slots.map((slot) => ({
|
||||||
@@ -353,8 +332,7 @@ d72a864e-2f41-45ab-9c9b-bf0512a31883,e9be51fd-2382-4e43-9988-74e76fde4b56,2024-1
|
|||||||
data: args.schedule,
|
data: args.schedule,
|
||||||
})
|
})
|
||||||
// generate schedule dates based on data and config
|
// generate schedule dates based on data and config
|
||||||
const scheduleDates =
|
const scheduleDates = await this.scheduleService.generateScheduleDates(schedule)
|
||||||
await this.scheduleService.generateScheduleDates(schedule)
|
|
||||||
// update schedule with schedule dates
|
// update schedule with schedule dates
|
||||||
return await this.prisma.schedule.update({
|
return await this.prisma.schedule.update({
|
||||||
...query,
|
...query,
|
||||||
|
|||||||
Reference in New Issue
Block a user