All files / src/domains/manufacturing/schemas manufacturing-resources.schema.ts

0% Statements 0/39
0% Branches 0/15
100% Functions 0/0
0% Lines 0/33

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                                                                                                                                                                             
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema as MongooseSchema } from 'mongoose';
 
@Schema({ timestamps: true, collection: 'manufacturing_plants' })
export class ManufacturingPlant extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ required: true })
  plantCode: string;
 
  @Prop({ required: true })
  plantName: string;
 
  @Prop()
  location?: string;
 
  @Prop({ default: true })
  isActive: boolean;
}
 
export const ManufacturingPlantSchema = SchemaFactory.createForClass(ManufacturingPlant);
ManufacturingPlantSchema.index({ tenantId: 1, plantCode: 1 }, { unique: true });
 
@Schema({ timestamps: true, collection: 'manufacturing_work_centers' })
export class WorkCenter extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'ManufacturingPlant', required: true })
  plantId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true })
  workCenterCode: string;
 
  @Prop({ required: true })
  workCenterName: string;
 
  @Prop({ default: 1 })
  numberOfMachines: number;
 
  @Prop({ default: 1 })
  numberOfOperators: number;
 
  @Prop({ default: 8 }) // standard 8 hours availability
  dailyCapacityHours: number;
 
  @Prop({ default: 0.85 }) // 85% standard efficiency
  efficiency: number;
 
  @Prop({ default: 0.90 }) // 90% utilization
  utilization: number;
 
  @Prop({ default: true })
  isActive: boolean;
}
 
export const WorkCenterSchema = SchemaFactory.createForClass(WorkCenter);
WorkCenterSchema.index({ tenantId: 1, workCenterCode: 1 }, { unique: true });
 
@Schema({ timestamps: true, collection: 'manufacturing_resources' })
export class MachineResource extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'WorkCenter', required: true })
  workCenterId: MongooseSchema.Types.ObjectId;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Asset', required: true })
  assetId: MongooseSchema.Types.ObjectId; // integration with Assets module
 
  @Prop({ required: true })
  resourceCode: string;
 
  @Prop({ required: true })
  resourceName: string;
 
  @Prop({ default: 0 })
  costRateMinor: number; // hourly run cost rate
 
  @Prop({ default: 'Available' })
  status: string; // 'Available' | 'Down' | 'Maintenance'
}
 
export const MachineResourceSchema = SchemaFactory.createForClass(MachineResource);
MachineResourceSchema.index({ tenantId: 1, resourceCode: 1 }, { unique: true });