@things-factory/work-shift 6.0.76 → 6.0.78
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 +158 -20
- package/dist-server/controllers/index.js.map +1 -1
- package/dist-server/index.js +0 -3
- package/dist-server/index.js.map +1 -1
- package/dist-server/service/work-shift/work-shift-query.js +1 -1
- package/dist-server/service/work-shift/work-shift-query.js.map +1 -1
- package/dist-server/service/work-shift/work-shift-type.js +17 -9
- package/dist-server/service/work-shift/work-shift-type.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/server/controllers/index.ts +205 -34
- package/server/index.ts +0 -4
- package/server/service/work-shift/work-shift-query.ts +3 -6
- package/server/service/work-shift/work-shift-type.ts +11 -5
- package/server/middlewares/index.ts +0 -3
- package/server/migrations/index.ts +0 -9
- package/server/routes.ts +0 -26
|
@@ -1,25 +1,79 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getWorkDateAndShift = void 0;
|
|
3
|
+
exports.getLatestWorkDateAndShift = exports.getWorkDateAndShift = exports.getDateRangeForWorkDate = exports.getDateRangeForWorkShift = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const moment_timezone_1 = tslib_1.__importDefault(require("moment-timezone"));
|
|
6
6
|
const env_1 = require("@things-factory/env");
|
|
7
7
|
const shell_1 = require("@things-factory/shell");
|
|
8
8
|
const work_shift_1 = require("../service/work-shift/work-shift");
|
|
9
|
-
function
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
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];
|
|
15
71
|
}
|
|
72
|
+
exports.getDateRangeForWorkDate = getDateRangeForWorkDate;
|
|
16
73
|
async function getWorkDateAndShift(domain, dateTime, options) {
|
|
17
74
|
const dateOptions = Object.assign({ timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD' }, options);
|
|
18
75
|
const { timezone, format } = dateOptions;
|
|
19
|
-
// const givenDate = dateTime.toISOString().split('T')[0]
|
|
20
76
|
const givenDate = (0, moment_timezone_1.default)(dateTime).tz(timezone);
|
|
21
|
-
const localDate = new Date(givenDate.format('YYYY-MM-DD HH:mm:ss'));
|
|
22
|
-
const workDate = givenDate.format(format);
|
|
23
77
|
/* 1. get work-shift list for the domain */
|
|
24
78
|
const workShifts = await (0, shell_1.getRepository)(work_shift_1.WorkShift).find({
|
|
25
79
|
where: {
|
|
@@ -31,30 +85,114 @@ async function getWorkDateAndShift(domain, dateTime, options) {
|
|
|
31
85
|
}
|
|
32
86
|
});
|
|
33
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');
|
|
34
91
|
if (workShifts && workShifts.length > 0) {
|
|
35
|
-
const theDay = new Date(givenDate.format('YYYY-MM-DD'));
|
|
36
|
-
const theDayBefore = new Date(theDay.getTime() - 24 * 60 * 60 * 1000);
|
|
37
|
-
const theDayAfter = new Date(theDay.getTime() + 24 * 60 * 60 * 1000);
|
|
38
92
|
const days = [theDayBefore, theDay, theDayAfter];
|
|
93
|
+
let dateBegin, dateEnd;
|
|
39
94
|
for (let i = 0; i < days.length; i++) {
|
|
40
|
-
const
|
|
95
|
+
const day = days[i];
|
|
96
|
+
dateBegin = null;
|
|
41
97
|
for (let j = 0; j < workShifts.length; j++) {
|
|
42
98
|
const { name, fromDate, fromTime, toDate, toTime } = workShifts[j];
|
|
43
|
-
|
|
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) {
|
|
44
106
|
return {
|
|
45
|
-
workDate,
|
|
46
|
-
workShift: name
|
|
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()]
|
|
47
111
|
};
|
|
48
112
|
}
|
|
49
113
|
}
|
|
50
114
|
}
|
|
51
115
|
env_1.logger.error(new Error('shift not found'));
|
|
52
116
|
}
|
|
53
|
-
/* 3. in case there are no work-shift, just give date and default shift '
|
|
117
|
+
/* 3. in case there are no work-shift, just give date and default shift '' */
|
|
54
118
|
return {
|
|
55
|
-
workDate,
|
|
56
|
-
workShift: '
|
|
119
|
+
workDate: givenDate.format(format),
|
|
120
|
+
workShift: '',
|
|
121
|
+
dateRange: [theDay.toDate(), theDayAfter.toDate()]
|
|
57
122
|
};
|
|
58
123
|
}
|
|
59
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;
|
|
60
198
|
//# 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;AAG/E,SAAS,OAAO,CACd,QAA2B,EAC3B,QAAgB,CAAC,WAAW,EAC5B,MAAyB,EACzB,MAAc,CAAC,WAAW,EAC1B,MAAY,EACZ,QAAc;IAEd,MAAM,iBAAiB,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,QAAQ,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAA;IACvF,MAAM,eAAe,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,MAAM,GAAG,CAAC,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-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 { WorkDateWorkShiftPair } from '../service/work-shift/work-shift-type'\n\nfunction between(\n fromDate: WorkShiftDateType,\n fromTime: string /* hh:mm */,\n toDate: WorkShiftDateType,\n toTime: string /* hh:mm */,\n theDay: Date,\n dateTime: Date\n): boolean {\n const convertedFromDate = new Date(theDay.getTime() + fromDate * (24 * 60 * 60 * 1000))\n const convertedToDate = new Date(theDay.getTime() + toDate * (24 * 60 * 60 * 1000))\n const from = new Date(`${convertedFromDate.toISOString().split('T')[0]}T${fromTime}`)\n const to = new Date(`${convertedToDate.toISOString().split('T')[0]}T${toTime}`)\n\n return dateTime >= from && to > dateTime\n}\n\nexport async function getWorkDateAndShift(\n domain: Domain,\n dateTime: Date,\n options?: any\n): Promise<WorkDateWorkShiftPair> {\n const dateOptions = { timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD', ...options }\n const { timezone, format } = dateOptions\n\n // const givenDate = dateTime.toISOString().split('T')[0]\n const givenDate = moment(dateTime).tz(timezone)\n const localDate = new Date(givenDate.format('YYYY-MM-DD HH:mm:ss'))\n const workDate = givenDate.format(format)\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 if (workShifts && workShifts.length > 0) {\n const theDay = new Date(givenDate.format('YYYY-MM-DD'))\n const theDayBefore = new Date(theDay.getTime() - 24 * 60 * 60 * 1000)\n const theDayAfter = new Date(theDay.getTime() + 24 * 60 * 60 * 1000)\n\n const days = [theDayBefore, theDay, theDayAfter]\n\n for (let i = 0; i < days.length; i++) {\n const theDay = days[i]\n\n for (let j = 0; j < workShifts.length; j++) {\n const { name, fromDate, fromTime, toDate, toTime } = workShifts[j]\n\n if (between(fromDate, fromTime, toDate, toTime, theDay, localDate)) {\n return {\n workDate,\n workShift: name\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 'NA' */\n return {\n workDate,\n workShift: 'NA'\n }\n}\n"]}
|
|
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;SACh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C,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;4BACpC,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"]}
|
package/dist-server/index.js
CHANGED
|
@@ -2,8 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./controllers"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./migrations"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./middlewares"), exports);
|
|
7
5
|
tslib_1.__exportStar(require("./service"), exports);
|
|
8
|
-
require("./routes");
|
|
9
6
|
//# sourceMappingURL=index.js.map
|
package/dist-server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,wDAA6B;AAC7B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,wDAA6B;AAC7B,oDAAyB","sourcesContent":["export * from './controllers'\nexport * from './service'\n"]}
|
|
@@ -26,7 +26,7 @@ let DomainWorkShiftQuery = class DomainWorkShiftQuery {
|
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
28
|
tslib_1.__decorate([
|
|
29
|
-
(0, type_graphql_1.Query)(returns => work_shift_type_1.
|
|
29
|
+
(0, type_graphql_1.Query)(returns => work_shift_type_1.WorkShiftInfo, { description: 'To fetch a work date and work shift for given datetime' }),
|
|
30
30
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('dateTime')),
|
|
31
31
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
32
32
|
tslib_1.__metadata("design:type", Function),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"work-shift-query.js","sourceRoot":"","sources":["../../../server/service/work-shift/work-shift-query.ts"],"names":[],"mappings":";;;;AAAA,+CAAmF;AAEnF,yDAAgD;AAChD,iDAAuG;AAEvG,mDAA6D;AAC7D,6CAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"work-shift-query.js","sourceRoot":"","sources":["../../../server/service/work-shift/work-shift-query.ts"],"names":[],"mappings":";;;;AAAA,+CAAmF;AAEnF,yDAAgD;AAChD,iDAAuG;AAEvG,mDAA6D;AAC7D,6CAAwC;AACxC,uDAAgE;AAGzD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAEzB,AAAN,KAAK,CAAC,mBAAmB,CAAkB,QAAc,EAAS,OAAwB;QACxF,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEhC,OAAO,MAAM,IAAA,2BAAmB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IACpD,CAAC;IAGK,AAAN,KAAK,CAAC,UAAU,CAAS,MAAc;QACrC,OAAO,MAAM,IAAA,qBAAa,EAAC,sBAAS,CAAC,CAAC,IAAI,CAAC;YACzC,KAAK,EAAE;gBACL,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;aAC1B;YACD,KAAK,EAAE;gBACL,QAAQ,EAAE,KAAK;gBACf,QAAQ,EAAE,KAAK;aAChB;SACF,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAlBO;IADL,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,+BAAa,EAAE,EAAE,WAAW,EAAE,wDAAwD,EAAE,CAAC;IAChF,mBAAA,IAAA,kBAAG,EAAC,UAAU,CAAC,CAAA;IAAkB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;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ACF,CAAA;AA5BO;IADL,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,+BAAa,EAAE,EAAE,WAAW,EAAE,8BAA8B,EAAE,CAAC;IAC/D,mBAAA,IAAA,mBAAI,GAAE,CAAA;IAAqB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;6CAAjB,iBAAS;;gDAYzC;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,CAAC;IAChB,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAY,sBAAS;;4CAExC;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,CAAC;IACb,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAY,sBAAS;;6CAEzC;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,CAAC;IACb,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAY,sBAAS;;6CAEzC;AA7BU,cAAc;IAD1B,IAAA,uBAAQ,EAAC,sBAAS,CAAC;GACP,cAAc,CA8B1B;AA9BY,wCAAc","sourcesContent":["import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'\n\nimport { User } from '@things-factory/auth-base'\nimport { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'\n\nimport { getWorkDateAndShift } from '../../controllers/index'\nimport { WorkShift } from './work-shift'\nimport { WorkShiftInfo, WorkShiftList } from './work-shift-type'\n\n@Resolver(Domain)\nexport class DomainWorkShiftQuery {\n @Query(returns => WorkShiftInfo, { description: 'To fetch a work date and work shift for given datetime' })\n async getWorkDateAndShift(@Arg('dateTime') dateTime: Date, @Ctx() context: ResolverContext): Promise<WorkShiftInfo> {\n const { domain } = context.state\n\n return await getWorkDateAndShift(domain, dateTime)\n }\n\n @FieldResolver(type => [WorkShift])\n async workShifts(@Root() domain: Domain): Promise<WorkShift[]> {\n return await getRepository(WorkShift).find({\n where: {\n domain: { id: domain.id }\n },\n order: {\n fromDate: 'ASC',\n fromTime: 'ASC'\n }\n })\n }\n}\n\n@Resolver(WorkShift)\nexport class WorkShiftQuery {\n @Query(returns => WorkShiftList, { description: 'To fetch multiple WorkShifts' })\n async workShifts(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<WorkShiftList> {\n const { domain } = context.state\n\n const queryBuilder = getQueryBuilderFromListParams({\n repository: getRepository(WorkShift),\n params,\n domain\n })\n\n const [items, total] = await queryBuilder.getManyAndCount()\n\n return { items, total }\n }\n\n @FieldResolver(type => Domain)\n async domain(@Root() workShift: WorkShift): Promise<Domain> {\n return await getRepository(Domain).findOneBy({ id: workShift.domainId })\n }\n\n @FieldResolver(type => User)\n async updater(@Root() workShift: WorkShift): Promise<User> {\n return await getRepository(User).findOneBy({ id: workShift.updaterId })\n }\n\n @FieldResolver(type => User)\n async creator(@Root() workShift: WorkShift): Promise<User> {\n return await getRepository(User).findOneBy({ id: workShift.creatorId })\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.WorkShiftInfo = exports.WorkShiftList = exports.WorkShiftPatch = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const type_graphql_1 = require("type-graphql");
|
|
6
6
|
const work_shift_1 = require("./work-shift");
|
|
@@ -48,18 +48,26 @@ WorkShiftList = tslib_1.__decorate([
|
|
|
48
48
|
(0, type_graphql_1.ObjectType)()
|
|
49
49
|
], WorkShiftList);
|
|
50
50
|
exports.WorkShiftList = WorkShiftList;
|
|
51
|
-
let
|
|
51
|
+
let WorkShiftInfo = class WorkShiftInfo {
|
|
52
52
|
};
|
|
53
53
|
tslib_1.__decorate([
|
|
54
|
-
(0, type_graphql_1.Field)(),
|
|
54
|
+
(0, type_graphql_1.Field)({ nullable: true }),
|
|
55
55
|
tslib_1.__metadata("design:type", String)
|
|
56
|
-
],
|
|
56
|
+
], WorkShiftInfo.prototype, "workDate", void 0);
|
|
57
57
|
tslib_1.__decorate([
|
|
58
|
-
(0, type_graphql_1.Field)(),
|
|
58
|
+
(0, type_graphql_1.Field)({ nullable: true }),
|
|
59
59
|
tslib_1.__metadata("design:type", String)
|
|
60
|
-
],
|
|
61
|
-
|
|
60
|
+
], WorkShiftInfo.prototype, "workShift", void 0);
|
|
61
|
+
tslib_1.__decorate([
|
|
62
|
+
(0, type_graphql_1.Field)(type => [Date], { nullable: true }),
|
|
63
|
+
tslib_1.__metadata("design:type", Array)
|
|
64
|
+
], WorkShiftInfo.prototype, "dateRange", void 0);
|
|
65
|
+
tslib_1.__decorate([
|
|
66
|
+
(0, type_graphql_1.Field)(type => [Date], { nullable: true }),
|
|
67
|
+
tslib_1.__metadata("design:type", Array)
|
|
68
|
+
], WorkShiftInfo.prototype, "shiftRange", void 0);
|
|
69
|
+
WorkShiftInfo = tslib_1.__decorate([
|
|
62
70
|
(0, type_graphql_1.ObjectType)()
|
|
63
|
-
],
|
|
64
|
-
exports.
|
|
71
|
+
], WorkShiftInfo);
|
|
72
|
+
exports.WorkShiftInfo = WorkShiftInfo;
|
|
65
73
|
//# sourceMappingURL=work-shift-type.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"work-shift-type.js","sourceRoot":"","sources":["../../../server/service/work-shift/work-shift-type.ts"],"names":[],"mappings":";;;;AAAA,+CAAsF;AACtF,6CAA2D;AAGpD,IAAM,cAAc,GAApB,MAAM,cAAc;CAkB1B,CAAA;AAjBC;IAAC,IAAA,oBAAK,GAAE;;4CACI;AAEZ;IAAC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;mDACN;AAEpB;IAAC,IAAA,oBAAK,GAAE;;gDACmB;AAE3B;IAAC,IAAA,oBAAK,GAAE;;gDACQ;AAEhB;IAAC,IAAA,oBAAK,GAAE;;8CACiB;AAEzB;IAAC,IAAA,oBAAK,GAAE;;8CACM;AAjBH,cAAc;IAD1B,IAAA,wBAAS,GAAE;GACC,cAAc,CAkB1B;AAlBY,wCAAc;AAqBpB,IAAM,aAAa,GAAnB,MAAM,aAAa;CAMzB,CAAA;AALC;IAAC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,sBAAS,CAAC,CAAC;;4CACT;AAElB;IAAC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,CAAC;;4CACN;AALF,aAAa;IADzB,IAAA,yBAAU,GAAE;GACA,aAAa,CAMzB;AANY,sCAAa;AASnB,IAAM,
|
|
1
|
+
{"version":3,"file":"work-shift-type.js","sourceRoot":"","sources":["../../../server/service/work-shift/work-shift-type.ts"],"names":[],"mappings":";;;;AAAA,+CAAsF;AACtF,6CAA2D;AAGpD,IAAM,cAAc,GAApB,MAAM,cAAc;CAkB1B,CAAA;AAjBC;IAAC,IAAA,oBAAK,GAAE;;4CACI;AAEZ;IAAC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;mDACN;AAEpB;IAAC,IAAA,oBAAK,GAAE;;gDACmB;AAE3B;IAAC,IAAA,oBAAK,GAAE;;gDACQ;AAEhB;IAAC,IAAA,oBAAK,GAAE;;8CACiB;AAEzB;IAAC,IAAA,oBAAK,GAAE;;8CACM;AAjBH,cAAc;IAD1B,IAAA,wBAAS,GAAE;GACC,cAAc,CAkB1B;AAlBY,wCAAc;AAqBpB,IAAM,aAAa,GAAnB,MAAM,aAAa;CAMzB,CAAA;AALC;IAAC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,sBAAS,CAAC,CAAC;;4CACT;AAElB;IAAC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,CAAC;;4CACN;AALF,aAAa;IADzB,IAAA,yBAAU,GAAE;GACA,aAAa,CAMzB;AANY,sCAAa;AASnB,IAAM,aAAa,GAAnB,MAAM,aAAa;CAYzB,CAAA;AAXC;IAAC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;+CACT;AAEjB;IAAC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;gDACR;AAElB;IAAC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;gDACxB;AAElB;IAAC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;iDACvB;AAXR,aAAa;IADzB,IAAA,yBAAU,GAAE;GACA,aAAa,CAYzB;AAZY,sCAAa","sourcesContent":["import { Field, ID, InputType, Int, ObjectType, registerEnumType } from 'type-graphql'\nimport { WorkShift, WorkShiftDateType } from './work-shift'\n\n@InputType()\nexport class WorkShiftPatch {\n @Field()\n name: string\n\n @Field({ nullable: true })\n description?: string\n\n @Field()\n fromDate: WorkShiftDateType\n\n @Field()\n fromTime: string\n\n @Field()\n toDate: WorkShiftDateType\n\n @Field()\n toTime: string\n}\n\n@ObjectType()\nexport class WorkShiftList {\n @Field(type => [WorkShift])\n items: WorkShift[]\n\n @Field(type => Int)\n total: number\n}\n\n@ObjectType()\nexport class WorkShiftInfo {\n @Field({ nullable: true })\n workDate?: string\n\n @Field({ nullable: true })\n workShift?: string\n\n @Field(type => [Date], { nullable: true })\n dateRange?: Date[]\n\n @Field(type => [Date], { nullable: true })\n shiftRange?: Date[]\n}\n"]}
|