All files / src/domains/hr/leave/schemas leave-period.schema.ts

0% Statements 0/42
0% Branches 0/8
100% Functions 0/0
0% Lines 0/36

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                                                                                                                                                         
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
 
// ─────────────────────────────────────────
// Leave Period
// ─────────────────────────────────────────
export type LeavePeriodDocument = LeavePeriod & Document;
 
@Schema({ collection: 'leave_periods', timestamps: true })
export class LeavePeriod {
  @Prop({ required: true }) tenantId: string;
  @Prop({ required: true }) periodCode: string;
  @Prop({ required: true }) periodName: string;
  @Prop({
    required: true,
    enum: ['Calendar', 'Financial', 'Custom', 'Anniversary', 'Regional'],
  })
  periodType: string;
  @Prop({ required: true }) startDate: string; // YYYY-MM-DD
  @Prop({ required: true }) endDate: string;
  @Prop() timezone: string;
  @Prop({ enum: ['active', 'closed', 'draft'], default: 'draft' })
  status: string;
  @Prop() lockDate: string;
  @Prop() carryForwardProcessingDate: string;
  @Prop() encashmentProcessingDate: string;
  @Prop() closedAt: Date;
  @Prop() closedBy: string;
  @Prop() createdBy: string;
}
 
export const LeavePeriodSchema = SchemaFactory.createForClass(LeavePeriod);
LeavePeriodSchema.index({ tenantId: 1, periodCode: 1 }, { unique: true });
LeavePeriodSchema.index({ tenantId: 1, status: 1, startDate: 1 });
 
// ─────────────────────────────────────────
// Leave Period Segment
// ─────────────────────────────────────────
export type LeavePeriodSegmentDocument = LeavePeriodSegment & Document;
 
@Schema({ collection: 'leave_period_segments', timestamps: true })
export class LeavePeriodSegment {
  @Prop({ required: true }) tenantId: string;
  @Prop({ required: true }) periodId: string;
  @Prop({ required: true }) segmentName: string;
  @Prop({ required: true }) startDate: string;
  @Prop({ required: true }) endDate: string;
  @Prop() segmentType: string;
}
 
export const LeavePeriodSegmentSchema =
  SchemaFactory.createForClass(LeavePeriodSegment);
LeavePeriodSegmentSchema.index({ tenantId: 1, periodId: 1 });
 
// ─────────────────────────────────────────
// Employee Leave Period Assignment
// ─────────────────────────────────────────
export type EmployeeLeavePeriodAssignmentDocument =
  EmployeeLeavePeriodAssignment & Document;
 
@Schema({ collection: 'employee_leave_period_assignments', timestamps: true })
export class EmployeeLeavePeriodAssignment {
  @Prop({ required: true }) tenantId: string;
  @Prop({ required: true }) employeeId: string;
  @Prop({ required: true }) periodId: string;
  @Prop() effectiveFrom: Date;
  @Prop({ enum: ['active', 'inactive'], default: 'active' }) status: string;
}
 
export const EmployeeLeavePeriodAssignmentSchema = SchemaFactory.createForClass(
  EmployeeLeavePeriodAssignment,
);
EmployeeLeavePeriodAssignmentSchema.index(
  { tenantId: 1, employeeId: 1, periodId: 1 },
  { unique: true },
);