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

0% Statements 0/68
0% Branches 0/4
100% Functions 0/0
0% Lines 0/58

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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169                                                                                                                                                                                                                                                                                                                                                 
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema as MongooseSchema } from 'mongoose';
 
@Schema({ timestamps: true, collection: 'work_weeks' })
export class WorkWeek extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ required: true })
  workWeekCode: string;
 
  @Prop({ required: true })
  workWeekName: string;
 
  @Prop()
  description: string;
 
  @Prop({ default: 'active' })
  status: string;
 
  @Prop({ default: null })
  createdBy: string;
}
export const WorkWeekSchema = SchemaFactory.createForClass(WorkWeek);
WorkWeekSchema.index({ tenantId: 1, workWeekCode: 1 }, { unique: true });
 
@Schema({ timestamps: true, collection: 'work_week_day_rules' })
export class WorkWeekDayRule extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({
    required: true,
    type: MongooseSchema.Types.ObjectId,
    ref: 'WorkWeek',
  })
  workWeekId: string;
 
  @Prop({ required: true })
  dayOfWeek: number; // 0=Sunday, 1=Monday...
 
  @Prop({ default: 'Working day' })
  dayType: string; // Working day, Weekly off, Half day
 
  @Prop()
  weekPattern: string; // All, Alternate, First and third, Second and fourth
 
  @Prop({ default: 0 })
  sequence: number; // For rotating weekly offs
 
  @Prop({ default: 480 })
  scheduledMinutes: number;
 
  @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'Shift', default: null })
  defaultShiftId: string;
}
export const WorkWeekDayRuleSchema =
  SchemaFactory.createForClass(WorkWeekDayRule);
WorkWeekDayRuleSchema.index({ tenantId: 1, workWeekId: 1 });
 
@Schema({ timestamps: true, collection: 'holiday_calendars' })
export class HolidayCalendar extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ required: true })
  calendarCode: string;
 
  @Prop({ required: true })
  calendarName: string;
 
  @Prop({ required: true })
  year: number;
 
  @Prop()
  description: string;
 
  @Prop({ default: 'active' })
  status: string;
 
  @Prop({ default: null })
  createdBy: string;
}
export const HolidayCalendarSchema =
  SchemaFactory.createForClass(HolidayCalendar);
HolidayCalendarSchema.index(
  { tenantId: 1, calendarCode: 1, year: 1 },
  { unique: true },
);
 
@Schema({ timestamps: true, collection: 'holidays' })
export class Holiday extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({
    required: true,
    type: MongooseSchema.Types.ObjectId,
    ref: 'HolidayCalendar',
  })
  holidayCalendarId: string;
 
  @Prop({ required: true })
  holidayCode: string;
 
  @Prop({ required: true })
  holidayName: string;
 
  @Prop({ required: true })
  date: Date;
 
  @Prop({ default: 'Public' })
  type: string; // Public, Company, Regional, Optional, Restricted, Bank, Local, Emergency
 
  @Prop()
  description: string;
 
  @Prop({ default: false })
  recurring: boolean;
 
  @Prop({ default: false })
  optional: boolean;
 
  @Prop({ default: false })
  halfDay: boolean;
 
  @Prop({ default: true })
  paid: boolean;
 
  @Prop({ type: [{ type: String }], default: [] })
  branchIds: string[];
 
  @Prop({ type: [{ type: String }], default: [] })
  locationIds: string[];
 
  @Prop()
  religionOrRegionReference: string;
 
  @Prop({ default: 'active' })
  status: string;
}
export const HolidaySchema = SchemaFactory.createForClass(Holiday);
HolidaySchema.index({ tenantId: 1, holidayCalendarId: 1, date: 1 });
 
@Schema({ timestamps: true, collection: 'optional_holiday_selections' })
export class OptionalHolidaySelection extends Document {
  @Prop({ required: true, index: true })
  tenantId: string;
 
  @Prop({ required: true, index: true })
  employeeId: string;
 
  @Prop({ required: true, type: MongooseSchema.Types.ObjectId, ref: 'Holiday' })
  holidayId: string;
 
  @Prop({ required: true })
  year: number;
 
  @Prop({ default: 'approved' })
  status: string;
}
export const OptionalHolidaySelectionSchema = SchemaFactory.createForClass(
  OptionalHolidaySelection,
);
OptionalHolidaySelectionSchema.index(
  { tenantId: 1, employeeId: 1, holidayId: 1 },
  { unique: true },
);