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 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { Document, Schema as MongooseSchema } from 'mongoose'; // ───────────────────────────────────────── // Comp-Off Policy // ───────────────────────────────────────── export type CompOffPolicyDocument = CompOffPolicy & Document; @Schema({ collection: 'comp_off_policies', timestamps: true }) export class CompOffPolicy { @Prop({ required: true }) tenantId: string; @Prop({ required: true }) policyName: string; @Prop() description: string; @Prop({ required: true }) creditLeaveTypeId: string; // what leave type comp-off credits into @Prop({ default: 4 }) minimumWorkHours: number; @Prop({ default: 30 }) expiryDays: number; @Prop() maximumBalance: number; @Prop({ default: true }) approvalRequired: boolean; @Prop({ default: false }) autoCredit: boolean; @Prop({ enum: ['active', 'inactive'], default: 'active' }) status: string; @Prop() createdBy: string; } export const CompOffPolicySchema = SchemaFactory.createForClass(CompOffPolicy); CompOffPolicySchema.index({ tenantId: 1 }); // ───────────────────────────────────────── // Comp-Off Earning // ───────────────────────────────────────── export type CompOffEarningDocument = CompOffEarning & Document; @Schema({ collection: 'comp_off_earnings', timestamps: true }) export class CompOffEarning { @Prop({ required: true }) tenantId: string; @Prop({ required: true }) employeeId: string; @Prop({ required: true }) policyId: string; @Prop({ required: true }) earnedDate: string; // The day worked @Prop({ required: true }) workedHours: number; @Prop({ required: true }) earnedQuantity: number; @Prop({ required: true }) unit: string; @Prop({ enum: [ 'Overtime', 'Holiday Work', 'Weekly Off Work', 'Field Duty', 'Manual HR Credit', ], }) source: string; @Prop() sourceReferenceId: string; @Prop({ enum: ['pending', 'approved', 'rejected', 'expired'], default: 'pending', }) status: string; @Prop() approvedBy: string; @Prop() approvedAt: Date; @Prop() rejectedReason: string; @Prop() expiresAt: Date; @Prop() ledgerId: string; @Prop() requestedBy: string; } export const CompOffEarningSchema = SchemaFactory.createForClass(CompOffEarning); CompOffEarningSchema.index({ tenantId: 1, employeeId: 1, status: 1 }); CompOffEarningSchema.index({ tenantId: 1, expiresAt: 1, status: 1 }); // ───────────────────────────────────────── // Comp-Off Request (usage request) // ───────────────────────────────────────── export type CompOffRequestDocument = CompOffRequest & Document; @Schema({ collection: 'comp_off_requests', timestamps: true }) export class CompOffRequest { @Prop({ required: true }) tenantId: string; @Prop({ required: true }) employeeId: string; @Prop({ required: true }) leaveRequestId: string; @Prop({ required: true }) quantity: number; @Prop({ required: true }) unit: string; @Prop({ type: [String] }) earningIds: string[]; @Prop({ enum: ['pending', 'fulfilled', 'cancelled'], default: 'pending' }) status: string; } export const CompOffRequestSchema = SchemaFactory.createForClass(CompOffRequest); CompOffRequestSchema.index({ tenantId: 1, employeeId: 1 }); CompOffRequestSchema.index({ tenantId: 1, leaveRequestId: 1 }); // ───────────────────────────────────────── // Comp-Off Expiry // ───────────────────────────────────────── export type CompOffExpiryDocument = CompOffExpiry & Document; @Schema({ collection: 'comp_off_expiries', timestamps: true }) export class CompOffExpiry { @Prop({ required: true }) tenantId: string; @Prop({ required: true }) employeeId: string; @Prop({ required: true }) earningId: string; @Prop({ required: true }) expiredQuantity: number; @Prop({ required: true }) expiryDate: string; @Prop() ledgerId: string; @Prop() processedAt: Date; } export const CompOffExpirySchema = SchemaFactory.createForClass(CompOffExpiry); CompOffExpirySchema.index({ tenantId: 1, employeeId: 1, expiryDate: 1 }); |