All files / src/domains/hr/attendance/schemas daily-record.schema.ts

0% Statements 0/65
0% Branches 0/24
100% Functions 0/0
0% Lines 0/57

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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176                                                                                                                                                                                                                                                                                                                                                               
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema as MongooseSchema } from 'mongoose';
 
@Schema({ timestamps: true, collection: 'attendance_daily_records' })
export class AttendanceDailyRecord extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ required: true, index: true })
  employeeId: string;
 
  @Prop({ required: true })
  attendanceDate: string;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Shift' })
  shiftId: string;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'AttendancePolicy' })
  policyId: string;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'WorkWeek' })
  workWeekId: string;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'HolidayCalendar' })
  holidayCalendarId: string;
 
  @Prop()
  scheduledStart: Date;
 
  @Prop()
  scheduledEnd: Date;
 
  @Prop()
  firstCheckIn: Date;
 
  @Prop()
  lastCheckOut: Date;
 
  @Prop({ default: 0 })
  workedMinutes: number;
 
  @Prop({ default: 0 })
  scheduledMinutes: number;
 
  @Prop({ default: 0 })
  paidBreakMinutes: number;
 
  @Prop({ default: 0 })
  unpaidBreakMinutes: number;
 
  @Prop({ default: 0 })
  lateMinutes: number;
 
  @Prop({ default: 0 })
  earlyDepartureMinutes: number;
 
  @Prop({ default: 0 })
  overtimeMinutes: number;
 
  @Prop({ default: 0 })
  approvedOvertimeMinutes: number;
 
  @Prop({ default: 0 })
  deficitMinutes: number;
 
  @Prop({ required: true })
  attendanceStatus: string; // Present, Absent, Half Day, Weekly Off, Holiday, Holiday Worked, Missed Punch, Incomplete, Late, Early Departure
 
  @Prop()
  dayType: string; // Working day, Weekly off, Holiday
 
  @Prop()
  sourceSummary: string; // Web, Mobile, Biometric, Mixed
 
  @Prop({ type: [{ type: String }], default: [] })
  anomalyFlags: string[];
 
  @Prop({ default: 'None' })
  regularizationStatus: string; // None, Pending, Approved, Rejected
 
  @Prop({ default: false })
  locked: boolean;
 
  @Prop({ default: 1 })
  calculationVersion: number;
 
  @Prop({ default: Date.now })
  calculatedAt: Date;
}
export const AttendanceDailyRecordSchema = SchemaFactory.createForClass(
  AttendanceDailyRecord,
);
AttendanceDailyRecordSchema.index(
  { tenantId: 1, employeeId: 1, attendanceDate: 1 },
  { unique: true },
);
AttendanceDailyRecordSchema.index({
  tenantId: 1,
  attendanceDate: 1,
  attendanceStatus: 1,
});
AttendanceDailyRecordSchema.index({
  tenantId: 1,
  locked: 1,
  attendanceDate: 1,
});
 
@Schema({ timestamps: true, collection: 'attendance_calculations' })
export class AttendanceCalculation extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ required: true })
  employeeId: string;
 
  @Prop({ required: true })
  attendanceDate: string;
 
  @Prop({ type: MongooseSchema.Types.Mixed })
  snapshotData: any; // Saves the exact inputs and outputs of the calculation engine run
 
  @Prop({ default: Date.now })
  calculatedAt: Date;
}
export const AttendanceCalculationSchema = SchemaFactory.createForClass(
  AttendanceCalculation,
);
 
@Schema({ timestamps: true, collection: 'attendance_exceptions' })
export class AttendanceException extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ required: true })
  employeeId: string;
 
  @Prop({ required: true })
  attendanceDate: string;
 
  @Prop({ required: true })
  exceptionType: string; // Late Arrival, Early Departure, Missed Punch
 
  @Prop()
  severity: string;
 
  @Prop()
  minutes: number;
 
  @Prop({ default: 'open' })
  status: string; // open, waived, penalized
}
export const AttendanceExceptionSchema =
  SchemaFactory.createForClass(AttendanceException);
 
@Schema({ timestamps: true, collection: 'attendance_exception_waivers' })
export class AttendanceExceptionWaiver extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({
    required: true,
    type: MongooseSchema.Types.ObjectId,
    ref: 'AttendanceException',
  })
  exceptionId: string;
 
  @Prop({ required: true })
  waivedBy: string;
 
  @Prop()
  reason: string;
}
export const AttendanceExceptionWaiverSchema = SchemaFactory.createForClass(
  AttendanceExceptionWaiver,
);