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 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { Document, Schema as MongooseSchema } from 'mongoose'; @Schema({ timestamps: true, collection: 'calendar_booking_requests' }) export class BookingRequest extends Document { @Prop({ required: true, index: true }) tenantId: string; @Prop({ required: true, unique: true, index: true }) bookingId: string; @Prop({ required: true }) bookingType: string; // 'Meeting' | 'Interview' | 'TechnicianVisit' | 'CustomerAppointment' | 'MaintenanceSlot' | 'RoomBooking' | 'EquipmentBooking' | 'VehicleBooking' | 'MachineSlot' | 'Custom' @Prop({ required: true, index: true }) startAt: Date; @Prop({ required: true, index: true }) endAt: Date; @Prop({ required: true, index: true }) bookerId: string; // Employee or User placing booking @Prop({ type: [String], default: [] }) participantIds: string[]; @Prop({ type: [String], default: [] }) resourceIds: string[]; // Room, vehicle, machine resources requested @Prop({ default: 'requested', enum: ['requested', 'held', 'pending_approval', 'confirmed', 'checked_in', 'completed', 'cancelled', 'expired', 'no_show', 'rescheduled'] }) status: string; @Prop({ default: null }) holdExpiresAt?: Date; @Prop() notes?: string; } export const BookingRequestSchema = SchemaFactory.createForClass(BookingRequest); BookingRequestSchema.index({ tenantId: 1, bookingId: 1 }, { unique: true }); BookingRequestSchema.index({ tenantId: 1, startAt: 1, endAt: 1 }); @Schema({ timestamps: true, collection: 'calendar_booking_rules' }) export class BookingRule extends Document { @Prop({ required: true, index: true }) tenantId: string; @Prop({ required: true }) resourceType: string; // 'Room' | 'Machine' | 'Vehicle' | etc. @Prop({ default: 15 }) minNoticeMinutes: number; @Prop({ default: 90 }) maxHorizonDays: number; @Prop({ default: 15 }) bufferBeforeMinutes: number; @Prop({ default: 15 }) bufferAfterMinutes: number; @Prop({ default: false }) approvalRequired: boolean; @Prop({ type: [String], default: [] }) approverIds: string[]; } export const BookingRuleSchema = SchemaFactory.createForClass(BookingRule); BookingRuleSchema.index({ tenantId: 1, resourceType: 1 }, { unique: true }); @Schema({ timestamps: true, collection: 'calendar_booking_holds' }) export class BookingHold extends Document { @Prop({ required: true, index: true }) tenantId: string; @Prop({ required: true, unique: true, index: true }) holdId: string; @Prop({ required: true }) resourceId: string; @Prop({ required: true }) startAt: Date; @Prop({ required: true }) endAt: Date; @Prop({ required: true }) expiresAt: Date; @Prop({ required: true }) heldByUserId: string; } export const BookingHoldSchema = SchemaFactory.createForClass(BookingHold); BookingHoldSchema.index({ tenantId: 1, resourceId: 1, startAt: 1, endAt: 1 }); BookingHoldSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 }); // MongoDB TTL index to auto-expire holds |