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 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { Document, Schema as MongooseSchema } from 'mongoose'; @Schema({ timestamps: true, collection: 'maintenance_schedules' }) export class MaintenanceSchedule extends Document { @Prop({ required: true, index: true }) tenantId: string; @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Asset', required: true }) assetId: MongooseSchema.Types.ObjectId; @Prop({ required: true }) maintenanceName: string; @Prop({ required: true }) intervalType: string; // 'Calendar' | 'Usage' @Prop({ default: 30 }) // e.g. every 30 days calendarIntervalDays: number; @Prop({ default: 1000 }) // e.g. every 1000 hours usageIntervalHours: number; @Prop({ default: null }) lastCompletedAt?: Date; @Prop({ required: true, default: () => new Date() }) nextDueAt: Date; } export const MaintenanceScheduleSchema = SchemaFactory.createForClass(MaintenanceSchedule); @Schema({ timestamps: true, collection: 'asset_work_orders' }) export class AssetWorkOrder extends Document { @Prop({ required: true, index: true }) tenantId: string; @Prop({ required: true, unique: true }) workOrderNumber: string; // e.g. "WO-000001" @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Asset', required: true }) assetId: MongooseSchema.Types.ObjectId; @Prop({ required: true }) workOrderType: string; // 'Preventive' | 'Corrective' | 'Emergency' | 'Calibration' @Prop({ default: 'medium' }) priority: string; // 'low' | 'medium' | 'high' | 'critical' @Prop({ default: 'draft' }) status: string; // 'draft' | 'scheduled' | 'assigned' | 'in_progress' | 'completed' | 'closed' | 'cancelled' @Prop({ default: null }) assignedTechnicianId?: string; @Prop({ default: null }) vendorId?: string; // external vendor @Prop({ default: 0 }) estimatedCostMinor: number; @Prop({ default: 0 }) actualCostMinor: number; @Prop({ default: 0 }) partsCostMinor: number; @Prop({ default: 0 }) downtimeHours: number; @Prop({ default: null }) completionNotes?: string; @Prop({ default: null }) completedAt?: Date; } export const AssetWorkOrderSchema = SchemaFactory.createForClass(AssetWorkOrder); AssetWorkOrderSchema.index({ tenantId: 1, workOrderNumber: 1 }, { unique: true }); AssetWorkOrderSchema.index({ tenantId: 1, status: 1 }); |