All files / src/domains/hr/payroll/loans/schemas loan.schema.ts

0% Statements 0/48
0% Branches 0/53
100% Functions 0/0
0% Lines 0/42

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, Schema as MongooseSchema } from 'mongoose';
 
@Schema({ collection: 'loan_types', timestamps: true })
export class LoanType extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true })
  tenantId!: MongooseSchema.Types.ObjectId;
  @Prop({ required: true }) typeName!: string;
  @Prop({ required: true }) typeCode!: string;
  @Prop({ default: 0 }) maxAmount!: number;
  @Prop({ default: 0 }) defaultInterestRate!: number;
  @Prop({ default: 'reducing', enum: ['reducing', 'flat', 'interest_free'] })
  interestType!: string;
  @Prop({ default: 36 }) maxTenureMonths!: number;
  @Prop({ default: true }) requiresApproval!: boolean;
  @Prop({ default: true }) isActive!: boolean;
}
export const LoanTypeSchema = SchemaFactory.createForClass(LoanType);
LoanTypeSchema.index({ tenantId: 1, typeCode: 1 }, { unique: true });
 
@Schema({ collection: 'employee_loans', timestamps: true })
export class EmployeeLoan extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true })
  tenantId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  employeeId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  loanTypeId!: MongooseSchema.Types.ObjectId;
  @Prop({ required: true }) principalAmount!: number;
  @Prop({ default: 0 }) interestRate!: number;
  @Prop({ required: true, enum: ['reducing', 'flat', 'interest_free'] })
  interestType!: string;
  @Prop({ required: true }) tenureMonths!: number;
  @Prop({ default: 0 }) emiAmount!: number;
  @Prop({ default: 0 }) totalInterest!: number;
  @Prop({ default: 0 }) totalRepayable!: number;
  @Prop({ default: 0 }) amountRepaid!: number;
  @Prop({ default: 0 }) outstandingBalance!: number;
  @Prop() disbursementDate?: Date;
  @Prop() repaymentStartDate?: Date;
  @Prop({ default: 0 }) moratoriumMonths!: number;
  @Prop({
    default: 'pending',
    enum: [
      'pending',
      'approved',
      'active',
      'closed',
      'foreclosed',
      'written_off',
      'rejected',
      'cancelled',
    ],
  })
  status!: string;
  @Prop({ type: MongooseSchema.Types.ObjectId })
  approvedBy?: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId })
  createdBy?: MongooseSchema.Types.ObjectId;
}
export const EmployeeLoanSchema = SchemaFactory.createForClass(EmployeeLoan);
EmployeeLoanSchema.index({ tenantId: 1, employeeId: 1, status: 1 });
 
@Schema({ collection: 'loan_approvals', timestamps: true })
export class LoanApproval extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  tenantId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  loanId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  approverId!: MongooseSchema.Types.ObjectId;
  @Prop({ required: true, enum: ['pending', 'approved', 'rejected'] })
  status!: string;
  @Prop() comments?: string;
}
export const LoanApprovalSchema = SchemaFactory.createForClass(LoanApproval);