@things-factory/work-shift 6.1.182 → 6.1.186
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/dist-server/controllers/index.js +2 -194
- package/dist-server/controllers/index.js.map +1 -1
- package/dist-server/controllers/work-shift-range.js +198 -0
- package/dist-server/controllers/work-shift-range.js.map +1 -0
- package/dist-server/controllers/work-shift-schedule.js +70 -0
- package/dist-server/controllers/work-shift-schedule.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/server/controllers/index.ts +2 -250
- package/server/controllers/work-shift-range.ts +250 -0
- package/server/controllers/work-shift-schedule.ts +79 -0
|
@@ -1,198 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLatestWorkDateAndShift = exports.getWorkDateAndShift = exports.getDateRangeForWorkDate = exports.getDateRangeForWorkShift = void 0;
|
|
4
3
|
const tslib_1 = require("tslib");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const shell_1 = require("@things-factory/shell");
|
|
8
|
-
const work_shift_1 = require("../service/work-shift/work-shift");
|
|
9
|
-
async function getDateRangeForWorkShift(domain, workDate, workShiftName, options) {
|
|
10
|
-
const dateOptions = Object.assign({ timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD' }, options);
|
|
11
|
-
const { timezone, format } = dateOptions;
|
|
12
|
-
const workShift = await (0, shell_1.getRepository)(work_shift_1.WorkShift).findOne({
|
|
13
|
-
where: {
|
|
14
|
-
domain: { id: domain.id },
|
|
15
|
-
name: workShiftName
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
if (!workShift) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const theDay = moment_timezone_1.default.tz(workDate, timezone);
|
|
22
|
-
const { name, fromDate, fromTime, toDate, toTime } = workShift;
|
|
23
|
-
const convertedFromDate = theDay.clone().add(fromDate, 'day');
|
|
24
|
-
const convertedToDate = theDay.clone().add(toDate, 'day');
|
|
25
|
-
const from = moment_timezone_1.default
|
|
26
|
-
.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)
|
|
27
|
-
.toDate();
|
|
28
|
-
const to = moment_timezone_1.default.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone).toDate();
|
|
29
|
-
return [from, to];
|
|
30
|
-
}
|
|
31
|
-
exports.getDateRangeForWorkShift = getDateRangeForWorkShift;
|
|
32
|
-
async function getDateRangeForWorkDate(domain, workDate, options) {
|
|
33
|
-
const dateOptions = Object.assign({ timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD' }, options);
|
|
34
|
-
const { timezone, format } = dateOptions;
|
|
35
|
-
var beginDate;
|
|
36
|
-
var endDate;
|
|
37
|
-
/* 1. get work-shift list for the domain */
|
|
38
|
-
const workShifts = await (0, shell_1.getRepository)(work_shift_1.WorkShift).find({
|
|
39
|
-
where: {
|
|
40
|
-
domain: { id: domain.id }
|
|
41
|
-
},
|
|
42
|
-
order: {
|
|
43
|
-
fromDate: 'ASC',
|
|
44
|
-
fromTime: 'ASC'
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
/* 2. get date-time for every work-shift */
|
|
48
|
-
if (workShifts && workShifts.length > 0) {
|
|
49
|
-
const theDay = moment_timezone_1.default.tz(workDate, timezone);
|
|
50
|
-
for (let j = 0; j < workShifts.length; j++) {
|
|
51
|
-
const { name, fromDate, fromTime, toDate, toTime } = workShifts[j];
|
|
52
|
-
const convertedFromDate = theDay.clone().add(fromDate, 'day');
|
|
53
|
-
const convertedToDate = theDay.clone().add(toDate, 'day');
|
|
54
|
-
const from = moment_timezone_1.default
|
|
55
|
-
.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)
|
|
56
|
-
.toDate();
|
|
57
|
-
const to = moment_timezone_1.default
|
|
58
|
-
.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)
|
|
59
|
-
.toDate();
|
|
60
|
-
if (!beginDate) {
|
|
61
|
-
beginDate = from;
|
|
62
|
-
}
|
|
63
|
-
endDate = to;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
/* 3. in case there are no work-shift, just give date and default shift '' */
|
|
70
|
-
return [beginDate, endDate];
|
|
71
|
-
}
|
|
72
|
-
exports.getDateRangeForWorkDate = getDateRangeForWorkDate;
|
|
73
|
-
async function getWorkDateAndShift(domain, dateTime, options) {
|
|
74
|
-
const dateOptions = Object.assign({ timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD' }, options);
|
|
75
|
-
const { timezone, format } = dateOptions;
|
|
76
|
-
const givenDate = (0, moment_timezone_1.default)(dateTime).tz(timezone);
|
|
77
|
-
/* 1. get work-shift list for the domain */
|
|
78
|
-
const workShifts = await (0, shell_1.getRepository)(work_shift_1.WorkShift).find({
|
|
79
|
-
where: {
|
|
80
|
-
domain: { id: domain.id }
|
|
81
|
-
},
|
|
82
|
-
order: {
|
|
83
|
-
fromDate: 'ASC',
|
|
84
|
-
fromTime: 'ASC'
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
/* 2. compare given date-time to every work-shift */
|
|
88
|
-
const theDay = givenDate.clone().startOf('day');
|
|
89
|
-
const theDayBefore = theDay.clone().subtract(1, 'day');
|
|
90
|
-
const theDayAfter = theDay.clone().add(1, 'day');
|
|
91
|
-
if (workShifts && workShifts.length > 0) {
|
|
92
|
-
const days = [theDayBefore, theDay, theDayAfter];
|
|
93
|
-
let dateBegin, dateEnd;
|
|
94
|
-
for (let i = 0; i < days.length; i++) {
|
|
95
|
-
const day = days[i];
|
|
96
|
-
dateBegin = null;
|
|
97
|
-
for (let j = 0; j < workShifts.length; j++) {
|
|
98
|
-
const { name, fromDate, fromTime, toDate, toTime } = workShifts[j];
|
|
99
|
-
const convertedFromDate = day.clone().add(fromDate, 'day');
|
|
100
|
-
const convertedToDate = day.clone().add(toDate, 'day');
|
|
101
|
-
const from = moment_timezone_1.default.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone);
|
|
102
|
-
const to = moment_timezone_1.default.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone);
|
|
103
|
-
dateBegin = dateBegin || from;
|
|
104
|
-
dateEnd = from.clone().add(1, 'day');
|
|
105
|
-
if (dateTime >= from.toDate() && to.toDate() > dateTime) {
|
|
106
|
-
return {
|
|
107
|
-
workDate: (0, moment_timezone_1.default)(day).format(format),
|
|
108
|
-
workShift: name,
|
|
109
|
-
dateRange: [dateBegin.toDate(), dateEnd.toDate()],
|
|
110
|
-
shiftRange: [from.toDate(), to.toDate()]
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
env_1.logger.error(new Error('shift not found'));
|
|
116
|
-
}
|
|
117
|
-
/* 3. in case there are no work-shift, just give date and default shift '' */
|
|
118
|
-
return {
|
|
119
|
-
workDate: givenDate.format(format),
|
|
120
|
-
workShift: '',
|
|
121
|
-
dateRange: [theDay.toDate(), theDayAfter.toDate()]
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
exports.getWorkDateAndShift = getWorkDateAndShift;
|
|
125
|
-
async function getLatestWorkDateAndShift(domain, dateTime, options) {
|
|
126
|
-
const dateOptions = Object.assign({ timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD' }, options);
|
|
127
|
-
const { timezone, format } = dateOptions;
|
|
128
|
-
const givenDate = (0, moment_timezone_1.default)(dateTime).tz(timezone);
|
|
129
|
-
/* 1. get work-shift list for the domain */
|
|
130
|
-
const workShifts = await (0, shell_1.getRepository)(work_shift_1.WorkShift).find({
|
|
131
|
-
where: {
|
|
132
|
-
domain: { id: domain.id }
|
|
133
|
-
},
|
|
134
|
-
order: {
|
|
135
|
-
fromDate: 'ASC',
|
|
136
|
-
fromTime: 'ASC'
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
/* 2. compare given date-time to every work-shift */
|
|
140
|
-
const theDay = givenDate.clone().startOf('day');
|
|
141
|
-
const theDayBefore = theDay.clone().subtract(1, 'day');
|
|
142
|
-
const theDayAfter = theDay.clone().add(1, 'day');
|
|
143
|
-
if (workShifts && workShifts.length > 0) {
|
|
144
|
-
const days = [theDayBefore, theDay, theDayAfter];
|
|
145
|
-
let dateBegin, dateEnd;
|
|
146
|
-
for (let i = 0; i < days.length; i++) {
|
|
147
|
-
const day = days[i];
|
|
148
|
-
dateBegin = null;
|
|
149
|
-
for (let j = 0; j < workShifts.length; j++) {
|
|
150
|
-
const { name, fromDate, fromTime, toDate, toTime } = workShifts[j];
|
|
151
|
-
const convertedFromDate = day.clone().add(fromDate, 'day');
|
|
152
|
-
const convertedToDate = day.clone().add(toDate, 'day');
|
|
153
|
-
const from = moment_timezone_1.default.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone);
|
|
154
|
-
const to = moment_timezone_1.default.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone);
|
|
155
|
-
dateBegin = dateBegin || from;
|
|
156
|
-
dateEnd = from.clone().add(1, 'day');
|
|
157
|
-
if (dateTime < from.toDate()) {
|
|
158
|
-
if (j > 0) {
|
|
159
|
-
const { name, fromDate, fromTime, toDate, toTime } = workShifts[j - 1];
|
|
160
|
-
const from = moment_timezone_1.default.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone);
|
|
161
|
-
const to = moment_timezone_1.default.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone);
|
|
162
|
-
return {
|
|
163
|
-
workDate: (0, moment_timezone_1.default)(day).format(format),
|
|
164
|
-
workShift: name,
|
|
165
|
-
dateRange: [dateBegin.toDate(), dateEnd.toDate()],
|
|
166
|
-
shiftRange: [from.toDate(), to.toDate()]
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
else if (i > 0) {
|
|
170
|
-
const { name, fromDate, fromTime, toDate, toTime } = workShifts[0];
|
|
171
|
-
const convertedFromDate = days[i - 1].clone().add(fromDate, 'day');
|
|
172
|
-
const convertedToDate = days[i - 1].clone().add(toDate, 'day');
|
|
173
|
-
const from = moment_timezone_1.default.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone);
|
|
174
|
-
const to = moment_timezone_1.default.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone);
|
|
175
|
-
return {
|
|
176
|
-
workDate: (0, moment_timezone_1.default)(day).format(format),
|
|
177
|
-
workShift: name,
|
|
178
|
-
dateRange: [dateBegin.clone().subtract(1, 'day').toDate(), dateBegin.toDate()],
|
|
179
|
-
shiftRange: [from.toDate(), to.toDate()]
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
env_1.logger.error(new Error('shift not found'));
|
|
189
|
-
}
|
|
190
|
-
/* 3. in case there are no work-shift, just give date and default shift '' */
|
|
191
|
-
return {
|
|
192
|
-
workDate: givenDate.clone().subtract(1, 'day').format(format),
|
|
193
|
-
workShift: '',
|
|
194
|
-
dateRange: [theDayBefore.toDate(), theDay.toDate()]
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
exports.getLatestWorkDateAndShift = getLatestWorkDateAndShift;
|
|
4
|
+
tslib_1.__exportStar(require("./work-shift-range"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./work-shift-schedule"), exports);
|
|
198
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/controllers/index.ts"],"names":[],"mappings":";;;;AAAA,8EAAoC;AAEpC,6CAA4C;AAC5C,iDAA6D;AAE7D,iEAA+E;AAGxE,KAAK,UAAU,wBAAwB,CAC5C,MAAc,EACd,QAAgB,EAChB,aAAqB,EACrB,OAA+C;IAE/C,MAAM,WAAW,mBAAK,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,KAAK,EAAE,MAAM,EAAE,YAAY,IAAK,OAAO,CAAE,CAAA;IAC5F,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,WAAW,CAAA;IAExC,MAAM,SAAS,GAAG,MAAM,IAAA,qBAAa,EAAC,sBAAS,CAAC,CAAC,OAAO,CAAC;QACvD,KAAK,EAAE;YACL,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;YACzB,IAAI,EAAE,aAAa;SACpB;KACF,CAAC,CAAA;IAEF,IAAI,CAAC,SAAS,EAAE;QACd,OAAM;KACP;IACD,MAAM,MAAM,GAAG,yBAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;IAC5C,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;IAE9D,MAAM,iBAAiB,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;IAC7D,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IACzD,MAAM,IAAI,GAAG,yBAAM;SAChB,EAAE,CAAC,GAAG,iBAAiB,CAAC,MAAM,CAAC,Y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pC,SAAS,EAAE,IAAI;4BACf,SAAS,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,SAAS,CAAC,MAAM,EAAE,CAAC;4BAC9E,UAAU,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC;yBACzC,CAAA;qBACF;yBAAM;wBACL,OAAM;qBACP;iBACF;aACF;SACF;QAED,YAAM,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAA;KAC3C;IAED,6EAA6E;IAC7E,OAAO;QACL,QAAQ,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;QAC7D,SAAS,EAAE,EAAE;QACb,SAAS,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;KACpD,CAAA;AACH,CAAC;AA9FD,8DA8FC","sourcesContent":["import moment from 'moment-timezone'\n\nimport { logger } from '@things-factory/env'\nimport { Domain, getRepository } from '@things-factory/shell'\n\nimport { WorkShift, WorkShiftDateType } from '../service/work-shift/work-shift'\nimport { WorkShiftInfo } from '../service/work-shift/work-shift-type'\n\nexport async function getDateRangeForWorkShift(\n domain: Domain,\n workDate: string,\n workShiftName: string,\n options: { timezone?: string; format?: string }\n): Promise<Date[]> {\n const dateOptions = { timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD', ...options }\n const { timezone, format } = dateOptions\n\n const workShift = await getRepository(WorkShift).findOne({\n where: {\n domain: { id: domain.id },\n name: workShiftName\n }\n })\n\n if (!workShift) {\n return\n }\n const theDay = moment.tz(workDate, timezone)\n const { name, fromDate, fromTime, toDate, toTime } = workShift\n\n const convertedFromDate = theDay.clone().add(fromDate, 'day')\n const convertedToDate = theDay.clone().add(toDate, 'day')\n const from = moment\n .tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n .toDate()\n const to = moment.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone).toDate()\n\n return [from, to]\n}\n\nexport async function getDateRangeForWorkDate(\n domain: Domain,\n workDate: string,\n options: { timezone?: string; format?: string }\n) {\n const dateOptions = { timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD', ...options }\n const { timezone, format } = dateOptions\n\n var beginDate\n var endDate\n\n /* 1. get work-shift list for the domain */\n const workShifts = await getRepository(WorkShift).find({\n where: {\n domain: { id: domain.id }\n },\n order: {\n fromDate: 'ASC',\n fromTime: 'ASC'\n }\n })\n\n /* 2. get date-time for every work-shift */\n if (workShifts && workShifts.length > 0) {\n const theDay = moment.tz(workDate, timezone)\n\n for (let j = 0; j < workShifts.length; j++) {\n const { name, fromDate, fromTime, toDate, toTime } = workShifts[j]\n\n const convertedFromDate = theDay.clone().add(fromDate, 'day')\n const convertedToDate = theDay.clone().add(toDate, 'day')\n const from = moment\n .tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n .toDate()\n const to = moment\n .tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n .toDate()\n\n if (!beginDate) {\n beginDate = from\n }\n\n endDate = to\n }\n } else {\n return\n }\n\n /* 3. in case there are no work-shift, just give date and default shift '' */\n return [beginDate, endDate]\n}\n\nexport async function getWorkDateAndShift(domain: Domain, dateTime: Date, options?: any): Promise<WorkShiftInfo> {\n const dateOptions = { timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD', ...options }\n const { timezone, format } = dateOptions\n\n const givenDate = moment(dateTime).tz(timezone)\n /* 1. get work-shift list for the domain */\n const workShifts = await getRepository(WorkShift).find({\n where: {\n domain: { id: domain.id }\n },\n order: {\n fromDate: 'ASC',\n fromTime: 'ASC'\n }\n })\n\n /* 2. compare given date-time to every work-shift */\n const theDay = givenDate.clone().startOf('day')\n const theDayBefore = theDay.clone().subtract(1, 'day')\n const theDayAfter = theDay.clone().add(1, 'day')\n\n if (workShifts && workShifts.length > 0) {\n const days = [theDayBefore, theDay, theDayAfter]\n let dateBegin, dateEnd\n\n for (let i = 0; i < days.length; i++) {\n const day = days[i]\n dateBegin = null\n\n for (let j = 0; j < workShifts.length; j++) {\n const { name, fromDate, fromTime, toDate, toTime } = workShifts[j]\n\n const convertedFromDate = day.clone().add(fromDate, 'day')\n const convertedToDate = day.clone().add(toDate, 'day')\n\n const from = moment.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n const to = moment.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n\n dateBegin = dateBegin || from\n dateEnd = from.clone().add(1, 'day')\n\n if (dateTime >= from.toDate() && to.toDate() > dateTime) {\n return {\n workDate: moment(day).format(format),\n workShift: name,\n dateRange: [dateBegin.toDate(), dateEnd.toDate()],\n shiftRange: [from.toDate(), to.toDate()]\n }\n }\n }\n }\n\n logger.error(new Error('shift not found'))\n }\n\n /* 3. in case there are no work-shift, just give date and default shift '' */\n return {\n workDate: givenDate.format(format),\n workShift: '',\n dateRange: [theDay.toDate(), theDayAfter.toDate()]\n }\n}\n\nexport async function getLatestWorkDateAndShift(domain: Domain, dateTime: Date, options?: any): Promise<WorkShiftInfo> {\n const dateOptions = { timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD', ...options }\n const { timezone, format } = dateOptions\n\n const givenDate = moment(dateTime).tz(timezone)\n\n /* 1. get work-shift list for the domain */\n const workShifts = await getRepository(WorkShift).find({\n where: {\n domain: { id: domain.id }\n },\n order: {\n fromDate: 'ASC',\n fromTime: 'ASC'\n }\n })\n\n /* 2. compare given date-time to every work-shift */\n const theDay = givenDate.clone().startOf('day')\n const theDayBefore = theDay.clone().subtract(1, 'day')\n const theDayAfter = theDay.clone().add(1, 'day')\n\n if (workShifts && workShifts.length > 0) {\n const days = [theDayBefore, theDay, theDayAfter]\n let dateBegin, dateEnd\n\n for (let i = 0; i < days.length; i++) {\n const day = days[i]\n dateBegin = null\n\n for (let j = 0; j < workShifts.length; j++) {\n const { name, fromDate, fromTime, toDate, toTime } = workShifts[j]\n\n const convertedFromDate = day.clone().add(fromDate, 'day')\n const convertedToDate = day.clone().add(toDate, 'day')\n\n const from = moment.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n const to = moment.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n\n dateBegin = dateBegin || from\n dateEnd = from.clone().add(1, 'day')\n\n if (dateTime < from.toDate()) {\n if (j > 0) {\n const { name, fromDate, fromTime, toDate, toTime } = workShifts[j - 1]\n\n const from = moment.tz(\n `${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`,\n 'YYYY-MM-DD HH:mm:ss',\n timezone\n )\n const to = moment.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n\n return {\n workDate: moment(day).format(format),\n workShift: name,\n dateRange: [dateBegin.toDate(), dateEnd.toDate()],\n shiftRange: [from.toDate(), to.toDate()]\n }\n } else if (i > 0) {\n const { name, fromDate, fromTime, toDate, toTime } = workShifts[0]\n\n const convertedFromDate = days[i - 1].clone().add(fromDate, 'day')\n const convertedToDate = days[i - 1].clone().add(toDate, 'day')\n\n const from = moment.tz(\n `${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`,\n 'YYYY-MM-DD HH:mm:ss',\n timezone\n )\n const to = moment.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n\n return {\n workDate: moment(day).format(format),\n workShift: name,\n dateRange: [dateBegin.clone().subtract(1, 'day').toDate(), dateBegin.toDate()],\n shiftRange: [from.toDate(), to.toDate()]\n }\n } else {\n return\n }\n }\n }\n }\n\n logger.error(new Error('shift not found'))\n }\n\n /* 3. in case there are no work-shift, just give date and default shift '' */\n return {\n workDate: givenDate.clone().subtract(1, 'day').format(format),\n workShift: '',\n dateRange: [theDayBefore.toDate(), theDay.toDate()]\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/controllers/index.ts"],"names":[],"mappings":";;;AAAA,6DAAkC;AAClC,gEAAqC","sourcesContent":["export * from './work-shift-range'\nexport * from './work-shift-schedule'\n"]}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLatestWorkDateAndShift = exports.getWorkDateAndShift = exports.getDateRangeForWorkDate = exports.getDateRangeForWorkShift = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const moment_timezone_1 = tslib_1.__importDefault(require("moment-timezone"));
|
|
6
|
+
const env_1 = require("@things-factory/env");
|
|
7
|
+
const shell_1 = require("@things-factory/shell");
|
|
8
|
+
const work_shift_1 = require("../service/work-shift/work-shift");
|
|
9
|
+
async function getDateRangeForWorkShift(domain, workDate, workShiftName, options) {
|
|
10
|
+
const dateOptions = Object.assign({ timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD' }, options);
|
|
11
|
+
const { timezone, format } = dateOptions;
|
|
12
|
+
const workShift = await (0, shell_1.getRepository)(work_shift_1.WorkShift).findOne({
|
|
13
|
+
where: {
|
|
14
|
+
domain: { id: domain.id },
|
|
15
|
+
name: workShiftName
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
if (!workShift) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const theDay = moment_timezone_1.default.tz(workDate, timezone);
|
|
22
|
+
const { name, fromDate, fromTime, toDate, toTime } = workShift;
|
|
23
|
+
const convertedFromDate = theDay.clone().add(fromDate, 'day');
|
|
24
|
+
const convertedToDate = theDay.clone().add(toDate, 'day');
|
|
25
|
+
const from = moment_timezone_1.default
|
|
26
|
+
.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)
|
|
27
|
+
.toDate();
|
|
28
|
+
const to = moment_timezone_1.default.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone).toDate();
|
|
29
|
+
return [from, to];
|
|
30
|
+
}
|
|
31
|
+
exports.getDateRangeForWorkShift = getDateRangeForWorkShift;
|
|
32
|
+
async function getDateRangeForWorkDate(domain, workDate, options) {
|
|
33
|
+
const dateOptions = Object.assign({ timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD' }, options);
|
|
34
|
+
const { timezone, format } = dateOptions;
|
|
35
|
+
var beginDate;
|
|
36
|
+
var endDate;
|
|
37
|
+
/* 1. get work-shift list for the domain */
|
|
38
|
+
const workShifts = await (0, shell_1.getRepository)(work_shift_1.WorkShift).find({
|
|
39
|
+
where: {
|
|
40
|
+
domain: { id: domain.id }
|
|
41
|
+
},
|
|
42
|
+
order: {
|
|
43
|
+
fromDate: 'ASC',
|
|
44
|
+
fromTime: 'ASC'
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
/* 2. get date-time for every work-shift */
|
|
48
|
+
if (workShifts && workShifts.length > 0) {
|
|
49
|
+
const theDay = moment_timezone_1.default.tz(workDate, timezone);
|
|
50
|
+
for (let j = 0; j < workShifts.length; j++) {
|
|
51
|
+
const { name, fromDate, fromTime, toDate, toTime } = workShifts[j];
|
|
52
|
+
const convertedFromDate = theDay.clone().add(fromDate, 'day');
|
|
53
|
+
const convertedToDate = theDay.clone().add(toDate, 'day');
|
|
54
|
+
const from = moment_timezone_1.default
|
|
55
|
+
.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)
|
|
56
|
+
.toDate();
|
|
57
|
+
const to = moment_timezone_1.default
|
|
58
|
+
.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)
|
|
59
|
+
.toDate();
|
|
60
|
+
if (!beginDate) {
|
|
61
|
+
beginDate = from;
|
|
62
|
+
}
|
|
63
|
+
endDate = to;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
/* 3. in case there are no work-shift, just give date and default shift '' */
|
|
70
|
+
return [beginDate, endDate];
|
|
71
|
+
}
|
|
72
|
+
exports.getDateRangeForWorkDate = getDateRangeForWorkDate;
|
|
73
|
+
async function getWorkDateAndShift(domain, dateTime, options) {
|
|
74
|
+
const dateOptions = Object.assign({ timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD' }, options);
|
|
75
|
+
const { timezone, format } = dateOptions;
|
|
76
|
+
const givenDate = (0, moment_timezone_1.default)(dateTime).tz(timezone);
|
|
77
|
+
/* 1. get work-shift list for the domain */
|
|
78
|
+
const workShifts = await (0, shell_1.getRepository)(work_shift_1.WorkShift).find({
|
|
79
|
+
where: {
|
|
80
|
+
domain: { id: domain.id }
|
|
81
|
+
},
|
|
82
|
+
order: {
|
|
83
|
+
fromDate: 'ASC',
|
|
84
|
+
fromTime: 'ASC'
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
/* 2. compare given date-time to every work-shift */
|
|
88
|
+
const theDay = givenDate.clone().startOf('day');
|
|
89
|
+
const theDayBefore = theDay.clone().subtract(1, 'day');
|
|
90
|
+
const theDayAfter = theDay.clone().add(1, 'day');
|
|
91
|
+
if (workShifts && workShifts.length > 0) {
|
|
92
|
+
const days = [theDayBefore, theDay, theDayAfter];
|
|
93
|
+
let dateBegin, dateEnd;
|
|
94
|
+
for (let i = 0; i < days.length; i++) {
|
|
95
|
+
const day = days[i];
|
|
96
|
+
dateBegin = null;
|
|
97
|
+
for (let j = 0; j < workShifts.length; j++) {
|
|
98
|
+
const { name, fromDate, fromTime, toDate, toTime } = workShifts[j];
|
|
99
|
+
const convertedFromDate = day.clone().add(fromDate, 'day');
|
|
100
|
+
const convertedToDate = day.clone().add(toDate, 'day');
|
|
101
|
+
const from = moment_timezone_1.default.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone);
|
|
102
|
+
const to = moment_timezone_1.default.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone);
|
|
103
|
+
dateBegin = dateBegin || from;
|
|
104
|
+
dateEnd = from.clone().add(1, 'day');
|
|
105
|
+
if (dateTime >= from.toDate() && to.toDate() > dateTime) {
|
|
106
|
+
return {
|
|
107
|
+
workDate: (0, moment_timezone_1.default)(day).format(format),
|
|
108
|
+
workShift: name,
|
|
109
|
+
dateRange: [dateBegin.toDate(), dateEnd.toDate()],
|
|
110
|
+
shiftRange: [from.toDate(), to.toDate()]
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
env_1.logger.error(new Error('shift not found'));
|
|
116
|
+
}
|
|
117
|
+
/* 3. in case there are no work-shift, just give date and default shift '' */
|
|
118
|
+
return {
|
|
119
|
+
workDate: givenDate.format(format),
|
|
120
|
+
workShift: '',
|
|
121
|
+
dateRange: [theDay.toDate(), theDayAfter.toDate()]
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
exports.getWorkDateAndShift = getWorkDateAndShift;
|
|
125
|
+
async function getLatestWorkDateAndShift(domain, dateTime, options) {
|
|
126
|
+
const dateOptions = Object.assign({ timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD' }, options);
|
|
127
|
+
const { timezone, format } = dateOptions;
|
|
128
|
+
const givenDate = (0, moment_timezone_1.default)(dateTime).tz(timezone);
|
|
129
|
+
/* 1. get work-shift list for the domain */
|
|
130
|
+
const workShifts = await (0, shell_1.getRepository)(work_shift_1.WorkShift).find({
|
|
131
|
+
where: {
|
|
132
|
+
domain: { id: domain.id }
|
|
133
|
+
},
|
|
134
|
+
order: {
|
|
135
|
+
fromDate: 'ASC',
|
|
136
|
+
fromTime: 'ASC'
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
/* 2. compare given date-time to every work-shift */
|
|
140
|
+
const theDay = givenDate.clone().startOf('day');
|
|
141
|
+
const theDayBefore = theDay.clone().subtract(1, 'day');
|
|
142
|
+
const theDayAfter = theDay.clone().add(1, 'day');
|
|
143
|
+
if (workShifts && workShifts.length > 0) {
|
|
144
|
+
const days = [theDayBefore, theDay, theDayAfter];
|
|
145
|
+
let dateBegin, dateEnd;
|
|
146
|
+
for (let i = 0; i < days.length; i++) {
|
|
147
|
+
const day = days[i];
|
|
148
|
+
dateBegin = null;
|
|
149
|
+
for (let j = 0; j < workShifts.length; j++) {
|
|
150
|
+
const { name, fromDate, fromTime, toDate, toTime } = workShifts[j];
|
|
151
|
+
const convertedFromDate = day.clone().add(fromDate, 'day');
|
|
152
|
+
const convertedToDate = day.clone().add(toDate, 'day');
|
|
153
|
+
const from = moment_timezone_1.default.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone);
|
|
154
|
+
const to = moment_timezone_1.default.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone);
|
|
155
|
+
dateBegin = dateBegin || from;
|
|
156
|
+
dateEnd = from.clone().add(1, 'day');
|
|
157
|
+
if (dateTime < from.toDate()) {
|
|
158
|
+
if (j > 0) {
|
|
159
|
+
const { name, fromDate, fromTime, toDate, toTime } = workShifts[j - 1];
|
|
160
|
+
const from = moment_timezone_1.default.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone);
|
|
161
|
+
const to = moment_timezone_1.default.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone);
|
|
162
|
+
return {
|
|
163
|
+
workDate: (0, moment_timezone_1.default)(day).format(format),
|
|
164
|
+
workShift: name,
|
|
165
|
+
dateRange: [dateBegin.toDate(), dateEnd.toDate()],
|
|
166
|
+
shiftRange: [from.toDate(), to.toDate()]
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
else if (i > 0) {
|
|
170
|
+
const { name, fromDate, fromTime, toDate, toTime } = workShifts[0];
|
|
171
|
+
const convertedFromDate = days[i - 1].clone().add(fromDate, 'day');
|
|
172
|
+
const convertedToDate = days[i - 1].clone().add(toDate, 'day');
|
|
173
|
+
const from = moment_timezone_1.default.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone);
|
|
174
|
+
const to = moment_timezone_1.default.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone);
|
|
175
|
+
return {
|
|
176
|
+
workDate: (0, moment_timezone_1.default)(day).format(format),
|
|
177
|
+
workShift: name,
|
|
178
|
+
dateRange: [dateBegin.clone().subtract(1, 'day').toDate(), dateBegin.toDate()],
|
|
179
|
+
shiftRange: [from.toDate(), to.toDate()]
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
env_1.logger.error(new Error('shift not found'));
|
|
189
|
+
}
|
|
190
|
+
/* 3. in case there are no work-shift, just give date and default shift '' */
|
|
191
|
+
return {
|
|
192
|
+
workDate: givenDate.clone().subtract(1, 'day').format(format),
|
|
193
|
+
workShift: '',
|
|
194
|
+
dateRange: [theDayBefore.toDate(), theDay.toDate()]
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
exports.getLatestWorkDateAndShift = getLatestWorkDateAndShift;
|
|
198
|
+
//# sourceMappingURL=work-shift-range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"work-shift-range.js","sourceRoot":"","sources":["../../server/controllers/work-shift-range.ts"],"names":[],"mappings":";;;;AAAA,8EAAoC;AAEpC,6CAA4C;AAC5C,iDAA6D;AAE7D,iEAA4D;AAGrD,KAAK,UAAU,wBAAwB,CAC5C,MAAc,EACd,QAAgB,EAChB,aAAqB,EACrB,OAA+C;IAE/C,MAAM,WAAW,mBAAK,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,KAAK,EAAE,MAAM,EAAE,YAAY,IAAK,OAAO,CAAE,CAAA;IAC5F,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,WAAW,CAAA;IAExC,MAAM,SAAS,GAAG,MAAM,IAAA,qBAAa,EAAC,sBAAS,CAAC,CAAC,OAAO,CAAC;QACvD,KAAK,EAAE;YACL,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;YACzB,IAAI,EAAE,aAAa;SACpB;KACF,CAAC,CAAA;IAEF,IAAI,CAAC,SAAS,EAAE;QACd,OAAM;KACP;IACD,MAAM,MAAM,GAAG,yBAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;IAC5C,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;IAE9D,MAAM,iBAAiB,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;IAC7D,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IACzD,MAAM,IAAI,GAAG,yBAAM;SAChB,EAAE,CAAC,GAAG,iBAAiB,CAAC,MAAM,CAAC,YAA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,SAAS,EAAE,IAAI;4BACf,SAAS,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,SAAS,CAAC,MAAM,EAAE,CAAC;4BAC9E,UAAU,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC;yBACzC,CAAA;qBACF;yBAAM;wBACL,OAAM;qBACP;iBACF;aACF;SACF;QAED,YAAM,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAA;KAC3C;IAED,6EAA6E;IAC7E,OAAO;QACL,QAAQ,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;QAC7D,SAAS,EAAE,EAAE;QACb,SAAS,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;KACpD,CAAA;AACH,CAAC;AA9FD,8DA8FC","sourcesContent":["import moment from 'moment-timezone'\n\nimport { logger } from '@things-factory/env'\nimport { Domain, getRepository } from '@things-factory/shell'\n\nimport { WorkShift } from '../service/work-shift/work-shift'\nimport { WorkShiftInfo } from '../service/work-shift/work-shift-type'\n\nexport async function getDateRangeForWorkShift(\n domain: Domain,\n workDate: string,\n workShiftName: string,\n options: { timezone?: string; format?: string }\n): Promise<Date[]> {\n const dateOptions = { timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD', ...options }\n const { timezone, format } = dateOptions\n\n const workShift = await getRepository(WorkShift).findOne({\n where: {\n domain: { id: domain.id },\n name: workShiftName\n }\n })\n\n if (!workShift) {\n return\n }\n const theDay = moment.tz(workDate, timezone)\n const { name, fromDate, fromTime, toDate, toTime } = workShift\n\n const convertedFromDate = theDay.clone().add(fromDate, 'day')\n const convertedToDate = theDay.clone().add(toDate, 'day')\n const from = moment\n .tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n .toDate()\n const to = moment.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone).toDate()\n\n return [from, to]\n}\n\nexport async function getDateRangeForWorkDate(\n domain: Domain,\n workDate: string,\n options: { timezone?: string; format?: string }\n) {\n const dateOptions = { timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD', ...options }\n const { timezone, format } = dateOptions\n\n var beginDate\n var endDate\n\n /* 1. get work-shift list for the domain */\n const workShifts = await getRepository(WorkShift).find({\n where: {\n domain: { id: domain.id }\n },\n order: {\n fromDate: 'ASC',\n fromTime: 'ASC'\n }\n })\n\n /* 2. get date-time for every work-shift */\n if (workShifts && workShifts.length > 0) {\n const theDay = moment.tz(workDate, timezone)\n\n for (let j = 0; j < workShifts.length; j++) {\n const { name, fromDate, fromTime, toDate, toTime } = workShifts[j]\n\n const convertedFromDate = theDay.clone().add(fromDate, 'day')\n const convertedToDate = theDay.clone().add(toDate, 'day')\n const from = moment\n .tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n .toDate()\n const to = moment\n .tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n .toDate()\n\n if (!beginDate) {\n beginDate = from\n }\n\n endDate = to\n }\n } else {\n return\n }\n\n /* 3. in case there are no work-shift, just give date and default shift '' */\n return [beginDate, endDate]\n}\n\nexport async function getWorkDateAndShift(domain: Domain, dateTime: Date, options?: any): Promise<WorkShiftInfo> {\n const dateOptions = { timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD', ...options }\n const { timezone, format } = dateOptions\n\n const givenDate = moment(dateTime).tz(timezone)\n /* 1. get work-shift list for the domain */\n const workShifts = await getRepository(WorkShift).find({\n where: {\n domain: { id: domain.id }\n },\n order: {\n fromDate: 'ASC',\n fromTime: 'ASC'\n }\n })\n\n /* 2. compare given date-time to every work-shift */\n const theDay = givenDate.clone().startOf('day')\n const theDayBefore = theDay.clone().subtract(1, 'day')\n const theDayAfter = theDay.clone().add(1, 'day')\n\n if (workShifts && workShifts.length > 0) {\n const days = [theDayBefore, theDay, theDayAfter]\n let dateBegin, dateEnd\n\n for (let i = 0; i < days.length; i++) {\n const day = days[i]\n dateBegin = null\n\n for (let j = 0; j < workShifts.length; j++) {\n const { name, fromDate, fromTime, toDate, toTime } = workShifts[j]\n\n const convertedFromDate = day.clone().add(fromDate, 'day')\n const convertedToDate = day.clone().add(toDate, 'day')\n\n const from = moment.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n const to = moment.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n\n dateBegin = dateBegin || from\n dateEnd = from.clone().add(1, 'day')\n\n if (dateTime >= from.toDate() && to.toDate() > dateTime) {\n return {\n workDate: moment(day).format(format),\n workShift: name,\n dateRange: [dateBegin.toDate(), dateEnd.toDate()],\n shiftRange: [from.toDate(), to.toDate()]\n }\n }\n }\n }\n\n logger.error(new Error('shift not found'))\n }\n\n /* 3. in case there are no work-shift, just give date and default shift '' */\n return {\n workDate: givenDate.format(format),\n workShift: '',\n dateRange: [theDay.toDate(), theDayAfter.toDate()]\n }\n}\n\nexport async function getLatestWorkDateAndShift(domain: Domain, dateTime: Date, options?: any): Promise<WorkShiftInfo> {\n const dateOptions = { timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD', ...options }\n const { timezone, format } = dateOptions\n\n const givenDate = moment(dateTime).tz(timezone)\n\n /* 1. get work-shift list for the domain */\n const workShifts = await getRepository(WorkShift).find({\n where: {\n domain: { id: domain.id }\n },\n order: {\n fromDate: 'ASC',\n fromTime: 'ASC'\n }\n })\n\n /* 2. compare given date-time to every work-shift */\n const theDay = givenDate.clone().startOf('day')\n const theDayBefore = theDay.clone().subtract(1, 'day')\n const theDayAfter = theDay.clone().add(1, 'day')\n\n if (workShifts && workShifts.length > 0) {\n const days = [theDayBefore, theDay, theDayAfter]\n let dateBegin, dateEnd\n\n for (let i = 0; i < days.length; i++) {\n const day = days[i]\n dateBegin = null\n\n for (let j = 0; j < workShifts.length; j++) {\n const { name, fromDate, fromTime, toDate, toTime } = workShifts[j]\n\n const convertedFromDate = day.clone().add(fromDate, 'day')\n const convertedToDate = day.clone().add(toDate, 'day')\n\n const from = moment.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n const to = moment.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n\n dateBegin = dateBegin || from\n dateEnd = from.clone().add(1, 'day')\n\n if (dateTime < from.toDate()) {\n if (j > 0) {\n const { name, fromDate, fromTime, toDate, toTime } = workShifts[j - 1]\n\n const from = moment.tz(\n `${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`,\n 'YYYY-MM-DD HH:mm:ss',\n timezone\n )\n const to = moment.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n\n return {\n workDate: moment(day).format(format),\n workShift: name,\n dateRange: [dateBegin.toDate(), dateEnd.toDate()],\n shiftRange: [from.toDate(), to.toDate()]\n }\n } else if (i > 0) {\n const { name, fromDate, fromTime, toDate, toTime } = workShifts[0]\n\n const convertedFromDate = days[i - 1].clone().add(fromDate, 'day')\n const convertedToDate = days[i - 1].clone().add(toDate, 'day')\n\n const from = moment.tz(\n `${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`,\n 'YYYY-MM-DD HH:mm:ss',\n timezone\n )\n const to = moment.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)\n\n return {\n workDate: moment(day).format(format),\n workShift: name,\n dateRange: [dateBegin.clone().subtract(1, 'day').toDate(), dateBegin.toDate()],\n shiftRange: [from.toDate(), to.toDate()]\n }\n } else {\n return\n }\n }\n }\n }\n\n logger.error(new Error('shift not found'))\n }\n\n /* 3. in case there are no work-shift, just give date and default shift '' */\n return {\n workDate: givenDate.clone().subtract(1, 'day').format(format),\n workShift: '',\n dateRange: [theDayBefore.toDate(), theDay.toDate()]\n }\n}\n"]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSummaryScheduleForWorkDate = exports.getSummaryScheduleForWorkShift = void 0;
|
|
4
|
+
const shell_1 = require("@things-factory/shell");
|
|
5
|
+
const work_shift_1 = require("../service/work-shift/work-shift");
|
|
6
|
+
async function getSummaryScheduleForWorkShift(domain) {
|
|
7
|
+
const workShifts = await (0, shell_1.getRepository)(work_shift_1.WorkShift).find({
|
|
8
|
+
where: {
|
|
9
|
+
domain: { id: domain.id }
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
if (!workShifts || workShifts.length == 0) {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
const hours = workShifts
|
|
16
|
+
.map(workShift => workShift.toTime)
|
|
17
|
+
.map(getNextHourIn24HourFormat)
|
|
18
|
+
.join(',');
|
|
19
|
+
return `10 ${hours} * * * *`;
|
|
20
|
+
}
|
|
21
|
+
exports.getSummaryScheduleForWorkShift = getSummaryScheduleForWorkShift;
|
|
22
|
+
async function getSummaryScheduleForWorkDate(domain) {
|
|
23
|
+
/* 1. 도메인의 워크시프트를 모두 가져온다. */
|
|
24
|
+
const workShifts = await (0, shell_1.getRepository)(work_shift_1.WorkShift).find({
|
|
25
|
+
where: {
|
|
26
|
+
domain: { id: domain.id }
|
|
27
|
+
},
|
|
28
|
+
order: {
|
|
29
|
+
fromDate: 'ASC',
|
|
30
|
+
fromTime: 'ASC'
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
/* 2. 워크데이의 마지막 시간을 구한 뒤, 그 30분뒤 시간에 매일 수행하는 crontab을 계산한다. */
|
|
34
|
+
if (workShifts && workShifts.length > 0) {
|
|
35
|
+
const { toTime } = workShifts[workShifts.length - 1];
|
|
36
|
+
return timePlusThirtyMinutesToCron(toTime);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.getSummaryScheduleForWorkDate = getSummaryScheduleForWorkDate;
|
|
43
|
+
function timePlusThirtyMinutesToCron(time) {
|
|
44
|
+
const isPM = time.toUpperCase().includes('PM');
|
|
45
|
+
const [hours, minutes] = time
|
|
46
|
+
.toUpperCase()
|
|
47
|
+
.replace(/(AM|PM)/, '')
|
|
48
|
+
.split(':')
|
|
49
|
+
.map(Number);
|
|
50
|
+
// 기준 날짜와 시간 정보를 사용하여 Date 객체를 생성합니다.
|
|
51
|
+
let date = new Date(1970, 0, 1, isPM ? (hours % 12) + 12 : hours % 12, minutes);
|
|
52
|
+
// 30분을 추가합니다.
|
|
53
|
+
date.setMinutes(date.getMinutes() + 30);
|
|
54
|
+
// 결과 시간을 얻습니다.
|
|
55
|
+
const resultHours = String(date.getHours()).padStart(2, '0');
|
|
56
|
+
const resultMinutes = String(date.getMinutes()).padStart(2, '0');
|
|
57
|
+
// 결과 시간을 사용하여 crontab 항목을 반환합니다.
|
|
58
|
+
return `${resultMinutes} ${resultHours} * * * *`;
|
|
59
|
+
}
|
|
60
|
+
function getNextHourIn24HourFormat(time) {
|
|
61
|
+
const isPM = time.toUpperCase().includes('PM');
|
|
62
|
+
const hours = Number(time.split(':')[0]);
|
|
63
|
+
// 기준 날짜와 시간 정보를 사용하여 Date 객체를 생성합니다.
|
|
64
|
+
let date = new Date(1970, 0, 1, isPM ? (hours % 12) + 12 : hours % 12, 0);
|
|
65
|
+
// 시간 값을 1 증가시킵니다.
|
|
66
|
+
date.setHours(date.getHours() + 1);
|
|
67
|
+
// 결과 시간을 얻습니다.
|
|
68
|
+
return String(date.getHours()).padStart(2, '0');
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=work-shift-schedule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"work-shift-schedule.js","sourceRoot":"","sources":["../../server/controllers/work-shift-schedule.ts"],"names":[],"mappings":";;;AAAA,iDAA6D;AAE7D,iEAA4D;AAErD,KAAK,UAAU,8BAA8B,CAAC,MAAc;IACjE,MAAM,UAAU,GAAG,MAAM,IAAA,qBAAa,EAAC,sBAAS,CAAC,CAAC,IAAI,CAAC;QACrD,KAAK,EAAE;YACL,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;SAC1B;KACF,CAAC,CAAA;IAEF,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,EAAE;QACzC,OAAO,EAAE,CAAA;KACV;IAED,MAAM,KAAK,GAAG,UAAU;SACrB,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC;SAClC,GAAG,CAAC,yBAAyB,CAAC;SAC9B,IAAI,CAAC,GAAG,CAAC,CAAA;IAEZ,OAAO,MAAM,KAAK,UAAU,CAAA;AAC9B,CAAC;AAjBD,wEAiBC;AAEM,KAAK,UAAU,6BAA6B,CAAC,MAAc;IAChE,6BAA6B;IAC7B,MAAM,UAAU,GAAG,MAAM,IAAA,qBAAa,EAAC,sBAAS,CAAC,CAAC,IAAI,CAAC;QACrD,KAAK,EAAE;YACL,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;SAC1B;QACD,KAAK,EAAE;YACL,QAAQ,EAAE,KAAK;YACf,QAAQ,EAAE,KAAK;SAChB;KACF,CAAC,CAAA;IAEF,8DAA8D;IAC9D,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;QACvC,MAAM,EAAE,MAAM,EAAE,GAAG,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CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAExC,qCAAqC;IACrC,IAAI,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,EAAE,CAAC,CAAC,CAAA;IAEzE,kBAAkB;IAClB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAA;IAElC,eAAe;IACf,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AACjD,CAAC","sourcesContent":["import { Domain, getRepository } from '@things-factory/shell'\n\nimport { WorkShift } from '../service/work-shift/work-shift'\n\nexport async function getSummaryScheduleForWorkShift(domain: Domain): Promise<string> {\n const workShifts = await getRepository(WorkShift).find({\n where: {\n domain: { id: domain.id }\n }\n })\n\n if (!workShifts || workShifts.length == 0) {\n return ''\n }\n\n const hours = workShifts\n .map(workShift => workShift.toTime)\n .map(getNextHourIn24HourFormat)\n .join(',')\n\n return `10 ${hours} * * * *`\n}\n\nexport async function getSummaryScheduleForWorkDate(domain: Domain): Promise<string> {\n /* 1. 도메인의 워크시프트를 모두 가져온다. */\n const workShifts = await getRepository(WorkShift).find({\n where: {\n domain: { id: domain.id }\n },\n order: {\n fromDate: 'ASC',\n fromTime: 'ASC'\n }\n })\n\n /* 2. 워크데이의 마지막 시간을 구한 뒤, 그 30분뒤 시간에 매일 수행하는 crontab을 계산한다. */\n if (workShifts && workShifts.length > 0) {\n const { toTime } = workShifts[workShifts.length - 1]\n return timePlusThirtyMinutesToCron(toTime)\n } else {\n return\n }\n}\n\nfunction timePlusThirtyMinutesToCron(time: string): string {\n const isPM = time.toUpperCase().includes('PM')\n const [hours, minutes] = time\n .toUpperCase()\n .replace(/(AM|PM)/, '')\n .split(':')\n .map(Number)\n\n // 기준 날짜와 시간 정보를 사용하여 Date 객체를 생성합니다.\n let date = new Date(1970, 0, 1, isPM ? (hours % 12) + 12 : hours % 12, minutes)\n\n // 30분을 추가합니다.\n date.setMinutes(date.getMinutes() + 30)\n\n // 결과 시간을 얻습니다.\n const resultHours = String(date.getHours()).padStart(2, '0')\n const resultMinutes = String(date.getMinutes()).padStart(2, '0')\n\n // 결과 시간을 사용하여 crontab 항목을 반환합니다.\n return `${resultMinutes} ${resultHours} * * * *`\n}\n\nfunction getNextHourIn24HourFormat(time: string): string {\n const isPM = time.toUpperCase().includes('PM')\n const hours = Number(time.split(':')[0])\n\n // 기준 날짜와 시간 정보를 사용하여 Date 객체를 생성합니다.\n let date = new Date(1970, 0, 1, isPM ? (hours % 12) + 12 : hours % 12, 0)\n\n // 시간 값을 1 증가시킵니다.\n date.setHours(date.getHours() + 1)\n\n // 결과 시간을 얻습니다.\n return String(date.getHours()).padStart(2, '0')\n}\n"]}
|