All files / src/domains/hr/attendance/schemas roster.schema.ts

0% Statements 0/61
0% Branches 0/16
100% Functions 0/0
0% Lines 0/51

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                                                                                                                                                                                                                                                                                                   
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema as MongooseSchema } from 'mongoose';
 
@Schema({ timestamps: true, collection: 'shift_rotations' })
export class ShiftRotation extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ required: true })
  rotationName: string;
 
  @Prop()
  description: string;
 
  @Prop({ default: 'Rotating Days' })
  pattern: string; // Fixed Weekly, Alternate Weekly, Rotating Days, Rotating Nights, 24x7 Rotation, Custom Pattern
 
  @Prop({ default: 'active' })
  status: string;
 
  @Prop({ default: null })
  createdBy: string;
}
export const ShiftRotationSchema = SchemaFactory.createForClass(ShiftRotation);
 
@Schema({ timestamps: true, collection: 'shift_rotation_steps' })
export class ShiftRotationStep extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({
    required: true,
    type: MongooseSchema.Types.ObjectId,
    ref: 'ShiftRotation',
  })
  rotationId: string;
 
  @Prop({ required: true })
  sequence: number;
 
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'Shift' })
  shiftId: string;
 
  @Prop({ default: 1 })
  durationDays: number;
}
export const ShiftRotationStepSchema =
  SchemaFactory.createForClass(ShiftRotationStep);
ShiftRotationStepSchema.index({ tenantId: 1, rotationId: 1, sequence: 1 });
 
@Schema({ timestamps: true, collection: 'shift_rosters' })
export class ShiftRoster extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ required: true })
  rosterName: string;
 
  @Prop()
  description: string;
 
  @Prop({ required: true })
  startDate: Date;
 
  @Prop({ required: true })
  endDate: Date;
 
  @Prop({ default: 'draft' })
  status: string; // draft, published, locked
 
  @Prop()
  targetType: string; // Branch, Team, Employee
 
  @Prop()
  targetId: string;
 
  @Prop({ default: null })
  createdBy: string;
}
export const ShiftRosterSchema = SchemaFactory.createForClass(ShiftRoster);
ShiftRosterSchema.index({ tenantId: 1, startDate: 1, endDate: 1 });
 
@Schema({ timestamps: true, collection: 'shift_roster_entries' })
export class ShiftRosterEntry extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({
    required: true,
    type: MongooseSchema.Types.ObjectId,
    ref: 'ShiftRoster',
  })
  rosterId: string;
 
  @Prop({ required: true, index: true })
  employeeId: string;
 
  @Prop({ required: true })
  rosterDate: Date;
 
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'Shift' })
  shiftId: string;
 
  @Prop({ default: false })
  isOffDay: boolean;
}
export const ShiftRosterEntrySchema =
  SchemaFactory.createForClass(ShiftRosterEntry);
ShiftRosterEntrySchema.index(
  { tenantId: 1, employeeId: 1, rosterDate: 1 },
  { unique: true },
);
 
@Schema({ timestamps: true, collection: 'shift_swap_requests' })
export class ShiftSwapRequest extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ required: true })
  requestingEmployeeId: string;
 
  @Prop({ required: true })
  targetEmployeeId: string;
 
  @Prop({ required: true })
  requestDate: Date;
 
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'Shift' })
  requestingShiftId: string;
 
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'Shift' })
  targetShiftId: string;
 
  @Prop()
  reason: string;
 
  @Prop({ default: 'pending' })
  status: string; // pending, approved, rejected, cancelled
 
  @Prop({ default: null })
  approvedBy: string;
}
export const ShiftSwapRequestSchema =
  SchemaFactory.createForClass(ShiftSwapRequest);
ShiftSwapRequestSchema.index({ tenantId: 1, requestingEmployeeId: 1 });