@managesome/eposmatic-toolkit 0.4.72 → 0.4.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/helpers/utils/hr-helpers.js +0 -10
- package/esm/helpers/utils/shift-window-helpers.js +24 -13
- package/esm/schemas/models/tenant_hr_attendance_records.js +2 -2
- package/esm/schemas/models/tenant_hr_employees.js +0 -10
- package/esm/schemas/models/tenant_hr_shift_schedules.js +3 -38
- package/esm/schemas/models/tenant_hr_shifts.js +27 -13
- package/lib/helpers/utils/hr-helpers.d.ts +0 -2
- package/lib/helpers/utils/hr-helpers.js +0 -10
- package/lib/helpers/utils/shift-window-helpers.d.ts +13 -7
- package/lib/helpers/utils/shift-window-helpers.js +24 -13
- package/lib/schemas/models/tenant_hr_attendance_records.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_attendance_records.js +2 -2
- package/lib/schemas/models/tenant_hr_employees.d.ts +0 -6
- package/lib/schemas/models/tenant_hr_employees.js +0 -10
- package/lib/schemas/models/tenant_hr_shift_schedules.d.ts +0 -19
- package/lib/schemas/models/tenant_hr_shift_schedules.js +3 -38
- package/lib/schemas/models/tenant_hr_shifts.d.ts +12 -30
- package/lib/schemas/models/tenant_hr_shifts.js +27 -13
- package/lib/schemas/types/tenant_hr_attendance_records.d.ts +2 -2
- package/lib/schemas/types/tenant_hr_employees.d.ts +1 -3
- package/lib/schemas/types/tenant_hr_shift_schedules.d.ts +2 -9
- package/lib/schemas/types/tenant_hr_shifts.d.ts +6 -6
- package/lib/tests/shift-window-helpers.test.js +23 -2
- package/lib/tests/tenant_hr_employees.test.d.ts +1 -0
- package/lib/tests/tenant_hr_employees.test.js +82 -0
- package/lib/tests/tenant_hr_shift_schedules.test.d.ts +1 -0
- package/lib/tests/tenant_hr_shift_schedules.test.js +68 -0
- package/lib/tests/tenant_hr_shifts.test.d.ts +1 -0
- package/lib/tests/tenant_hr_shifts.test.js +61 -0
- package/package.json +1 -1
|
@@ -42,16 +42,6 @@ export function getHrEmployeeWithPrice(employee, writeable) {
|
|
|
42
42
|
: {}),
|
|
43
43
|
...(employee.salary_per_hour != null ? { salary_per_hour: convert(employee.salary_per_hour) } : {}),
|
|
44
44
|
...(employee.monthly_salary != null ? { monthly_salary: convert(employee.monthly_salary) } : {}),
|
|
45
|
-
...(employee.hr_working_days_per_month != null
|
|
46
|
-
? {
|
|
47
|
-
hr_working_days_per_month: convert(employee.hr_working_days_per_month),
|
|
48
|
-
}
|
|
49
|
-
: {}),
|
|
50
|
-
...(employee.hr_hours_per_working_day != null
|
|
51
|
-
? {
|
|
52
|
-
hr_hours_per_working_day: convert(employee.hr_hours_per_working_day),
|
|
53
|
-
}
|
|
54
|
-
: {}),
|
|
55
45
|
...(employee.hr_overtime_multiplier != null
|
|
56
46
|
? { hr_overtime_multiplier: convert(employee.hr_overtime_multiplier) }
|
|
57
47
|
: {}),
|
|
@@ -94,14 +94,20 @@ export function getFirstShiftStartPosition(shifts, dayMidnightMs, dayIndex) {
|
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* Whether a new business day may be started for a CLOSED day (mirrors the POS
|
|
97
|
-
* `dayWindow` / the backend day guard)
|
|
98
|
-
* BEHIND the tenant's current local date
|
|
99
|
-
* elapsed
|
|
100
|
-
* closed day's weekday.
|
|
97
|
+
* `dayWindow` / the backend day guard). The closed day's `localDate` must be
|
|
98
|
+
* BEHIND the tenant's current local date and the closed day must have fully
|
|
99
|
+
* elapsed:
|
|
101
100
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
101
|
+
* - the closed day has scheduled shifts → `now` is past the LAST end position
|
|
102
|
+
* on that weekday. The next weekday's schedule is irrelevant; it may be an
|
|
103
|
+
* off-day, and the following business day must still become startable.
|
|
104
|
+
* - the closed day has NO scheduled shifts (off-day) → `now` is at or past the
|
|
105
|
+
* NEXT calendar day's FIRST shift start (the next business day has entered —
|
|
106
|
+
* the same boundary `hasNextDayFirstShiftStarted` uses).
|
|
107
|
+
*
|
|
108
|
+
* Returns `null` only when there is no anchor at all (no shift scheduled on
|
|
109
|
+
* either the closed day's weekday or the next day's weekday) — callers apply
|
|
110
|
+
* their legacy fallback (e.g. "a new day may start only when none is running").
|
|
105
111
|
*/
|
|
106
112
|
export function canStartNewBusinessDay(shifts, dayLocalDate, gmtOffset, now = new Date()) {
|
|
107
113
|
const frame = getTenantFramePosition(gmtOffset, now);
|
|
@@ -109,14 +115,19 @@ export function canStartNewBusinessDay(shifts, dayLocalDate, gmtOffset, now = ne
|
|
|
109
115
|
const nextDayMidnightMs = dayMidnightMs + MS_IN_DAY;
|
|
110
116
|
const dayIndex = ALL_DAY_INDEX[new Date(dayMidnightMs).getUTCDay()];
|
|
111
117
|
const nextDayIndex = ALL_DAY_INDEX[new Date(nextDayMidnightMs).getUTCDay()];
|
|
118
|
+
// A day only advances once the closed date is behind the tenant's date.
|
|
119
|
+
if (dayLocalDate >= formatLocalDateFromMidnight(frame.dayMidnightMs))
|
|
120
|
+
return false;
|
|
112
121
|
const lastEndPosition = getLastShiftEndPosition(shifts, dayMidnightMs, dayIndex);
|
|
113
122
|
const firstNextStartPosition = getFirstShiftStartPosition(shifts, nextDayMidnightMs, nextDayIndex);
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
123
|
+
// Off-day closed day: it has no window of its own to wait for, so the next
|
|
124
|
+
// business day's first shift start is the anchor.
|
|
125
|
+
if (lastEndPosition == null) {
|
|
126
|
+
return firstNextStartPosition == null ? null : frame.nowPos >= firstNextStartPosition;
|
|
127
|
+
}
|
|
128
|
+
// The closed day has fully elapsed once its own last shift ended. An off-day
|
|
129
|
+
// on the next weekday must not postpone the following business day.
|
|
130
|
+
return frame.nowPos > lastEndPosition;
|
|
120
131
|
}
|
|
121
132
|
/**
|
|
122
133
|
* Normalizes a shift time-range into coverage intervals on the
|
|
@@ -54,10 +54,10 @@ export const TenantHrAttendanceRecordSchema = new Schema({
|
|
|
54
54
|
required: true,
|
|
55
55
|
match: /^\d{4}-\d{2}-\d{2}$/,
|
|
56
56
|
},
|
|
57
|
-
|
|
57
|
+
shift_id: {
|
|
58
58
|
type: String,
|
|
59
59
|
required: true,
|
|
60
|
-
ref: '
|
|
60
|
+
ref: 'tenant_hr_shifts',
|
|
61
61
|
},
|
|
62
62
|
clock_time: {
|
|
63
63
|
type: [hrClockTimeSchema],
|
|
@@ -124,16 +124,6 @@ export const TenantHrEmployeeSchema = new Schema({
|
|
|
124
124
|
type: Number,
|
|
125
125
|
default: null,
|
|
126
126
|
},
|
|
127
|
-
hr_working_days_per_month: {
|
|
128
|
-
type: Number,
|
|
129
|
-
required: true,
|
|
130
|
-
default: 0,
|
|
131
|
-
},
|
|
132
|
-
hr_hours_per_working_day: {
|
|
133
|
-
type: Number,
|
|
134
|
-
required: true,
|
|
135
|
-
default: 0,
|
|
136
|
-
},
|
|
137
127
|
hr_overtime_multiplier: {
|
|
138
128
|
type: Number,
|
|
139
129
|
required: true,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Schema } from 'mongoose';
|
|
2
|
-
import { ALL_DAY_INDEX, ALL_HR_SHIFT_STATUS_NAMES, ALL_HR_SHIFT_TYPE_NAMES, HR_SHIFT_STATUS_ENUM, HR_SHIFT_TYPE_ENUM, } from '../../constants';
|
|
3
2
|
export const TenantHrShiftScheduleSchema = new Schema({
|
|
4
3
|
_id: {
|
|
5
4
|
type: Schema.Types.ObjectId,
|
|
@@ -18,11 +17,10 @@ export const TenantHrShiftScheduleSchema = new Schema({
|
|
|
18
17
|
immutable: true,
|
|
19
18
|
ref: 'tenant_hr_employees',
|
|
20
19
|
},
|
|
21
|
-
|
|
22
|
-
type:
|
|
23
|
-
enum: ALL_DAY_INDEX,
|
|
20
|
+
shift_id: {
|
|
21
|
+
type: String,
|
|
24
22
|
required: true,
|
|
25
|
-
|
|
23
|
+
ref: 'tenant_hr_shifts',
|
|
26
24
|
},
|
|
27
25
|
start_date: {
|
|
28
26
|
type: Date,
|
|
@@ -32,43 +30,10 @@ export const TenantHrShiftScheduleSchema = new Schema({
|
|
|
32
30
|
type: Date,
|
|
33
31
|
default: null,
|
|
34
32
|
},
|
|
35
|
-
start_time: {
|
|
36
|
-
type: Number,
|
|
37
|
-
required: true,
|
|
38
|
-
min: 0,
|
|
39
|
-
max: 86399,
|
|
40
|
-
},
|
|
41
|
-
end_time: {
|
|
42
|
-
type: Number,
|
|
43
|
-
required: true,
|
|
44
|
-
min: 0,
|
|
45
|
-
max: 86399,
|
|
46
|
-
},
|
|
47
|
-
position: {
|
|
48
|
-
type: String,
|
|
49
|
-
default: null,
|
|
50
|
-
},
|
|
51
|
-
type: {
|
|
52
|
-
type: String,
|
|
53
|
-
required: true,
|
|
54
|
-
enum: ALL_HR_SHIFT_TYPE_NAMES,
|
|
55
|
-
default: HR_SHIFT_TYPE_ENUM.REGULAR,
|
|
56
|
-
},
|
|
57
|
-
status: {
|
|
58
|
-
type: String,
|
|
59
|
-
required: true,
|
|
60
|
-
enum: ALL_HR_SHIFT_STATUS_NAMES,
|
|
61
|
-
default: HR_SHIFT_STATUS_ENUM.SCHEDULED,
|
|
62
|
-
},
|
|
63
33
|
notes: {
|
|
64
34
|
type: String,
|
|
65
35
|
default: null,
|
|
66
36
|
},
|
|
67
|
-
shift_id: {
|
|
68
|
-
type: String,
|
|
69
|
-
default: null,
|
|
70
|
-
ref: 'tenant_hr_shifts',
|
|
71
|
-
},
|
|
72
37
|
createdAt: {
|
|
73
38
|
type: Schema.Types.Date,
|
|
74
39
|
required: true,
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { Schema } from 'mongoose';
|
|
2
|
-
|
|
3
|
-
position: {
|
|
4
|
-
type: String,
|
|
5
|
-
required: true,
|
|
6
|
-
},
|
|
7
|
-
count: {
|
|
8
|
-
type: Number,
|
|
9
|
-
required: true,
|
|
10
|
-
},
|
|
11
|
-
}, { _id: false, minimize: false });
|
|
2
|
+
import { ALL_DAY_INDEX } from '../../constants';
|
|
12
3
|
export const TenantHrShiftSchema = new Schema({
|
|
13
4
|
_id: {
|
|
14
5
|
type: Schema.Types.ObjectId,
|
|
@@ -37,13 +28,36 @@ export const TenantHrShiftSchema = new Schema({
|
|
|
37
28
|
min: 0,
|
|
38
29
|
max: 86399,
|
|
39
30
|
},
|
|
31
|
+
break_start_time: {
|
|
32
|
+
type: Number,
|
|
33
|
+
default: null,
|
|
34
|
+
min: 0,
|
|
35
|
+
max: 86399,
|
|
36
|
+
},
|
|
37
|
+
break_end_time: {
|
|
38
|
+
type: Number,
|
|
39
|
+
default: null,
|
|
40
|
+
min: 0,
|
|
41
|
+
max: 86399,
|
|
42
|
+
},
|
|
43
|
+
working_days: {
|
|
44
|
+
type: [String],
|
|
45
|
+
enum: ALL_DAY_INDEX,
|
|
46
|
+
required: true,
|
|
47
|
+
validate: {
|
|
48
|
+
validator: (days) => Array.isArray(days) && days.length > 0,
|
|
49
|
+
message: 'working_days must contain at least one day',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
40
52
|
grace_period_minutes: {
|
|
41
53
|
type: Number,
|
|
42
54
|
default: null,
|
|
43
55
|
},
|
|
44
|
-
|
|
45
|
-
type:
|
|
46
|
-
default:
|
|
56
|
+
overtime_start_time: {
|
|
57
|
+
type: Number,
|
|
58
|
+
default: null,
|
|
59
|
+
min: 0,
|
|
60
|
+
max: 86399,
|
|
47
61
|
},
|
|
48
62
|
is_active: {
|
|
49
63
|
type: Boolean,
|
|
@@ -22,8 +22,6 @@ export declare function getHrPayrollsFetchedData(data: ITenantHrPayroll[]): ITen
|
|
|
22
22
|
export interface IHrEmployeePriceFields {
|
|
23
23
|
salary_per_hour?: number | null;
|
|
24
24
|
monthly_salary?: number | null;
|
|
25
|
-
hr_working_days_per_month?: number | null;
|
|
26
|
-
hr_hours_per_working_day?: number | null;
|
|
27
25
|
hr_overtime_multiplier?: number | null;
|
|
28
26
|
leave_allowance?: Partial<Record<HR_LEAVE_TYPE_ENUM, number>> | null;
|
|
29
27
|
}
|
|
@@ -48,16 +48,6 @@ function getHrEmployeeWithPrice(employee, writeable) {
|
|
|
48
48
|
: {}),
|
|
49
49
|
...(employee.salary_per_hour != null ? { salary_per_hour: convert(employee.salary_per_hour) } : {}),
|
|
50
50
|
...(employee.monthly_salary != null ? { monthly_salary: convert(employee.monthly_salary) } : {}),
|
|
51
|
-
...(employee.hr_working_days_per_month != null
|
|
52
|
-
? {
|
|
53
|
-
hr_working_days_per_month: convert(employee.hr_working_days_per_month),
|
|
54
|
-
}
|
|
55
|
-
: {}),
|
|
56
|
-
...(employee.hr_hours_per_working_day != null
|
|
57
|
-
? {
|
|
58
|
-
hr_hours_per_working_day: convert(employee.hr_hours_per_working_day),
|
|
59
|
-
}
|
|
60
|
-
: {}),
|
|
61
51
|
...(employee.hr_overtime_multiplier != null
|
|
62
52
|
? { hr_overtime_multiplier: convert(employee.hr_overtime_multiplier) }
|
|
63
53
|
: {}),
|
|
@@ -82,14 +82,20 @@ export declare function getLastShiftEndPosition(shifts: IShiftWindowSource[], da
|
|
|
82
82
|
export declare function getFirstShiftStartPosition(shifts: IShiftWindowSource[], dayMidnightMs: number, dayIndex: DAY_INDEX_ENUM): number | null;
|
|
83
83
|
/**
|
|
84
84
|
* Whether a new business day may be started for a CLOSED day (mirrors the POS
|
|
85
|
-
* `dayWindow` / the backend day guard)
|
|
86
|
-
* BEHIND the tenant's current local date
|
|
87
|
-
* elapsed
|
|
88
|
-
* closed day's weekday.
|
|
85
|
+
* `dayWindow` / the backend day guard). The closed day's `localDate` must be
|
|
86
|
+
* BEHIND the tenant's current local date and the closed day must have fully
|
|
87
|
+
* elapsed:
|
|
89
88
|
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
89
|
+
* - the closed day has scheduled shifts → `now` is past the LAST end position
|
|
90
|
+
* on that weekday. The next weekday's schedule is irrelevant; it may be an
|
|
91
|
+
* off-day, and the following business day must still become startable.
|
|
92
|
+
* - the closed day has NO scheduled shifts (off-day) → `now` is at or past the
|
|
93
|
+
* NEXT calendar day's FIRST shift start (the next business day has entered —
|
|
94
|
+
* the same boundary `hasNextDayFirstShiftStarted` uses).
|
|
95
|
+
*
|
|
96
|
+
* Returns `null` only when there is no anchor at all (no shift scheduled on
|
|
97
|
+
* either the closed day's weekday or the next day's weekday) — callers apply
|
|
98
|
+
* their legacy fallback (e.g. "a new day may start only when none is running").
|
|
93
99
|
*/
|
|
94
100
|
export declare function canStartNewBusinessDay(shifts: IShiftWindowSource[], dayLocalDate: string, gmtOffset: number, now?: Date): boolean | null;
|
|
95
101
|
/**
|
|
@@ -110,14 +110,20 @@ function getFirstShiftStartPosition(shifts, dayMidnightMs, dayIndex) {
|
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
112
|
* Whether a new business day may be started for a CLOSED day (mirrors the POS
|
|
113
|
-
* `dayWindow` / the backend day guard)
|
|
114
|
-
* BEHIND the tenant's current local date
|
|
115
|
-
* elapsed
|
|
116
|
-
* closed day's weekday.
|
|
113
|
+
* `dayWindow` / the backend day guard). The closed day's `localDate` must be
|
|
114
|
+
* BEHIND the tenant's current local date and the closed day must have fully
|
|
115
|
+
* elapsed:
|
|
117
116
|
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
117
|
+
* - the closed day has scheduled shifts → `now` is past the LAST end position
|
|
118
|
+
* on that weekday. The next weekday's schedule is irrelevant; it may be an
|
|
119
|
+
* off-day, and the following business day must still become startable.
|
|
120
|
+
* - the closed day has NO scheduled shifts (off-day) → `now` is at or past the
|
|
121
|
+
* NEXT calendar day's FIRST shift start (the next business day has entered —
|
|
122
|
+
* the same boundary `hasNextDayFirstShiftStarted` uses).
|
|
123
|
+
*
|
|
124
|
+
* Returns `null` only when there is no anchor at all (no shift scheduled on
|
|
125
|
+
* either the closed day's weekday or the next day's weekday) — callers apply
|
|
126
|
+
* their legacy fallback (e.g. "a new day may start only when none is running").
|
|
121
127
|
*/
|
|
122
128
|
function canStartNewBusinessDay(shifts, dayLocalDate, gmtOffset, now = new Date()) {
|
|
123
129
|
const frame = getTenantFramePosition(gmtOffset, now);
|
|
@@ -125,14 +131,19 @@ function canStartNewBusinessDay(shifts, dayLocalDate, gmtOffset, now = new Date(
|
|
|
125
131
|
const nextDayMidnightMs = dayMidnightMs + exports.MS_IN_DAY;
|
|
126
132
|
const dayIndex = constants_1.ALL_DAY_INDEX[new Date(dayMidnightMs).getUTCDay()];
|
|
127
133
|
const nextDayIndex = constants_1.ALL_DAY_INDEX[new Date(nextDayMidnightMs).getUTCDay()];
|
|
134
|
+
// A day only advances once the closed date is behind the tenant's date.
|
|
135
|
+
if (dayLocalDate >= formatLocalDateFromMidnight(frame.dayMidnightMs))
|
|
136
|
+
return false;
|
|
128
137
|
const lastEndPosition = getLastShiftEndPosition(shifts, dayMidnightMs, dayIndex);
|
|
129
138
|
const firstNextStartPosition = getFirstShiftStartPosition(shifts, nextDayMidnightMs, nextDayIndex);
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
// Off-day closed day: it has no window of its own to wait for, so the next
|
|
140
|
+
// business day's first shift start is the anchor.
|
|
141
|
+
if (lastEndPosition == null) {
|
|
142
|
+
return firstNextStartPosition == null ? null : frame.nowPos >= firstNextStartPosition;
|
|
143
|
+
}
|
|
144
|
+
// The closed day has fully elapsed once its own last shift ended. An off-day
|
|
145
|
+
// on the next weekday must not postpone the following business day.
|
|
146
|
+
return frame.nowPos > lastEndPosition;
|
|
136
147
|
}
|
|
137
148
|
/**
|
|
138
149
|
* Normalizes a shift time-range into coverage intervals on the
|
|
@@ -14,6 +14,7 @@ export declare const TenantHrAttendanceRecordSchema: Schema<any, import("mongoos
|
|
|
14
14
|
tenant_id: string;
|
|
15
15
|
status: HR_ATTENDANCE_STATUS_ENUM;
|
|
16
16
|
employee_id: string;
|
|
17
|
+
shift_id: string;
|
|
17
18
|
break_time: import("mongoose").Types.DocumentArray<{
|
|
18
19
|
start_time: number;
|
|
19
20
|
end_time: number;
|
|
@@ -25,7 +26,6 @@ export declare const TenantHrAttendanceRecordSchema: Schema<any, import("mongoos
|
|
|
25
26
|
end_time: number;
|
|
26
27
|
}>;
|
|
27
28
|
attendance_date: string;
|
|
28
|
-
schedule_id: string;
|
|
29
29
|
clock_time: import("mongoose").Types.DocumentArray<{
|
|
30
30
|
type: import("../../constants").HR_CLOCK_TIME_TYPE_ENUM;
|
|
31
31
|
method: import("../../constants").HR_CHECK_IN_METHOD_ENUM;
|
|
@@ -51,6 +51,7 @@ export declare const TenantHrAttendanceRecordSchema: Schema<any, import("mongoos
|
|
|
51
51
|
tenant_id: string;
|
|
52
52
|
status: HR_ATTENDANCE_STATUS_ENUM;
|
|
53
53
|
employee_id: string;
|
|
54
|
+
shift_id: string;
|
|
54
55
|
break_time: import("mongoose").Types.DocumentArray<{
|
|
55
56
|
start_time: number;
|
|
56
57
|
end_time: number;
|
|
@@ -62,7 +63,6 @@ export declare const TenantHrAttendanceRecordSchema: Schema<any, import("mongoos
|
|
|
62
63
|
end_time: number;
|
|
63
64
|
}>;
|
|
64
65
|
attendance_date: string;
|
|
65
|
-
schedule_id: string;
|
|
66
66
|
clock_time: import("mongoose").Types.DocumentArray<{
|
|
67
67
|
type: import("../../constants").HR_CLOCK_TIME_TYPE_ENUM;
|
|
68
68
|
method: import("../../constants").HR_CHECK_IN_METHOD_ENUM;
|
|
@@ -88,6 +88,7 @@ export declare const TenantHrAttendanceRecordSchema: Schema<any, import("mongoos
|
|
|
88
88
|
tenant_id: string;
|
|
89
89
|
status: HR_ATTENDANCE_STATUS_ENUM;
|
|
90
90
|
employee_id: string;
|
|
91
|
+
shift_id: string;
|
|
91
92
|
break_time: import("mongoose").Types.DocumentArray<{
|
|
92
93
|
start_time: number;
|
|
93
94
|
end_time: number;
|
|
@@ -99,7 +100,6 @@ export declare const TenantHrAttendanceRecordSchema: Schema<any, import("mongoos
|
|
|
99
100
|
end_time: number;
|
|
100
101
|
}>;
|
|
101
102
|
attendance_date: string;
|
|
102
|
-
schedule_id: string;
|
|
103
103
|
clock_time: import("mongoose").Types.DocumentArray<{
|
|
104
104
|
type: import("../../constants").HR_CLOCK_TIME_TYPE_ENUM;
|
|
105
105
|
method: import("../../constants").HR_CHECK_IN_METHOD_ENUM;
|
|
@@ -57,10 +57,10 @@ exports.TenantHrAttendanceRecordSchema = new mongoose_1.Schema({
|
|
|
57
57
|
required: true,
|
|
58
58
|
match: /^\d{4}-\d{2}-\d{2}$/,
|
|
59
59
|
},
|
|
60
|
-
|
|
60
|
+
shift_id: {
|
|
61
61
|
type: String,
|
|
62
62
|
required: true,
|
|
63
|
-
ref: '
|
|
63
|
+
ref: 'tenant_hr_shifts',
|
|
64
64
|
},
|
|
65
65
|
clock_time: {
|
|
66
66
|
type: [hrClockTimeSchema],
|
|
@@ -25,8 +25,6 @@ export declare const TenantHrEmployeeSchema: Schema<any, import("mongoose").Mode
|
|
|
25
25
|
monthly_salary: number;
|
|
26
26
|
pay_type: HR_PAY_TYPE_ENUM;
|
|
27
27
|
leave_allowance: Map<string, number>;
|
|
28
|
-
hr_working_days_per_month: number;
|
|
29
|
-
hr_hours_per_working_day: number;
|
|
30
28
|
hr_overtime_multiplier: number;
|
|
31
29
|
staff_auth_code: string;
|
|
32
30
|
address: string;
|
|
@@ -351,8 +349,6 @@ export declare const TenantHrEmployeeSchema: Schema<any, import("mongoose").Mode
|
|
|
351
349
|
monthly_salary: number;
|
|
352
350
|
pay_type: HR_PAY_TYPE_ENUM;
|
|
353
351
|
leave_allowance: Map<string, number>;
|
|
354
|
-
hr_working_days_per_month: number;
|
|
355
|
-
hr_hours_per_working_day: number;
|
|
356
352
|
hr_overtime_multiplier: number;
|
|
357
353
|
staff_auth_code: string;
|
|
358
354
|
address: string;
|
|
@@ -677,8 +673,6 @@ export declare const TenantHrEmployeeSchema: Schema<any, import("mongoose").Mode
|
|
|
677
673
|
monthly_salary: number;
|
|
678
674
|
pay_type: HR_PAY_TYPE_ENUM;
|
|
679
675
|
leave_allowance: Map<string, number>;
|
|
680
|
-
hr_working_days_per_month: number;
|
|
681
|
-
hr_hours_per_working_day: number;
|
|
682
676
|
hr_overtime_multiplier: number;
|
|
683
677
|
staff_auth_code: string;
|
|
684
678
|
address: string;
|
|
@@ -127,16 +127,6 @@ exports.TenantHrEmployeeSchema = new mongoose_1.Schema({
|
|
|
127
127
|
type: Number,
|
|
128
128
|
default: null,
|
|
129
129
|
},
|
|
130
|
-
hr_working_days_per_month: {
|
|
131
|
-
type: Number,
|
|
132
|
-
required: true,
|
|
133
|
-
default: 0,
|
|
134
|
-
},
|
|
135
|
-
hr_hours_per_working_day: {
|
|
136
|
-
type: Number,
|
|
137
|
-
required: true,
|
|
138
|
-
default: 0,
|
|
139
|
-
},
|
|
140
130
|
hr_overtime_multiplier: {
|
|
141
131
|
type: Number,
|
|
142
132
|
required: true,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Schema } from 'mongoose';
|
|
2
|
-
import { HR_SHIFT_STATUS_ENUM, HR_SHIFT_TYPE_ENUM } from '../../constants';
|
|
3
2
|
export declare const TenantHrShiftScheduleSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
4
3
|
timestamps: true;
|
|
5
4
|
versionKey: false;
|
|
@@ -9,17 +8,11 @@ export declare const TenantHrShiftScheduleSchema: Schema<any, import("mongoose")
|
|
|
9
8
|
updatedAt: NativeDate;
|
|
10
9
|
} & {
|
|
11
10
|
_id: import("mongoose").Types.ObjectId;
|
|
12
|
-
type: HR_SHIFT_TYPE_ENUM;
|
|
13
11
|
createdAt: NativeDate;
|
|
14
12
|
updatedAt: NativeDate;
|
|
15
|
-
position: string;
|
|
16
|
-
start_time: number;
|
|
17
|
-
end_time: number;
|
|
18
13
|
start_date: NativeDate;
|
|
19
14
|
end_date: NativeDate;
|
|
20
15
|
tenant_id: string;
|
|
21
|
-
status: HR_SHIFT_STATUS_ENUM;
|
|
22
|
-
day_indexes: string[];
|
|
23
16
|
notes: string;
|
|
24
17
|
employee_id: string;
|
|
25
18
|
shift_id: string;
|
|
@@ -28,17 +21,11 @@ export declare const TenantHrShiftScheduleSchema: Schema<any, import("mongoose")
|
|
|
28
21
|
updatedAt: NativeDate;
|
|
29
22
|
} & {
|
|
30
23
|
_id: import("mongoose").Types.ObjectId;
|
|
31
|
-
type: HR_SHIFT_TYPE_ENUM;
|
|
32
24
|
createdAt: NativeDate;
|
|
33
25
|
updatedAt: NativeDate;
|
|
34
|
-
position: string;
|
|
35
|
-
start_time: number;
|
|
36
|
-
end_time: number;
|
|
37
26
|
start_date: NativeDate;
|
|
38
27
|
end_date: NativeDate;
|
|
39
28
|
tenant_id: string;
|
|
40
|
-
status: HR_SHIFT_STATUS_ENUM;
|
|
41
|
-
day_indexes: string[];
|
|
42
29
|
notes: string;
|
|
43
30
|
employee_id: string;
|
|
44
31
|
shift_id: string;
|
|
@@ -47,17 +34,11 @@ export declare const TenantHrShiftScheduleSchema: Schema<any, import("mongoose")
|
|
|
47
34
|
updatedAt: NativeDate;
|
|
48
35
|
} & {
|
|
49
36
|
_id: import("mongoose").Types.ObjectId;
|
|
50
|
-
type: HR_SHIFT_TYPE_ENUM;
|
|
51
37
|
createdAt: NativeDate;
|
|
52
38
|
updatedAt: NativeDate;
|
|
53
|
-
position: string;
|
|
54
|
-
start_time: number;
|
|
55
|
-
end_time: number;
|
|
56
39
|
start_date: NativeDate;
|
|
57
40
|
end_date: NativeDate;
|
|
58
41
|
tenant_id: string;
|
|
59
|
-
status: HR_SHIFT_STATUS_ENUM;
|
|
60
|
-
day_indexes: string[];
|
|
61
42
|
notes: string;
|
|
62
43
|
employee_id: string;
|
|
63
44
|
shift_id: string;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TENANT_HR_SHIFT_SCHEDULES_COLLECTION_NAME = exports.TenantHrShiftScheduleSchema = void 0;
|
|
4
4
|
const mongoose_1 = require("mongoose");
|
|
5
|
-
const constants_1 = require("../../constants");
|
|
6
5
|
exports.TenantHrShiftScheduleSchema = new mongoose_1.Schema({
|
|
7
6
|
_id: {
|
|
8
7
|
type: mongoose_1.Schema.Types.ObjectId,
|
|
@@ -21,11 +20,10 @@ exports.TenantHrShiftScheduleSchema = new mongoose_1.Schema({
|
|
|
21
20
|
immutable: true,
|
|
22
21
|
ref: 'tenant_hr_employees',
|
|
23
22
|
},
|
|
24
|
-
|
|
25
|
-
type:
|
|
26
|
-
enum: constants_1.ALL_DAY_INDEX,
|
|
23
|
+
shift_id: {
|
|
24
|
+
type: String,
|
|
27
25
|
required: true,
|
|
28
|
-
|
|
26
|
+
ref: 'tenant_hr_shifts',
|
|
29
27
|
},
|
|
30
28
|
start_date: {
|
|
31
29
|
type: Date,
|
|
@@ -35,43 +33,10 @@ exports.TenantHrShiftScheduleSchema = new mongoose_1.Schema({
|
|
|
35
33
|
type: Date,
|
|
36
34
|
default: null,
|
|
37
35
|
},
|
|
38
|
-
start_time: {
|
|
39
|
-
type: Number,
|
|
40
|
-
required: true,
|
|
41
|
-
min: 0,
|
|
42
|
-
max: 86399,
|
|
43
|
-
},
|
|
44
|
-
end_time: {
|
|
45
|
-
type: Number,
|
|
46
|
-
required: true,
|
|
47
|
-
min: 0,
|
|
48
|
-
max: 86399,
|
|
49
|
-
},
|
|
50
|
-
position: {
|
|
51
|
-
type: String,
|
|
52
|
-
default: null,
|
|
53
|
-
},
|
|
54
|
-
type: {
|
|
55
|
-
type: String,
|
|
56
|
-
required: true,
|
|
57
|
-
enum: constants_1.ALL_HR_SHIFT_TYPE_NAMES,
|
|
58
|
-
default: constants_1.HR_SHIFT_TYPE_ENUM.REGULAR,
|
|
59
|
-
},
|
|
60
|
-
status: {
|
|
61
|
-
type: String,
|
|
62
|
-
required: true,
|
|
63
|
-
enum: constants_1.ALL_HR_SHIFT_STATUS_NAMES,
|
|
64
|
-
default: constants_1.HR_SHIFT_STATUS_ENUM.SCHEDULED,
|
|
65
|
-
},
|
|
66
36
|
notes: {
|
|
67
37
|
type: String,
|
|
68
38
|
default: null,
|
|
69
39
|
},
|
|
70
|
-
shift_id: {
|
|
71
|
-
type: String,
|
|
72
|
-
default: null,
|
|
73
|
-
ref: 'tenant_hr_shifts',
|
|
74
|
-
},
|
|
75
40
|
createdAt: {
|
|
76
41
|
type: mongoose_1.Schema.Types.Date,
|
|
77
42
|
required: true,
|
|
@@ -15,17 +15,11 @@ export declare const TenantHrShiftSchema: Schema<any, import("mongoose").Model<a
|
|
|
15
15
|
end_time: number;
|
|
16
16
|
tenant_id: string;
|
|
17
17
|
is_active: boolean;
|
|
18
|
+
break_start_time: number;
|
|
19
|
+
break_end_time: number;
|
|
20
|
+
working_days: string[];
|
|
18
21
|
grace_period_minutes: number;
|
|
19
|
-
|
|
20
|
-
count: number;
|
|
21
|
-
position: string;
|
|
22
|
-
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
23
|
-
count: number;
|
|
24
|
-
position: string;
|
|
25
|
-
}> & {
|
|
26
|
-
count: number;
|
|
27
|
-
position: string;
|
|
28
|
-
}>;
|
|
22
|
+
overtime_start_time: number;
|
|
29
23
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
30
24
|
createdAt: NativeDate;
|
|
31
25
|
updatedAt: NativeDate;
|
|
@@ -38,17 +32,11 @@ export declare const TenantHrShiftSchema: Schema<any, import("mongoose").Model<a
|
|
|
38
32
|
end_time: number;
|
|
39
33
|
tenant_id: string;
|
|
40
34
|
is_active: boolean;
|
|
35
|
+
break_start_time: number;
|
|
36
|
+
break_end_time: number;
|
|
37
|
+
working_days: string[];
|
|
41
38
|
grace_period_minutes: number;
|
|
42
|
-
|
|
43
|
-
count: number;
|
|
44
|
-
position: string;
|
|
45
|
-
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
46
|
-
count: number;
|
|
47
|
-
position: string;
|
|
48
|
-
}> & {
|
|
49
|
-
count: number;
|
|
50
|
-
position: string;
|
|
51
|
-
}>;
|
|
39
|
+
overtime_start_time: number;
|
|
52
40
|
}>> & import("mongoose").FlatRecord<{
|
|
53
41
|
createdAt: NativeDate;
|
|
54
42
|
updatedAt: NativeDate;
|
|
@@ -61,17 +49,11 @@ export declare const TenantHrShiftSchema: Schema<any, import("mongoose").Model<a
|
|
|
61
49
|
end_time: number;
|
|
62
50
|
tenant_id: string;
|
|
63
51
|
is_active: boolean;
|
|
52
|
+
break_start_time: number;
|
|
53
|
+
break_end_time: number;
|
|
54
|
+
working_days: string[];
|
|
64
55
|
grace_period_minutes: number;
|
|
65
|
-
|
|
66
|
-
count: number;
|
|
67
|
-
position: string;
|
|
68
|
-
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
69
|
-
count: number;
|
|
70
|
-
position: string;
|
|
71
|
-
}> & {
|
|
72
|
-
count: number;
|
|
73
|
-
position: string;
|
|
74
|
-
}>;
|
|
56
|
+
overtime_start_time: number;
|
|
75
57
|
}> & Required<{
|
|
76
58
|
_id: import("mongoose").Types.ObjectId;
|
|
77
59
|
}> & {
|
|
@@ -2,16 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TENANT_HR_SHIFTS_COLLECTION_NAME = exports.TenantHrShiftSchema = void 0;
|
|
4
4
|
const mongoose_1 = require("mongoose");
|
|
5
|
-
const
|
|
6
|
-
position: {
|
|
7
|
-
type: String,
|
|
8
|
-
required: true,
|
|
9
|
-
},
|
|
10
|
-
count: {
|
|
11
|
-
type: Number,
|
|
12
|
-
required: true,
|
|
13
|
-
},
|
|
14
|
-
}, { _id: false, minimize: false });
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
15
6
|
exports.TenantHrShiftSchema = new mongoose_1.Schema({
|
|
16
7
|
_id: {
|
|
17
8
|
type: mongoose_1.Schema.Types.ObjectId,
|
|
@@ -40,13 +31,36 @@ exports.TenantHrShiftSchema = new mongoose_1.Schema({
|
|
|
40
31
|
min: 0,
|
|
41
32
|
max: 86399,
|
|
42
33
|
},
|
|
34
|
+
break_start_time: {
|
|
35
|
+
type: Number,
|
|
36
|
+
default: null,
|
|
37
|
+
min: 0,
|
|
38
|
+
max: 86399,
|
|
39
|
+
},
|
|
40
|
+
break_end_time: {
|
|
41
|
+
type: Number,
|
|
42
|
+
default: null,
|
|
43
|
+
min: 0,
|
|
44
|
+
max: 86399,
|
|
45
|
+
},
|
|
46
|
+
working_days: {
|
|
47
|
+
type: [String],
|
|
48
|
+
enum: constants_1.ALL_DAY_INDEX,
|
|
49
|
+
required: true,
|
|
50
|
+
validate: {
|
|
51
|
+
validator: (days) => Array.isArray(days) && days.length > 0,
|
|
52
|
+
message: 'working_days must contain at least one day',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
43
55
|
grace_period_minutes: {
|
|
44
56
|
type: Number,
|
|
45
57
|
default: null,
|
|
46
58
|
},
|
|
47
|
-
|
|
48
|
-
type:
|
|
49
|
-
default:
|
|
59
|
+
overtime_start_time: {
|
|
60
|
+
type: Number,
|
|
61
|
+
default: null,
|
|
62
|
+
min: 0,
|
|
63
|
+
max: 86399,
|
|
50
64
|
},
|
|
51
65
|
is_active: {
|
|
52
66
|
type: Boolean,
|
|
@@ -13,12 +13,12 @@ export interface ITenantHrAttendanceRecord {
|
|
|
13
13
|
tenant_id: string;
|
|
14
14
|
employee_id: string;
|
|
15
15
|
attendance_date: string;
|
|
16
|
-
|
|
16
|
+
shift_id: string;
|
|
17
17
|
clock_time: ITenantHrClockTime[];
|
|
18
18
|
break_time: ITenantHrBreakTime[];
|
|
19
19
|
total_break_time: number;
|
|
20
20
|
total_worked_time: number;
|
|
21
21
|
status: HR_ATTENDANCE_STATUS_ENUM;
|
|
22
22
|
createdAt: Date;
|
|
23
|
-
updatedAt: Date
|
|
23
|
+
updatedAt: Date;
|
|
24
24
|
}
|
|
@@ -32,11 +32,9 @@ export interface ITenantHrEmployee {
|
|
|
32
32
|
pay_type: HR_PAY_TYPE_ENUM;
|
|
33
33
|
salary_per_hour?: number | null;
|
|
34
34
|
monthly_salary?: number | null;
|
|
35
|
-
hr_working_days_per_month: number;
|
|
36
|
-
hr_hours_per_working_day: number;
|
|
37
35
|
hr_overtime_multiplier: number;
|
|
38
36
|
leave_allowance?: Partial<Record<HR_LEAVE_TYPE_ENUM, number>>;
|
|
39
|
-
docs: Record<HR_DOCUMENT_TYPE_ENUM, ITenantHrEmployeeDocument
|
|
37
|
+
docs: Partial<Record<HR_DOCUMENT_TYPE_ENUM, ITenantHrEmployeeDocument>>;
|
|
40
38
|
notes?: string | null;
|
|
41
39
|
createdAt: Date;
|
|
42
40
|
updatedAt: Date;
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
import { DAY_INDEX_ENUM, HR_SHIFT_STATUS_ENUM, HR_SHIFT_TYPE_ENUM } from '../../constants';
|
|
2
1
|
export interface ITenantHrShiftSchedule {
|
|
3
2
|
_id: string;
|
|
4
3
|
tenant_id: string;
|
|
5
4
|
employee_id: string;
|
|
6
|
-
|
|
5
|
+
shift_id: string;
|
|
7
6
|
start_date: Date;
|
|
8
7
|
end_date?: Date | null;
|
|
9
|
-
start_time: number;
|
|
10
|
-
end_time: number;
|
|
11
|
-
position?: string | null;
|
|
12
|
-
type: HR_SHIFT_TYPE_ENUM;
|
|
13
|
-
status: HR_SHIFT_STATUS_ENUM;
|
|
14
8
|
notes?: string | null;
|
|
15
|
-
shift_id?: string | null;
|
|
16
9
|
createdAt: Date;
|
|
17
|
-
updatedAt: Date
|
|
10
|
+
updatedAt: Date;
|
|
18
11
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
position: string;
|
|
3
|
-
count: number;
|
|
4
|
-
}
|
|
1
|
+
import { DAY_INDEX_ENUM } from '../../constants';
|
|
5
2
|
export interface ITenantHrShift {
|
|
6
3
|
_id: string;
|
|
7
4
|
tenant_id: string;
|
|
8
5
|
name: string;
|
|
9
6
|
start_time: number;
|
|
10
7
|
end_time: number;
|
|
8
|
+
break_start_time?: number | null;
|
|
9
|
+
break_end_time?: number | null;
|
|
10
|
+
working_days: DAY_INDEX_ENUM[];
|
|
11
11
|
grace_period_minutes?: number | null;
|
|
12
|
-
|
|
12
|
+
overtime_start_time?: number | null;
|
|
13
13
|
is_active: boolean;
|
|
14
14
|
createdAt: Date;
|
|
15
|
-
updatedAt: Date
|
|
15
|
+
updatedAt: Date;
|
|
16
16
|
}
|
|
@@ -11,9 +11,17 @@ const shift = (start_time, end_time, day_indexes = constants_1.ALL_DAY_INDEX) =>
|
|
|
11
11
|
end_time,
|
|
12
12
|
});
|
|
13
13
|
const NO_MONDAY = constants_1.ALL_DAY_INDEX.filter((day) => day !== constants_1.DAY_INDEX_ENUM.MON);
|
|
14
|
+
const NO_SATURDAY = constants_1.ALL_DAY_INDEX.filter((day) => day !== constants_1.DAY_INDEX_ENUM.SAT);
|
|
14
15
|
// Production shift sets (Auckland Thai Lemon: Day 9:00-17:00, Night 17:00-27:00:59.999).
|
|
15
16
|
const R1 = [shift(32400000, 61199999), shift(61200000, 97259999)];
|
|
16
17
|
const R1_NO_MONDAY = [shift(32400000, 61199999, NO_MONDAY), shift(61200000, 97259999, NO_MONDAY)];
|
|
18
|
+
// Reported production shape: one 08:00 → 29:59:59.999 shift, Saturday off.
|
|
19
|
+
// 2026-10-31 = Saturday, 2026-11-01 = Sunday.
|
|
20
|
+
const R_SATURDAY_OFF = [shift(8 * HOUR, 29 * HOUR + 59 * MINUTE + 59 * 1000 + 999, NO_SATURDAY)];
|
|
21
|
+
// Only Wednesday is scheduled — a closed Saturday and the next-day Sunday both
|
|
22
|
+
// have no shift anchor.
|
|
23
|
+
const WEDNESDAY_ONLY = [constants_1.DAY_INDEX_ENUM.WED];
|
|
24
|
+
const R_WEDNESDAY_ONLY = [shift(8 * HOUR, 17 * HOUR, WEDNESDAY_ONLY)];
|
|
17
25
|
// 2026-09-13 = Sunday, 2026-09-14 = Monday, 2026-09-15 = Tuesday.
|
|
18
26
|
const at = (y, m, d, hh, mm, ss = 0) => new Date(Date.UTC(y, m - 1, d, hh, mm, ss));
|
|
19
27
|
describe('getShiftEndPosition', () => {
|
|
@@ -67,9 +75,22 @@ describe('canStartNewBusinessDay', () => {
|
|
|
67
75
|
it('blocks while the closed date is still the current date', () => {
|
|
68
76
|
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R1, '2026-09-13', 0, at(2026, 9, 13, 23, 0))).toBe(false);
|
|
69
77
|
});
|
|
70
|
-
it('
|
|
71
|
-
|
|
78
|
+
it('allows after the closed day window ends even when the next weekday is an off-day', () => {
|
|
79
|
+
// Monday has no shifts; Sunday's night window still ends at Mon 03:00:59.999.
|
|
80
|
+
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R1_NO_MONDAY, '2026-09-13', 0, at(2026, 9, 14, 0, 30))).toBe(false);
|
|
81
|
+
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R1_NO_MONDAY, '2026-09-13', 0, at(2026, 9, 14, 3, 0, 59))).toBe(false);
|
|
82
|
+
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R1_NO_MONDAY, '2026-09-13', 0, at(2026, 9, 14, 3, 1))).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
it('anchors an off-day closed day on the next day first shift start', () => {
|
|
85
|
+
// 2026-10-31 is Saturday (no Saturday shift); Sunday 2026-11-01 starts 08:00.
|
|
86
|
+
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R_SATURDAY_OFF, '2026-10-31', 0, at(2026, 10, 31, 23, 0))).toBe(false);
|
|
87
|
+
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R_SATURDAY_OFF, '2026-10-31', 0, at(2026, 11, 1, 7, 59))).toBe(false);
|
|
88
|
+
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R_SATURDAY_OFF, '2026-10-31', 0, at(2026, 11, 1, 8, 0))).toBe(true);
|
|
89
|
+
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R_SATURDAY_OFF, '2026-10-31', 0, at(2026, 11, 1, 16, 28))).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
it('returns null only when neither the closed day nor the next day has a shift anchor', () => {
|
|
72
92
|
expect((0, shift_window_helpers_1.canStartNewBusinessDay)([], '2026-09-13', 0, at(2026, 9, 14, 3, 1))).toBeNull();
|
|
93
|
+
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R_WEDNESDAY_ONLY, '2026-10-31', 0, at(2026, 11, 1, 16, 28))).toBeNull();
|
|
73
94
|
});
|
|
74
95
|
});
|
|
75
96
|
describe('getShiftCoverageIntervals / doShiftWindowsOverlap', () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
const tenant_hr_employees_1 = require("../schemas/models/tenant_hr_employees");
|
|
9
|
+
const EmployeeModel = mongoose_1.default.model('TestHrEmployee', tenant_hr_employees_1.TenantHrEmployeeSchema, 'test_hr_employees');
|
|
10
|
+
const validEmployee = () => ({
|
|
11
|
+
_id: new mongoose_1.default.Types.ObjectId(),
|
|
12
|
+
uid: 'firebase-uid-1',
|
|
13
|
+
tenant_id: 'test-store',
|
|
14
|
+
phone_number: '+923001234567',
|
|
15
|
+
join_date: new Date('2026-03-12T00:00:00.000Z'),
|
|
16
|
+
});
|
|
17
|
+
const validate = (overrides = {}) => new EmployeeModel({ ...validEmployee(), ...overrides }).validate();
|
|
18
|
+
describe('tenant_hr_employees schema', () => {
|
|
19
|
+
describe('identity', () => {
|
|
20
|
+
it('accepts a minimal employee record', async () => {
|
|
21
|
+
await expect(validate()).resolves.toBeUndefined();
|
|
22
|
+
});
|
|
23
|
+
it('requires uid, tenant_id, phone_number and join_date', async () => {
|
|
24
|
+
await expect(validate({ uid: undefined })).rejects.toThrow(/uid/);
|
|
25
|
+
await expect(validate({ tenant_id: undefined })).rejects.toThrow(/tenant_id/);
|
|
26
|
+
await expect(validate({ phone_number: undefined })).rejects.toThrow(/phone_number/);
|
|
27
|
+
await expect(validate({ join_date: undefined })).rejects.toThrow(/join_date/);
|
|
28
|
+
});
|
|
29
|
+
it('defaults to an enabled employee with unverified contact details', () => {
|
|
30
|
+
const employee = new EmployeeModel(validEmployee());
|
|
31
|
+
expect(employee.is_disabled).toBe(false);
|
|
32
|
+
expect(employee.email_verified).toBe(false);
|
|
33
|
+
expect(employee.phone_number_verified).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
describe('HR profile', () => {
|
|
37
|
+
it('allows an unassigned position (employee not placed yet)', async () => {
|
|
38
|
+
await expect(validate({ position_id: null })).resolves.toBeUndefined();
|
|
39
|
+
});
|
|
40
|
+
it('defaults employment status and pay type', () => {
|
|
41
|
+
const employee = new EmployeeModel(validEmployee());
|
|
42
|
+
expect(employee.employment_status).toBe(constants_1.HR_EMPLOYMENT_STATUS_ENUM.ACTIVE);
|
|
43
|
+
expect(employee.pay_type).toBe(constants_1.HR_PAY_TYPE_ENUM.MONTHLY);
|
|
44
|
+
expect(employee.hr_overtime_multiplier).toBe(0);
|
|
45
|
+
});
|
|
46
|
+
it('rejects an employment status outside the enum', async () => {
|
|
47
|
+
await expect(validate({ employment_status: 'FIRED' })).rejects.toThrow(/employment_status/);
|
|
48
|
+
});
|
|
49
|
+
it('rejects a pay type outside the enum', async () => {
|
|
50
|
+
await expect(validate({ pay_type: 'DAILY' })).rejects.toThrow(/pay_type/);
|
|
51
|
+
});
|
|
52
|
+
it('accepts a partial leave allowance map', async () => {
|
|
53
|
+
await expect(validate({
|
|
54
|
+
leave_allowance: {
|
|
55
|
+
[constants_1.HR_LEAVE_TYPE_ENUM.ANNUAL]: 21,
|
|
56
|
+
[constants_1.HR_LEAVE_TYPE_ENUM.SICK]: 10,
|
|
57
|
+
},
|
|
58
|
+
})).resolves.toBeUndefined();
|
|
59
|
+
});
|
|
60
|
+
it('accepts a partial documents map (not every document type is uploaded)', async () => {
|
|
61
|
+
await expect(validate({
|
|
62
|
+
docs: {
|
|
63
|
+
CNIC: {
|
|
64
|
+
doc_url: 'https://storage.example/cnic.pdf',
|
|
65
|
+
doc_name: 'cnic.pdf',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
})).resolves.toBeUndefined();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe('shift assignment lives elsewhere', () => {
|
|
72
|
+
it('does not carry a shift_id column', () => {
|
|
73
|
+
// the assignment is a dated row in tenant_hr_shift_schedules
|
|
74
|
+
expect(tenant_hr_employees_1.TenantHrEmployeeSchema.path('shift_id')).toBeUndefined();
|
|
75
|
+
});
|
|
76
|
+
it('does not carry the payroll-policy fields', () => {
|
|
77
|
+
// working days / hours per day now come from the shift at payroll time
|
|
78
|
+
expect(tenant_hr_employees_1.TenantHrEmployeeSchema.path('hr_working_days_per_month')).toBeUndefined();
|
|
79
|
+
expect(tenant_hr_employees_1.TenantHrEmployeeSchema.path('hr_hours_per_working_day')).toBeUndefined();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
7
|
+
const tenant_hr_shift_schedules_1 = require("../schemas/models/tenant_hr_shift_schedules");
|
|
8
|
+
const ScheduleModel = mongoose_1.default.model('TestHrShiftSchedule', tenant_hr_shift_schedules_1.TenantHrShiftScheduleSchema, 'test_hr_shift_schedules');
|
|
9
|
+
const validSchedule = () => ({
|
|
10
|
+
_id: new mongoose_1.default.Types.ObjectId(),
|
|
11
|
+
tenant_id: 'test-store',
|
|
12
|
+
employee_id: 'employee-1',
|
|
13
|
+
shift_id: 'shift-1',
|
|
14
|
+
start_date: new Date('2026-11-02T00:00:00.000Z'),
|
|
15
|
+
});
|
|
16
|
+
const validate = (overrides = {}) => new ScheduleModel({ ...validSchedule(), ...overrides }).validate();
|
|
17
|
+
describe('tenant_hr_shift_schedules schema (a dated assignment)', () => {
|
|
18
|
+
describe('shape', () => {
|
|
19
|
+
it('accepts employee + shift + start_date', async () => {
|
|
20
|
+
await expect(validate()).resolves.toBeUndefined();
|
|
21
|
+
});
|
|
22
|
+
it('requires employee_id, shift_id and start_date', async () => {
|
|
23
|
+
await expect(validate({ employee_id: undefined })).rejects.toThrow(/employee_id/);
|
|
24
|
+
await expect(validate({ shift_id: undefined })).rejects.toThrow(/shift_id/);
|
|
25
|
+
await expect(validate({ start_date: undefined })).rejects.toThrow(/start_date/);
|
|
26
|
+
});
|
|
27
|
+
it('treats end_date as optional and nullable (open-ended assignment)', async () => {
|
|
28
|
+
await expect(validate({ end_date: null })).resolves.toBeUndefined();
|
|
29
|
+
await expect(validate({ end_date: undefined })).resolves.toBeUndefined();
|
|
30
|
+
await expect(validate({ end_date: new Date('2026-12-31T00:00:00.000Z') })).resolves.toBeUndefined();
|
|
31
|
+
});
|
|
32
|
+
it('accepts notes and defaults them to null', async () => {
|
|
33
|
+
await expect(validate({ notes: 'covering for Ali' })).resolves.toBeUndefined();
|
|
34
|
+
const schedule = new ScheduleModel(validSchedule());
|
|
35
|
+
expect(schedule.notes).toBeNull();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('no shift data on the assignment', () => {
|
|
39
|
+
// These used to be real columns. If any of them comes back, the model has
|
|
40
|
+
// regressed to the pre-thin shape and shift edits would stop propagating.
|
|
41
|
+
const forbidden = [
|
|
42
|
+
'day_indexes',
|
|
43
|
+
'start_time',
|
|
44
|
+
'end_time',
|
|
45
|
+
'position',
|
|
46
|
+
'type',
|
|
47
|
+
'status',
|
|
48
|
+
];
|
|
49
|
+
it.each(forbidden)('does not declare `%s`', (path) => {
|
|
50
|
+
expect(tenant_hr_shift_schedules_1.TenantHrShiftScheduleSchema.path(path)).toBeUndefined();
|
|
51
|
+
});
|
|
52
|
+
it('drops legacy keys instead of persisting them', () => {
|
|
53
|
+
const schedule = new ScheduleModel({
|
|
54
|
+
...validSchedule(),
|
|
55
|
+
day_indexes: ['MON'],
|
|
56
|
+
start_time: 28800,
|
|
57
|
+
end_time: 57600,
|
|
58
|
+
type: 'REGULAR',
|
|
59
|
+
status: 'SCHEDULED',
|
|
60
|
+
position: 'Line Cook',
|
|
61
|
+
});
|
|
62
|
+
const plain = schedule.toObject();
|
|
63
|
+
for (const path of forbidden) {
|
|
64
|
+
expect(plain).not.toHaveProperty(path);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
const tenant_hr_shifts_1 = require("../schemas/models/tenant_hr_shifts");
|
|
9
|
+
const ShiftModel = mongoose_1.default.model('TestHrShift', tenant_hr_shifts_1.TenantHrShiftSchema, 'test_hr_shifts');
|
|
10
|
+
const validShift = () => ({
|
|
11
|
+
_id: new mongoose_1.default.Types.ObjectId(),
|
|
12
|
+
tenant_id: 'test-store',
|
|
13
|
+
name: 'Morning',
|
|
14
|
+
start_time: 28800, // 08:00
|
|
15
|
+
end_time: 57600, // 16:00
|
|
16
|
+
working_days: [constants_1.DAY_INDEX_ENUM.MON, constants_1.DAY_INDEX_ENUM.TUE],
|
|
17
|
+
grace_period_minutes: 10,
|
|
18
|
+
});
|
|
19
|
+
const validate = (overrides = {}) => new ShiftModel({ ...validShift(), ...overrides }).validate();
|
|
20
|
+
describe('tenant_hr_shifts schema', () => {
|
|
21
|
+
describe('shape', () => {
|
|
22
|
+
it('accepts a complete shift', async () => {
|
|
23
|
+
await expect(validate()).resolves.toBeUndefined();
|
|
24
|
+
});
|
|
25
|
+
it('requires a name', async () => {
|
|
26
|
+
await expect(validate({ name: undefined })).rejects.toThrow(/name/);
|
|
27
|
+
});
|
|
28
|
+
it('requires both start_time and end_time', async () => {
|
|
29
|
+
await expect(validate({ start_time: undefined })).rejects.toThrow(/start_time/);
|
|
30
|
+
await expect(validate({ end_time: undefined })).rejects.toThrow(/end_time/);
|
|
31
|
+
});
|
|
32
|
+
it('rejects times outside 0..86399 (the seconds-of-day range)', async () => {
|
|
33
|
+
await expect(validate({ start_time: -1 })).rejects.toThrow(/start_time/);
|
|
34
|
+
await expect(validate({ end_time: 86400 })).rejects.toThrow(/end_time/);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('working days', () => {
|
|
38
|
+
it('requires at least one working day', async () => {
|
|
39
|
+
// an empty list used to mean "every day" in three different places; the
|
|
40
|
+
// schema now forbids it so that meaning lives in exactly one rule
|
|
41
|
+
await expect(validate({ working_days: [] })).rejects.toThrow(/working_days/);
|
|
42
|
+
});
|
|
43
|
+
it('accepts every valid day code', async () => {
|
|
44
|
+
await expect(validate({ working_days: [...constants_1.ALL_DAY_INDEX] })).resolves.toBeUndefined();
|
|
45
|
+
});
|
|
46
|
+
it('rejects a day code outside the enum', async () => {
|
|
47
|
+
await expect(validate({ working_days: ['FUNDAY'] })).rejects.toThrow(/working_days/);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
describe('flags', () => {
|
|
51
|
+
it('defaults to active with no grace period', () => {
|
|
52
|
+
const shift = new ShiftModel({
|
|
53
|
+
...validShift(),
|
|
54
|
+
is_active: undefined,
|
|
55
|
+
grace_period_minutes: undefined,
|
|
56
|
+
});
|
|
57
|
+
expect(shift.is_active).toBe(true);
|
|
58
|
+
expect(shift.grace_period_minutes).toBeNull();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|