update preview date
This commit is contained in:
@@ -8,12 +8,39 @@ import {
|
||||
import { Builder } from '../Graphql/graphql.builder'
|
||||
import { PrismaService } from '../Prisma/prisma.service'
|
||||
import { ScheduleStatus } from '@prisma/client'
|
||||
import { ScheduleService } from './schedule.service'
|
||||
import { AppConfigService } from '../AppConfig/appconfig.service'
|
||||
|
||||
export type ScheduleConfigType =
|
||||
| {
|
||||
midDayBreakTimeStart?: string | null | undefined
|
||||
midDayBreakTimeEnd?: string | null | undefined
|
||||
slotDuration?: string | null | undefined
|
||||
slotBreakDuration?: string | null | undefined
|
||||
slotEndTime?: string | null | undefined
|
||||
slotStartTime?: string | null | undefined
|
||||
}
|
||||
| null
|
||||
| undefined
|
||||
|
||||
export type ScheduleSlotType = {
|
||||
slot: string
|
||||
start: string
|
||||
end: string
|
||||
}
|
||||
|
||||
export type PreviewScheduleType = {
|
||||
totalSlots: number
|
||||
slots: ScheduleSlotType[]
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ScheduleSchema extends PothosSchema {
|
||||
constructor(
|
||||
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly scheduleService: ScheduleService,
|
||||
private readonly appConfigService: AppConfigService,
|
||||
) {
|
||||
super()
|
||||
}
|
||||
@@ -53,6 +80,29 @@ export class ScheduleSchema extends PothosSchema {
|
||||
})
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
scheduleSlot() {
|
||||
return this.builder.simpleObject('ScheduleSlot', {
|
||||
fields: (t) => ({
|
||||
slot: t.string({}),
|
||||
start: t.string({}),
|
||||
end: t.string({}),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
previewSchedule() {
|
||||
return this.builder.simpleObject('PreviewSchedule', {
|
||||
fields: (t) => ({
|
||||
totalSlots: t.int(),
|
||||
slots: t.field({
|
||||
type: [this.scheduleSlot()],
|
||||
}),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
scheduleDate() {
|
||||
return this.builder.prismaObject('ScheduleDate', {
|
||||
@@ -79,6 +129,21 @@ export class ScheduleSchema extends PothosSchema {
|
||||
})
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
scheduleConfigInput() {
|
||||
return this.builder.inputType('ScheduleConfigInput', {
|
||||
description: 'A schedule config in the system.',
|
||||
fields: (t) => ({
|
||||
midDayBreakTimeStart: t.string(),
|
||||
midDayBreakTimeEnd: t.string(),
|
||||
slotDuration: t.string(),
|
||||
slotBreakDuration: t.string(),
|
||||
slotEndTime: t.string(),
|
||||
slotStartTime: t.string(),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
@Pothos()
|
||||
init(): void {
|
||||
this.builder.queryFields((t) => ({
|
||||
@@ -109,6 +174,21 @@ export class ScheduleSchema extends PothosSchema {
|
||||
})
|
||||
},
|
||||
}),
|
||||
|
||||
adminPreviewSchedule: t.field({
|
||||
type: this.previewSchedule(),
|
||||
description: 'Preview a schedule for admin.',
|
||||
args: {
|
||||
scheduleConfig: t.arg({
|
||||
type: this.scheduleConfigInput(),
|
||||
}),
|
||||
},
|
||||
resolve: async (_parent, args, _context, _info) => {
|
||||
return await this.scheduleService.createSchedulePreview(
|
||||
args.scheduleConfig,
|
||||
)
|
||||
},
|
||||
}),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user