All files / src/domains/performance/schemas goals-okrs.schema.ts

100% Statements 45/45
79.71% Branches 55/69
100% Functions 0/0
100% Lines 37/37

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 102 103 104 105 106 1071x 1x     1x   1x     1x     1x     1x     1x     1x     1x     1x     1x     1x                   1x   1x     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_goals' })
export class PerformanceGoal extends Document {
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId })
  tenantId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'PerformanceCycle' })
  cycleId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true })
  title: string;
 
  @Prop({ required: true, enum: ['company', 'department', 'team', 'employee'] })
  type: string;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Employee' })
  employeeId?: MongooseSchema.Types.ObjectId;
 
  @Prop({ type: MongooseSchema.Types.ObjectId })
  departmentId?: MongooseSchema.Types.ObjectId;
 
  @Prop({ type: MongooseSchema.Types.ObjectId })
  teamId?: MongooseSchema.Types.ObjectId;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'PerformanceGoal' })
  parentGoalId?: MongooseSchema.Types.ObjectId; // For cascading alignment
 
  @Prop({ required: true, default: 0, type: Number })
  progress: number; // 0 to 100
 
  @Prop({ required: true, enum: ['draft', 'pending_approval', 'approved', 'rejected'], default: 'draft' })
  status: string;
 
  @Prop({
    type: [{
      title: { type: String, required: true },
      progress: { type: Number, required: true, default: 0 },
      isCompleted: { type: Boolean, required: true, default: false }
    }],
    default: []
  })
  milestones: Array<{ title: string; progress: number; isCompleted: boolean }>;
}
export const PerformanceGoalSchema = SchemaFactory.createForClass(PerformanceGoal);
 
@Schema({ timestamps: true, collection: 'performance_goal_templates' })
export class PerformanceGoalTemplate extends Document {
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId })
  tenantId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true })
  title: string;
 
  @Prop({ required: true })
  description: string;
 
  @Prop({ required: true, enum: ['general', 'technical', 'sales', 'operations'] })
  category: string;
}
export const PerformanceGoalTemplateSchema = SchemaFactory.createForClass(PerformanceGoalTemplate);
 
@Schema({ timestamps: true, collection: 'performance_objectives' })
export class PerformanceObjective extends Document {
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId })
  tenantId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'PerformanceCycle' })
  cycleId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'Employee' })
  employeeId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true })
  title: string;
 
  @Prop({ required: true, default: 0, type: Number })
  progress: number;
}
export const PerformanceObjectiveSchema = SchemaFactory.createForClass(PerformanceObjective);
 
@Schema({ timestamps: true, collection: 'performance_key_results' })
export class PerformanceKeyResult extends Document {
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId })
  tenantId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'PerformanceObjective' })
  objectiveId: MongooseSchema.Types.ObjectId;
 
  @Prop({ required: true })
  title: string;
 
  @Prop({ required: true, type: Number })
  weight: number; // e.g. 50 (percentage weight out of 100 for the objective)
 
  @Prop({ required: true, type: Number, default: 0 })
  currentValue: number;
 
  @Prop({ required: true, type: Number })
  targetValue: number;
 
  @Prop({ type: MongooseSchema.Types.ObjectId })
  projectId?: MongooseSchema.Types.ObjectId; // Integration links to Project
}
export const PerformanceKeyResultSchema = SchemaFactory.createForClass(PerformanceKeyResult);