All files / src/domains/hr/payroll/payslips/schemas payslip.schema.ts

0% Statements 0/48
0% Branches 0/67
100% Functions 0/0
0% Lines 0/40

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                                                                                                                                                                     
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema as MongooseSchema } from 'mongoose';
 
@Schema({ collection: 'payslips', timestamps: true })
export class Payslip extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true })
  tenantId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  runId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  employeeId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  resultId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  periodId!: MongooseSchema.Types.ObjectId;
  @Prop() fileId?: string;
  @Prop() fileName?: string;
  @Prop({ default: 1 }) version!: number;
  @Prop({ default: false }) isPasswordProtected!: boolean;
  @Prop({
    default: 'generated',
    enum: ['generated', 'delivered', 'viewed', 'failed'],
  })
  status!: string;
  @Prop() generatedAt?: Date;
  @Prop() deliveredAt?: Date;
}
export const PayslipSchema = SchemaFactory.createForClass(Payslip);
PayslipSchema.index({ tenantId: 1, runId: 1, employeeId: 1 });
PayslipSchema.index({ tenantId: 1, employeeId: 1, periodId: 1 });
 
@Schema({ collection: 'payslip_versions', timestamps: true })
export class PayslipVersion extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  tenantId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  payslipId!: MongooseSchema.Types.ObjectId;
  @Prop({ required: true }) version!: number;
  @Prop() fileId?: string;
  @Prop() reason?: string;
}
export const PayslipVersionSchema =
  SchemaFactory.createForClass(PayslipVersion);
 
@Schema({ collection: 'payslip_templates', timestamps: true })
export class PayslipTemplate extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  tenantId!: MongooseSchema.Types.ObjectId;
  @Prop({ required: true }) templateName!: string;
  @Prop({ type: MongooseSchema.Types.Mixed }) templateConfig!: Record<
    string,
    unknown
  >;
  @Prop({ default: true }) isDefault!: boolean;
  @Prop({ default: true }) isActive!: boolean;
}
export const PayslipTemplateSchema =
  SchemaFactory.createForClass(PayslipTemplate);
 
@Schema({ collection: 'payslip_delivery_logs', timestamps: true })
export class PayslipDeliveryLog extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  tenantId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  payslipId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  employeeId!: MongooseSchema.Types.ObjectId;
  @Prop({ required: true, enum: ['email', 'in_app', 'mobile_push'] })
  channel!: string;
  @Prop({
    default: 'pending',
    enum: ['pending', 'sent', 'delivered', 'failed'],
  })
  status!: string;
  @Prop() error?: string;
}
export const PayslipDeliveryLogSchema =
  SchemaFactory.createForClass(PayslipDeliveryLog);
 
// ────────────────────────────────────────────────────────────────
// 18. BANK TRANSFER & PAYMENTS
// ────────────────────────────────────────────────────────────────