All files / src/domains/performance/schemas kpis-measurements.schema.ts

100% Statements 29/29
79.48% Branches 31/39
100% Functions 0/0
100% Lines 23/23

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 601x 1x     1x   1x     1x     1x     1x   1x     1x   1x     1x     1x     1x     1x     1x     1x   1x     1x   1x     1x     1x     1x   1x  
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema as MongooseSchema } from 'mongoose';
 
@Schema({ timestamps: true, collection: 'performance_kpi_libraries' })
export class PerformanceKpiLibrary extends Document {
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId })
  tenantId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true })
  name: string;
 
  @Prop({ required: true })
  description: string;
 
  @Prop({ required: true, default: '((actual / target) * 100)' })
  formulaExpression: string; // Dynamic calculations
}
export const PerformanceKpiLibrarySchema = SchemaFactory.createForClass(PerformanceKpiLibrary);
 
@Schema({ timestamps: true, collection: 'performance_kpi_measurements' })
export class PerformanceKpiMeasurement extends Document {
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId })
  tenantId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'Employee' })
  employeeId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'PerformanceKpiLibrary' })
  kpiId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'PerformanceCycle' })
  cycleId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true, type: Number })
  targetValue: number;
 
  @Prop({ required: true, type: Number, default: 0 })
  actualValue: number;
 
  @Prop({ required: true, type: Number, default: 0 })
  achievementScore: number; // Calculated based on formulaExpression
}
export const PerformanceKpiMeasurementSchema = SchemaFactory.createForClass(PerformanceKpiMeasurement);
 
@Schema({ timestamps: true, collection: 'performance_kpi_snapshots' })
export class PerformanceKpiHistorySnapshot extends Document {
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId })
  tenantId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'Employee' })
  employeeId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true, type: Number })
  overallKpiScore: number;
 
  @Prop({ required: true })
  recordedDate: Date;
}
export const PerformanceKpiHistorySnapshotSchema = SchemaFactory.createForClass(PerformanceKpiHistorySnapshot);