All files / src/domains/procurement/inspections/schemas inspection.schema.ts

0% Statements 0/21
100% Branches 0/0
100% Functions 0/0
0% Lines 0/17

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                                                                                             
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Types } from 'mongoose';
 
@Schema({ _id: false })
export class InspectionCriterion {
  @Prop({ required: true })
  name: string;
 
  @Prop({ required: true })
  type: string; // e.g. boolean, numeric
 
  @Prop({ default: null })
  expectedValue: string;
}
 
@Schema({ timestamps: true })
export class QualityInspection extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ required: true, index: true })
  inspectionNumber: string;
 
  @Prop({ required: true, index: true })
  goodsReceiptId: string;
 
  @Prop({ required: true })
  inspectorId: string;
 
  @Prop({ type: [InspectionCriterion], default: [] })
  criteria: InspectionCriterion[];
 
  @Prop({
    required: true,
    default: 'accepted',
    enum: ['accepted', 'conditionally_accepted', 'rejected', 'quarantined', 'reinspection_required'],
  })
  decision: string;
 
  @Prop({ default: null })
  comments: string;
}
 
export const QualityInspectionSchema = SchemaFactory.createForClass(QualityInspection);
QualityInspectionSchema.index({ tenantId: 1, inspectionNumber: 1 }, { unique: true });
QualityInspectionSchema.index({ tenantId: 1, goodsReceiptId: 1 });