Enhance NestJS application with SWC builder configuration, add @nestjs/devtools-integration for development support, and refactor various components for improved readability. Update package dependencies and streamline import statements across multiple files.

This commit is contained in:
2024-11-26 04:26:55 +07:00
parent c4e302387f
commit a1ca5c62fb
12 changed files with 1646 additions and 235 deletions

View File

@@ -4,15 +4,10 @@ import { Injectable, Logger } from '@nestjs/common'
import { PrismaService } from 'src/Prisma/prisma.service'
import { AppConfigService } from 'src/AppConfig/appconfig.service'
import {
PreviewScheduleType,
ScheduleConfigType,
ScheduleConfigTypeForCenter,
ScheduleSlotType,
} from './schedule.d'
import { PreviewScheduleType, ScheduleConfigType, ScheduleConfigTypeForCenter, ScheduleSlotType } from './schedule.d'
import { Config, Schedule, ScheduleDate } from '@prisma/client'
import { DateTime, Settings, Zone } from 'luxon'
import * as _ from 'lodash'
import _ from 'lodash'
import { ScheduleDateInput } from './schedule'
@Injectable()
@@ -22,9 +17,7 @@ export class ScheduleService {
private readonly appConfigService: AppConfigService,
) {}
async createSchedulePreviewForSingleDay(
scheduleConfig: ScheduleConfigType,
): Promise<PreviewScheduleType> {
async createSchedulePreviewForSingleDay(scheduleConfig: ScheduleConfigType): Promise<PreviewScheduleType> {
// generate Slot By config
const slots = this.generateSlots(scheduleConfig)
@@ -35,12 +28,8 @@ export class ScheduleService {
}
// create preview for center require scheduleConfigInput: { startDate: "2024-11-02T00:00:00.000Z", endDate: "2024-11-22T00:00:00.000Z", slots: [1, 3], days: [2, 5] }
async createSchedulePreviewForCenter(
scheduleConfig: ScheduleConfigTypeForCenter,
): Promise<PreviewScheduleType> {
const config: ScheduleConfigType = (
await this.appConfigService.getVisibleConfigs()
).reduce((acc, curr) => {
async createSchedulePreviewForCenter(scheduleConfig: ScheduleConfigTypeForCenter): Promise<PreviewScheduleType> {
const config: ScheduleConfigType = (await this.appConfigService.getVisibleConfigs()).reduce((acc, curr) => {
// @ts-ignore
acc[curr.key] = curr.value
return acc
@@ -54,9 +43,7 @@ export class ScheduleService {
async generateScheduleDates(schedule: Schedule): Promise<ScheduleDate[]> {
// generate schedule dates based on data and config
const config: ScheduleConfigType = (
await this.appConfigService.getVisibleConfigs()
).reduce((acc, curr) => {
const config: ScheduleConfigType = (await this.appConfigService.getVisibleConfigs()).reduce((acc, curr) => {
// @ts-ignore
acc[curr.key] = curr.value
return acc
@@ -72,11 +59,7 @@ export class ScheduleService {
const scheduleDates: ScheduleDateInput[] = []
// loop each day from scheduleStart to scheduleEnd
for (
let date = scheduleStart;
date <= scheduleEnd;
date = date.plus({ days: 1 })
) {
for (let date = scheduleStart; date <= scheduleEnd; date = date.plus({ days: 1 })) {
// Check if the current date matches one of the specified days of the week
if (daysOfWeeks.includes(date.weekday)) {
// loop through slots
@@ -85,10 +68,7 @@ export class ScheduleService {
slot,
slotDuration.toString(),
slotBreakDuration.toString(),
DateTimeUtils.getATimeWithDateB(
DateTime.fromISO(config.dayStartTime),
date,
).toISO() ?? '',
DateTimeUtils.getATimeWithDateB(DateTime.fromISO(config.dayStartTime), date).toISO() ?? '',
)
scheduleDates.push({
scheduleId: schedule.id,
@@ -103,10 +83,9 @@ export class ScheduleService {
}
}
}
const scheduleDatesCreated =
await this.prisma.scheduleDate.createManyAndReturn({
data: scheduleDates,
})
const scheduleDatesCreated = await this.prisma.scheduleDate.createManyAndReturn({
data: scheduleDates,
})
return scheduleDatesCreated
}
@@ -137,11 +116,7 @@ query CenterPreviewSchedule {
const scheduleStart = DateTime.fromISO(_scheduleConfig.startDate)
const scheduleEnd = DateTime.fromISO(_scheduleConfig.endDate)
// loop each day from scheduleStart to scheduleEnd
for (
let date = scheduleStart;
date <= scheduleEnd;
date = date.plus({ days: 1 })
) {
for (let date = scheduleStart; date <= scheduleEnd; date = date.plus({ days: 1 })) {
// Check if the current date matches one of the specified days of the week
if (daysOfWeeks.includes(date.weekday)) {
// loop through slots
@@ -151,10 +126,7 @@ query CenterPreviewSchedule {
slot,
_config.slotDuration,
_config.slotBreakDuration,
DateTimeUtils.getATimeWithDateB(
DateTime.fromISO(_config.dayStartTime),
date,
).toISO() ?? '',
DateTimeUtils.getATimeWithDateB(DateTime.fromISO(_config.dayStartTime), date).toISO() ?? '',
)
// if the slot is not overlapping with mid day break time, add it to the slots
if (
@@ -213,24 +185,11 @@ query CenterPreviewSchedule {
return slots
}
isOverLapping(
startTime1: DateTime,
endTime1: DateTime,
startTime2: DateTime,
endTime2: DateTime,
) {
return (
Math.max(startTime1.toMillis(), startTime2.toMillis()) <
Math.min(endTime1.toMillis(), endTime2.toMillis())
)
isOverLapping(startTime1: DateTime, endTime1: DateTime, startTime2: DateTime, endTime2: DateTime) {
return Math.max(startTime1.toMillis(), startTime2.toMillis()) < Math.min(endTime1.toMillis(), endTime2.toMillis())
}
calculateNumberOfSlots(
startTime: string,
endTime: string,
slotDuration: string,
slotBreakDuration: string,
) {
calculateNumberOfSlots(startTime: string, endTime: string, slotDuration: string, slotBreakDuration: string) {
const _startTime = DateTimeUtils.toTime(startTime)
const _endTime = DateTimeUtils.toTime(endTime)
const _slotDuration = parseInt(slotDuration) // minutes
@@ -247,20 +206,12 @@ query CenterPreviewSchedule {
second: _endTime.second,
})
const totalMinutes =
(endDate.toMillis() - startDate.toMillis()) / (60 * 1000)
const numberOfSlots = Math.floor(
totalMinutes / (_slotDuration + _slotBreakDuration),
)
const totalMinutes = (endDate.toMillis() - startDate.toMillis()) / (60 * 1000)
const numberOfSlots = Math.floor(totalMinutes / (_slotDuration + _slotBreakDuration))
return numberOfSlots
}
getSlotStartAndEndTime(
slotNumber: number,
slotDuration: string,
slotBreakDuration: string,
dayStartTime: string,
) {
getSlotStartAndEndTime(slotNumber: number, slotDuration: string, slotBreakDuration: string, dayStartTime: string) {
const durationInMinutes = parseInt(slotDuration)
const breakDurationInMinutes = parseInt(slotBreakDuration)
const initialStartTime = DateTime.fromISO(dayStartTime)