Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { Document, Schema as MongooseSchema } from 'mongoose'; @Schema({ timestamps: true, collection: 'calendar_business_hours' }) export class SharedBusinessHoursDefinition extends Document { @Prop({ required: true, index: true }) tenantId: string; @Prop({ required: true }) calendarName: string; @Prop({ default: 'UTC' }) timezone: string; @Prop({ type: MongooseSchema.Types.Map, of: String, default: {} }) weeklyHours: Map<string, string>; // e.g., 'monday' -> '09:00-17:00' or split shift '09:00-12:00,14:00-18:00' @Prop({ type: [Date], default: [] }) holidays: Date[]; } export const SharedBusinessHoursDefinitionSchema = SchemaFactory.createForClass(SharedBusinessHoursDefinition); @Schema({ timestamps: true, collection: 'calendar_working_calendars' }) export class WorkingCalendar extends Document { @Prop({ required: true, index: true }) tenantId: string; @Prop({ required: true }) name: string; @Prop({ default: 'UTC' }) timezone: string; @Prop({ default: 'active', enum: ['active', 'inactive', 'draft'] }) status: string; @Prop({ type: [{ dayOfWeek: { type: Number, required: true }, // 0=Sunday, 1=Monday... isWorkingDay: { type: Boolean, default: true }, isHalfDay: { type: Boolean, default: false }, shifts: [{ startTime: { type: String, required: true }, // '09:00' endTime: { type: String, required: true }, // '17:00' crossesMidnight: { type: Boolean, default: false }, breaks: [{ breakName: { type: String }, startTime: { type: String, required: true }, endTime: { type: String, required: true }, isPaid: { type: Boolean, default: false } }] }] }], default: [] }) workingDays: Array<{ dayOfWeek: number; isWorkingDay: boolean; isHalfDay: boolean; shifts: Array<{ startTime: string; endTime: string; crossesMidnight: boolean; breaks: Array<{ breakName?: string; startTime: string; endTime: string; isPaid: boolean; }>; }>; }>; @Prop({ type: [{ exceptionDate: { type: String, required: true }, // 'YYYY-MM-DD' isWorkingDay: { type: Boolean, required: true }, shifts: [{ startTime: { type: String }, endTime: { type: String } }], reason: { type: String } }], default: [] }) exceptions: Array<{ exceptionDate: string; isWorkingDay: boolean; shifts: Array<{ startTime: string; endTime: string }>; reason?: string; }>; @Prop({ required: true, default: () => new Date() }) effectiveFrom: Date; @Prop({ default: null }) effectiveTo: Date; } export const WorkingCalendarSchema = SchemaFactory.createForClass(WorkingCalendar); WorkingCalendarSchema.index({ tenantId: 1, effectiveFrom: -1 }); @Schema({ timestamps: true, collection: 'calendar_working_calendar_versions' }) export class WorkingCalendarVersion extends Document { @Prop({ required: true, index: true }) tenantId: string; @Prop({ required: true, index: true }) workingCalendarId: string; @Prop({ required: true }) version: number; @Prop({ type: MongooseSchema.Types.Mixed, required: true }) workingCalendarData: any; } export const WorkingCalendarVersionSchema = SchemaFactory.createForClass(WorkingCalendarVersion); WorkingCalendarVersionSchema.index({ tenantId: 1, workingCalendarId: 1, version: 1 }, { unique: true }); |