@things-factory/work-shift 10.0.18 → 10.1.0
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-client/pages/work-shift.d.ts +106 -1
- package/dist-client/pages/work-shift.js +798 -43
- package/dist-client/pages/work-shift.js.map +1 -1
- package/dist-client/shift-coverage.d.ts +76 -0
- package/dist-client/shift-coverage.js +146 -0
- package/dist-client/shift-coverage.js.map +1 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/controllers/work-shift-range.js +23 -36
- package/dist-server/controllers/work-shift-range.js.map +1 -1
- package/dist-server/service/index.d.ts +5 -2
- package/dist-server/service/index.js +9 -0
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/work-shift/days-of-week.d.ts +30 -0
- package/dist-server/service/work-shift/days-of-week.js +74 -0
- package/dist-server/service/work-shift/days-of-week.js.map +1 -0
- package/dist-server/service/work-shift/index.d.ts +5 -2
- package/dist-server/service/work-shift/index.js +11 -2
- package/dist-server/service/work-shift/index.js.map +1 -1
- package/dist-server/service/work-shift/work-shift-mutation.d.ts +10 -0
- package/dist-server/service/work-shift/work-shift-mutation.js +51 -1
- package/dist-server/service/work-shift/work-shift-mutation.js.map +1 -1
- package/dist-server/service/work-shift/work-shift-revision-query.d.ts +20 -0
- package/dist-server/service/work-shift/work-shift-revision-query.js +74 -0
- package/dist-server/service/work-shift/work-shift-revision-query.js.map +1 -0
- package/dist-server/service/work-shift/work-shift-revision-service.d.ts +69 -0
- package/dist-server/service/work-shift/work-shift-revision-service.js +186 -0
- package/dist-server/service/work-shift/work-shift-revision-service.js.map +1 -0
- package/dist-server/service/work-shift/work-shift-revision.d.ts +67 -0
- package/dist-server/service/work-shift/work-shift-revision.js +116 -0
- package/dist-server/service/work-shift/work-shift-revision.js.map +1 -0
- package/dist-server/service/work-shift/work-shift-selection.d.ts +50 -0
- package/dist-server/service/work-shift/work-shift-selection.js +65 -0
- package/dist-server/service/work-shift/work-shift-selection.js.map +1 -0
- package/dist-server/service/work-shift/work-shift-type.d.ts +12 -0
- package/dist-server/service/work-shift/work-shift-type.js +20 -1
- package/dist-server/service/work-shift/work-shift-type.js.map +1 -1
- package/dist-server/service/work-shift/work-shift.d.ts +32 -0
- package/dist-server/service/work-shift/work-shift.js +5 -0
- package/dist-server/service/work-shift/work-shift.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/helps/page/work-shift.ko.md +5 -0
- package/helps/page/work-shift.md +13 -0
- package/package.json +6 -5
- package/translations/en.json +31 -1
- package/translations/ja.json +1 -1
- package/translations/ko.json +31 -1
- package/translations/ms.json +1 -1
- package/translations/zh.json +1 -1
|
@@ -9,15 +9,26 @@ const moment_timezone_1 = tslib_1.__importDefault(require("moment-timezone"));
|
|
|
9
9
|
const env_1 = require("@things-factory/env");
|
|
10
10
|
const shell_1 = require("@things-factory/shell");
|
|
11
11
|
const work_shift_1 = require("../service/work-shift/work-shift");
|
|
12
|
+
const work_shift_revision_service_1 = require("../service/work-shift/work-shift-revision-service");
|
|
13
|
+
/**
|
|
14
|
+
* 그 시각에 쓰던 교대 — **지금 편성이 아닐 수 있다.**
|
|
15
|
+
*
|
|
16
|
+
* 편성이 바뀌기 전의 시각을 지금 편성으로 읽으면, 그 시각의 사실이 있지도 않았던 교대 이름으로 나온다.
|
|
17
|
+
* 공장이 2교대에서 3교대로 바꾸는 날 지난 석 달의 실적이 통째로 다시 이름 붙는 것이 그것이다.
|
|
18
|
+
*
|
|
19
|
+
* **이력보다 앞선 시각은 빈 목록이다.** 그때 무엇을 쓰고 있었는지 이 시스템은 모른다 — 지금 편성으로
|
|
20
|
+
* 대신하지 않는다.
|
|
21
|
+
*/
|
|
22
|
+
async function shiftsAt(domain, at) {
|
|
23
|
+
const found = await (0, work_shift_revision_service_1.shiftsInForceAt)((0, shell_1.getRepository)(work_shift_1.WorkShift).manager, domain, at);
|
|
24
|
+
return (found?.shifts ?? []);
|
|
25
|
+
}
|
|
12
26
|
async function getDateRangeForWorkShift(domain, workDate, workShiftName, options) {
|
|
13
27
|
const dateOptions = { timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD', ...options };
|
|
14
28
|
const { timezone, format } = dateOptions;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
name: workShiftName
|
|
19
|
-
}
|
|
20
|
-
});
|
|
29
|
+
/* 그 조업일에 쓰던 편성에서 찾는다 — 지금 편성에는 없는 이름일 수 있다. */
|
|
30
|
+
const asOf = moment_timezone_1.default.tz(workDate, timezone).toDate();
|
|
31
|
+
const workShift = (await shiftsAt(domain, asOf)).find(shift => shift.name === workShiftName);
|
|
21
32
|
if (!workShift) {
|
|
22
33
|
return;
|
|
23
34
|
}
|
|
@@ -36,16 +47,8 @@ async function getDateRangeForWorkDate(domain, workDate, options) {
|
|
|
36
47
|
const { timezone, format } = dateOptions;
|
|
37
48
|
var beginDate;
|
|
38
49
|
var endDate;
|
|
39
|
-
/* 1.
|
|
40
|
-
const workShifts = await (
|
|
41
|
-
where: {
|
|
42
|
-
domain: { id: domain.id }
|
|
43
|
-
},
|
|
44
|
-
order: {
|
|
45
|
-
fromDate: 'ASC',
|
|
46
|
-
fromTime: 'ASC'
|
|
47
|
-
}
|
|
48
|
-
});
|
|
50
|
+
/* 1. 그 조업일에 쓰던 편성을 가져온다 — 지금 편성이 아닐 수 있다. */
|
|
51
|
+
const workShifts = await shiftsAt(domain, moment_timezone_1.default.tz(workDate, timezone).toDate());
|
|
49
52
|
/* 2. get date-time for every work-shift */
|
|
50
53
|
if (workShifts && workShifts.length > 0) {
|
|
51
54
|
const theDay = moment_timezone_1.default.tz(workDate, timezone);
|
|
@@ -75,16 +78,8 @@ async function getWorkDateAndShift(domain, dateTime, options) {
|
|
|
75
78
|
const dateOptions = { timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD', ...options };
|
|
76
79
|
const { timezone, format } = dateOptions;
|
|
77
80
|
const givenDate = (0, moment_timezone_1.default)(dateTime).tz(timezone);
|
|
78
|
-
/* 1.
|
|
79
|
-
const workShifts = await (
|
|
80
|
-
where: {
|
|
81
|
-
domain: { id: domain.id }
|
|
82
|
-
},
|
|
83
|
-
order: {
|
|
84
|
-
fromDate: 'ASC',
|
|
85
|
-
fromTime: 'ASC'
|
|
86
|
-
}
|
|
87
|
-
});
|
|
81
|
+
/* 1. 그 시각에 쓰던 편성을 가져온다 — 바뀌기 전의 시각이면 지금 편성이 아니다. */
|
|
82
|
+
const workShifts = await shiftsAt(domain, dateTime);
|
|
88
83
|
/* 2. compare given date-time to every work-shift */
|
|
89
84
|
const theDay = givenDate.clone().startOf('day');
|
|
90
85
|
const theDayBefore = theDay.clone().subtract(1, 'day');
|
|
@@ -126,16 +121,8 @@ async function getLatestWorkDateAndShift(domain, dateTime, options) {
|
|
|
126
121
|
const dateOptions = { timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD', ...options };
|
|
127
122
|
const { timezone, format } = dateOptions;
|
|
128
123
|
const givenDate = (0, moment_timezone_1.default)(dateTime).tz(timezone);
|
|
129
|
-
/* 1.
|
|
130
|
-
const workShifts = await (
|
|
131
|
-
where: {
|
|
132
|
-
domain: { id: domain.id }
|
|
133
|
-
},
|
|
134
|
-
order: {
|
|
135
|
-
fromDate: 'ASC',
|
|
136
|
-
fromTime: 'ASC'
|
|
137
|
-
}
|
|
138
|
-
});
|
|
124
|
+
/* 1. 그 시각에 쓰던 편성을 가져온다 — 바뀌기 전의 시각이면 지금 편성이 아니다. */
|
|
125
|
+
const workShifts = await shiftsAt(domain, dateTime);
|
|
139
126
|
/* 2. compare given date-time to every work-shift */
|
|
140
127
|
const theDay = givenDate.clone().startOf('day');
|
|
141
128
|
const theDayBefore = theDay.clone().subtract(1, 'day');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"work-shift-range.js","sourceRoot":"","sources":["../../server/controllers/work-shift-range.ts"],"names":[],"mappings":";;AAQA,4DA8BC;AAED,0DAkDC;AAED,kDA6DC;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AAE,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;oBACH,CAAC;yBAAM,CAAC;wBACN,OAAM;oBACR,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,YAAM,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAA;IAC5C,CAAC;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","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"]}
|
|
1
|
+
{"version":3,"file":"work-shift-range.js","sourceRoot":"","sources":["../../server/controllers/work-shift-range.ts"],"names":[],"mappings":";;AAwBA,4DA2BC;AAED,0DA0CC;AAED,kDAqDC;AAED,8DAsFC;;AA9OD,8EAAoC;AAEpC,6CAA4C;AAC5C,iDAA6D;AAE7D,iEAA4D;AAE5D,mGAAmF;AAEnF;;;;;;;;GAQG;AACH,KAAK,UAAU,QAAQ,CAAC,MAAc,EAAE,EAAQ;IAC9C,MAAM,KAAK,GAAG,MAAM,IAAA,6CAAe,EAAC,IAAA,qBAAa,EAAC,sBAAS,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,CAAA;IAEjF,OAAO,CAAC,KAAK,EAAE,MAAM,IAAI,EAAE,CAA8E,CAAA;AAC3G,CAAC;AAEM,KAAK,UAAU,wBAAwB,CAC5C,MAAc,EACd,QAAgB,EAChB,aAAqB,EACrB,OAAgD;IAEhD,MAAM,WAAW,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,EAAE,CAAA;IAC5F,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,WAAW,CAAA;IAExC,+CAA+C;IAC/C,MAAM,IAAI,GAAG,yBAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAA;IACnD,MAAM,SAAS,GAAG,CAAC,MAAM,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CA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T,CAAA;wBACD,MAAM,EAAE,GAAG,yBAAM,CAAC,EAAE,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,MAAM,EAAE,EAAE,qBAAqB,EAAE,QAAQ,CAAC,CAAA;wBAE1G,OAAO;4BACL,QAAQ,EAAE,IAAA,yBAAM,EAAC,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;oBACH,CAAC;yBAAM,CAAC;wBACN,OAAM;oBACR,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,YAAM,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAA;IAC5C,CAAC;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","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'\nimport { shiftsInForceAt } from '../service/work-shift/work-shift-revision-service'\n\n/**\n * 그 시각에 쓰던 교대 — **지금 편성이 아닐 수 있다.**\n *\n * 편성이 바뀌기 전의 시각을 지금 편성으로 읽으면, 그 시각의 사실이 있지도 않았던 교대 이름으로 나온다.\n * 공장이 2교대에서 3교대로 바꾸는 날 지난 석 달의 실적이 통째로 다시 이름 붙는 것이 그것이다.\n *\n * **이력보다 앞선 시각은 빈 목록이다.** 그때 무엇을 쓰고 있었는지 이 시스템은 모른다 — 지금 편성으로\n * 대신하지 않는다.\n */\nasync function shiftsAt(domain: Domain, at: Date): Promise<Pick<WorkShift, 'name' | 'fromDate' | 'fromTime' | 'toDate' | 'toTime'>[]> {\n const found = await shiftsInForceAt(getRepository(WorkShift).manager, domain, at)\n\n return (found?.shifts ?? []) as Pick<WorkShift, 'name' | 'fromDate' | 'fromTime' | 'toDate' | 'toTime'>[]\n}\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 /* 그 조업일에 쓰던 편성에서 찾는다 — 지금 편성에는 없는 이름일 수 있다. */\n const asOf = moment.tz(workDate, timezone).toDate()\n const workShift = (await shiftsAt(domain, asOf)).find(shift => shift.name === workShiftName)\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. 그 조업일에 쓰던 편성을 가져온다 — 지금 편성이 아닐 수 있다. */\n const workShifts = await shiftsAt(domain, moment.tz(workDate, timezone).toDate())\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. 그 시각에 쓰던 편성을 가져온다 — 바뀌기 전의 시각이면 지금 편성이 아니다. */\n const workShifts = await shiftsAt(domain, dateTime)\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. 그 시각에 쓰던 편성을 가져온다 — 바뀌기 전의 시각이면 지금 편성이 아니다. */\n const workShifts = await shiftsAt(domain, dateTime)\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,5 +1,8 @@
|
|
|
1
1
|
export * from './work-shift/work-shift';
|
|
2
|
-
export
|
|
2
|
+
export * from './work-shift/work-shift-revision';
|
|
3
|
+
export * from './work-shift/work-shift-revision-service';
|
|
4
|
+
export * from './work-shift/days-of-week';
|
|
5
|
+
export declare const entities: (typeof import("./work-shift/work-shift").WorkShift | typeof import("./work-shift/work-shift-revision").WorkShiftRevision)[];
|
|
3
6
|
export declare const schema: {
|
|
4
|
-
resolverClasses: (typeof import("./work-shift/work-shift-query").DomainWorkShiftQuery | typeof import("./work-shift/work-shift-query").WorkShiftQuery | typeof import("./work-shift/work-shift-mutation").WorkShiftMutation)[];
|
|
7
|
+
resolverClasses: (typeof import("./work-shift/work-shift-query").DomainWorkShiftQuery | typeof import("./work-shift/work-shift-query").WorkShiftQuery | typeof import("./work-shift/work-shift-mutation").WorkShiftMutation | typeof import("./work-shift/work-shift-revision-query").WorkShiftRevisionQuery)[];
|
|
5
8
|
};
|
|
@@ -4,6 +4,15 @@ exports.schema = exports.entities = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
/* EXPORT ENTITY TYPES */
|
|
6
6
|
tslib_1.__exportStar(require("./work-shift/work-shift"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./work-shift/work-shift-revision"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./work-shift/work-shift-revision-service"), exports);
|
|
9
|
+
/*
|
|
10
|
+
* This file names each source file rather than re-exporting the folder barrel, so anything added
|
|
11
|
+
* to that barrel stops at the package boundary unless it is also listed here. `daysOfWeek` is
|
|
12
|
+
* stored as a CSV and every consumer has to parse it, so the parser has to be reachable — a
|
|
13
|
+
* consumer that cannot import it writes its own, and the two disagree quietly.
|
|
14
|
+
*/
|
|
15
|
+
tslib_1.__exportStar(require("./work-shift/days-of-week"), exports);
|
|
7
16
|
/* IMPORT ENTITIES AND RESOLVERS */
|
|
8
17
|
const work_shift_1 = require("./work-shift");
|
|
9
18
|
exports.entities = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/service/index.ts"],"names":[],"mappings":";;;;AAAA,yBAAyB;AACzB,kEAAuC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/service/index.ts"],"names":[],"mappings":";;;;AAAA,yBAAyB;AACzB,kEAAuC;AACvC,2EAAgD;AAChD,mFAAwD;AACxD;;;;;GAKG;AACH,oEAAyC;AAEzC,mCAAmC;AACnC,6CAA6F;AAEhF,QAAA,QAAQ,GAAG;IACtB,cAAc;IACf,GAAG,qBAAiB;CACpB,CAAA;AAGY,QAAA,MAAM,GAAG;IACpB,eAAe,EAAE;QACf,sBAAsB;QACxB,GAAG,sBAAkB;KACpB;CACF,CAAA","sourcesContent":["/* EXPORT ENTITY TYPES */\nexport * from './work-shift/work-shift'\nexport * from './work-shift/work-shift-revision'\nexport * from './work-shift/work-shift-revision-service'\n/*\n * This file names each source file rather than re-exporting the folder barrel, so anything added\n * to that barrel stops at the package boundary unless it is also listed here. `daysOfWeek` is\n * stored as a CSV and every consumer has to parse it, so the parser has to be reachable — a\n * consumer that cannot import it writes its own, and the two disagree quietly.\n */\nexport * from './work-shift/days-of-week'\n\n/* IMPORT ENTITIES AND RESOLVERS */\nimport { entities as WorkShiftEntities, resolvers as WorkShiftResolvers } from './work-shift'\n\nexport const entities = [ \n /* ENTITIES */\n\t...WorkShiftEntities,\n] \n\n\nexport const schema = {\n resolverClasses: [\n /* RESOLVER CLASSES */\n\t\t...WorkShiftResolvers,\n ] \n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** 0 Sunday … 6 Saturday, the same numbering `Date.getDay()` uses. */
|
|
2
|
+
export type Weekday = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
3
|
+
/**
|
|
4
|
+
* The weekdays this shift runs on, or `undefined` when it runs every day.
|
|
5
|
+
*
|
|
6
|
+
* Junk is dropped rather than throwing. This value comes from a column that a person can
|
|
7
|
+
* edit and from clients written before the field existed; refusing to read a row because
|
|
8
|
+
* one segment is wrong would take a whole site's calendar down for a typo. What is
|
|
9
|
+
* dropped is a segment, and if every segment is junk the result is `undefined` — which is
|
|
10
|
+
* the pre-existing behaviour, not a made-up restriction.
|
|
11
|
+
*/
|
|
12
|
+
export declare function readDaysOfWeek(csv?: string | null): Weekday[] | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* The stored form of a weekday list, or `undefined` for every day.
|
|
15
|
+
*
|
|
16
|
+
* Sorted and de-duplicated so that two ways of saying the same thing produce the same
|
|
17
|
+
* string — otherwise a row looks changed when it is not, and the revision history fills
|
|
18
|
+
* with edits nobody made.
|
|
19
|
+
*/
|
|
20
|
+
export declare function writeDaysOfWeek(days?: readonly number[] | null): string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Does this shift run on that date?
|
|
23
|
+
*
|
|
24
|
+
* ⚠ The weekday is read in the caller's timezone, because `Date.getDay()` is local. A
|
|
25
|
+
* shift's days are stated against the site's calendar, so the date handed in must already
|
|
26
|
+
* be in the site's time base — the same rule the shift's `HH:MM` already follows
|
|
27
|
+
* (§`withSpaceTimeBase`). Handing in a UTC date for a site that is not on UTC will get
|
|
28
|
+
* the wrong answer near midnight, silently.
|
|
29
|
+
*/
|
|
30
|
+
export declare function runsOn(csv: string | null | undefined, when: Date): boolean;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Reading and writing a shift's weekdays — pure, one place.
|
|
4
|
+
*
|
|
5
|
+
* ── Why this is not left to each consumer ─────────────────────────────────
|
|
6
|
+
* The column is a CSV because array columns are not portable across the five drivers
|
|
7
|
+
* things-factory supports. That means every reader has to parse it, and a parser written
|
|
8
|
+
* twice will disagree eventually — on whitespace, on an out-of-range digit, on what an
|
|
9
|
+
* empty string means. The disagreement would not raise anything: one consumer would think
|
|
10
|
+
* the site rests on Sunday and another would not, and both would keep computing.
|
|
11
|
+
*
|
|
12
|
+
* So the string is written and read here, and the meaning is decided once.
|
|
13
|
+
*
|
|
14
|
+
* ── Empty means every day ─────────────────────────────────────────────────
|
|
15
|
+
* Rows that predate the column have no value, and they must keep behaving as they did.
|
|
16
|
+
* `undefined` is returned for that case rather than a full list of seven, so a caller can
|
|
17
|
+
* still tell "no restriction was ever stated" from "someone chose all seven days". The
|
|
18
|
+
* two are the same in effect and different in intent, and the second one is a person's
|
|
19
|
+
* decision worth keeping.
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.readDaysOfWeek = readDaysOfWeek;
|
|
23
|
+
exports.writeDaysOfWeek = writeDaysOfWeek;
|
|
24
|
+
exports.runsOn = runsOn;
|
|
25
|
+
/**
|
|
26
|
+
* The weekdays this shift runs on, or `undefined` when it runs every day.
|
|
27
|
+
*
|
|
28
|
+
* Junk is dropped rather than throwing. This value comes from a column that a person can
|
|
29
|
+
* edit and from clients written before the field existed; refusing to read a row because
|
|
30
|
+
* one segment is wrong would take a whole site's calendar down for a typo. What is
|
|
31
|
+
* dropped is a segment, and if every segment is junk the result is `undefined` — which is
|
|
32
|
+
* the pre-existing behaviour, not a made-up restriction.
|
|
33
|
+
*/
|
|
34
|
+
function readDaysOfWeek(csv) {
|
|
35
|
+
if (!csv || !csv.trim()) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const days = new Set();
|
|
39
|
+
for (const part of csv.split(',')) {
|
|
40
|
+
const n = Number(part.trim());
|
|
41
|
+
if (Number.isInteger(n) && n >= 0 && n <= 6) {
|
|
42
|
+
days.add(n);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return days.size ? [...days].sort((a, b) => a - b) : undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The stored form of a weekday list, or `undefined` for every day.
|
|
49
|
+
*
|
|
50
|
+
* Sorted and de-duplicated so that two ways of saying the same thing produce the same
|
|
51
|
+
* string — otherwise a row looks changed when it is not, and the revision history fills
|
|
52
|
+
* with edits nobody made.
|
|
53
|
+
*/
|
|
54
|
+
function writeDaysOfWeek(days) {
|
|
55
|
+
if (!days?.length) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const kept = readDaysOfWeek(days.join(','));
|
|
59
|
+
return kept?.join(',');
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Does this shift run on that date?
|
|
63
|
+
*
|
|
64
|
+
* ⚠ The weekday is read in the caller's timezone, because `Date.getDay()` is local. A
|
|
65
|
+
* shift's days are stated against the site's calendar, so the date handed in must already
|
|
66
|
+
* be in the site's time base — the same rule the shift's `HH:MM` already follows
|
|
67
|
+
* (§`withSpaceTimeBase`). Handing in a UTC date for a site that is not on UTC will get
|
|
68
|
+
* the wrong answer near midnight, silently.
|
|
69
|
+
*/
|
|
70
|
+
function runsOn(csv, when) {
|
|
71
|
+
const days = readDaysOfWeek(csv);
|
|
72
|
+
return days === undefined || days.includes(when.getDay());
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=days-of-week.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"days-of-week.js","sourceRoot":"","sources":["../../../server/service/work-shift/days-of-week.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;AAcH,wCAgBC;AASD,0CAQC;AAWD,wBAIC;AAzDD;;;;;;;;GAQG;AACH,SAAgB,cAAc,CAAC,GAAmB;IAChD,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;QACxB,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,GAAG,EAAW,CAAA;IAE/B,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;QAE7B,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5C,IAAI,CAAC,GAAG,CAAC,CAAY,CAAC,CAAA;QACxB,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AAChE,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,IAA+B;IAC7D,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;QAClB,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,MAAM,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;IAE3C,OAAO,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;AACxB,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,MAAM,CAAC,GAA8B,EAAE,IAAU;IAC/D,MAAM,IAAI,GAAG,cAAc,CAAC,GAAG,CAAC,CAAA;IAEhC,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAa,CAAC,CAAA;AACtE,CAAC","sourcesContent":["/*\n * Reading and writing a shift's weekdays — pure, one place.\n *\n * ── Why this is not left to each consumer ─────────────────────────────────\n * The column is a CSV because array columns are not portable across the five drivers\n * things-factory supports. That means every reader has to parse it, and a parser written\n * twice will disagree eventually — on whitespace, on an out-of-range digit, on what an\n * empty string means. The disagreement would not raise anything: one consumer would think\n * the site rests on Sunday and another would not, and both would keep computing.\n *\n * So the string is written and read here, and the meaning is decided once.\n *\n * ── Empty means every day ─────────────────────────────────────────────────\n * Rows that predate the column have no value, and they must keep behaving as they did.\n * `undefined` is returned for that case rather than a full list of seven, so a caller can\n * still tell \"no restriction was ever stated\" from \"someone chose all seven days\". The\n * two are the same in effect and different in intent, and the second one is a person's\n * decision worth keeping.\n */\n\n/** 0 Sunday … 6 Saturday, the same numbering `Date.getDay()` uses. */\nexport type Weekday = 0 | 1 | 2 | 3 | 4 | 5 | 6\n\n/**\n * The weekdays this shift runs on, or `undefined` when it runs every day.\n *\n * Junk is dropped rather than throwing. This value comes from a column that a person can\n * edit and from clients written before the field existed; refusing to read a row because\n * one segment is wrong would take a whole site's calendar down for a typo. What is\n * dropped is a segment, and if every segment is junk the result is `undefined` — which is\n * the pre-existing behaviour, not a made-up restriction.\n */\nexport function readDaysOfWeek(csv?: string | null): Weekday[] | undefined {\n if (!csv || !csv.trim()) {\n return undefined\n }\n\n const days = new Set<Weekday>()\n\n for (const part of csv.split(',')) {\n const n = Number(part.trim())\n\n if (Number.isInteger(n) && n >= 0 && n <= 6) {\n days.add(n as Weekday)\n }\n }\n\n return days.size ? [...days].sort((a, b) => a - b) : undefined\n}\n\n/**\n * The stored form of a weekday list, or `undefined` for every day.\n *\n * Sorted and de-duplicated so that two ways of saying the same thing produce the same\n * string — otherwise a row looks changed when it is not, and the revision history fills\n * with edits nobody made.\n */\nexport function writeDaysOfWeek(days?: readonly number[] | null): string | undefined {\n if (!days?.length) {\n return undefined\n }\n\n const kept = readDaysOfWeek(days.join(','))\n\n return kept?.join(',')\n}\n\n/**\n * Does this shift run on that date?\n *\n * ⚠ The weekday is read in the caller's timezone, because `Date.getDay()` is local. A\n * shift's days are stated against the site's calendar, so the date handed in must already\n * be in the site's time base — the same rule the shift's `HH:MM` already follows\n * (§`withSpaceTimeBase`). Handing in a UTC date for a site that is not on UTC will get\n * the wrong answer near midnight, silently.\n */\nexport function runsOn(csv: string | null | undefined, when: Date): boolean {\n const days = readDaysOfWeek(csv)\n\n return days === undefined || days.includes(when.getDay() as Weekday)\n}\n"]}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { DomainWorkShiftQuery, WorkShiftQuery } from './work-shift-query';
|
|
2
2
|
import { WorkShift } from './work-shift';
|
|
3
3
|
import { WorkShiftMutation } from './work-shift-mutation';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { WorkShiftRevision } from './work-shift-revision';
|
|
5
|
+
import { WorkShiftRevisionQuery } from './work-shift-revision-query';
|
|
6
|
+
export * from './days-of-week';
|
|
7
|
+
export declare const entities: (typeof WorkShift | typeof WorkShiftRevision)[];
|
|
8
|
+
export declare const resolvers: (typeof DomainWorkShiftQuery | typeof WorkShiftQuery | typeof WorkShiftMutation | typeof WorkShiftRevisionQuery)[];
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolvers = exports.entities = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const work_shift_query_1 = require("./work-shift-query");
|
|
5
6
|
const work_shift_1 = require("./work-shift");
|
|
6
7
|
const work_shift_mutation_1 = require("./work-shift-mutation");
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const work_shift_revision_1 = require("./work-shift-revision");
|
|
9
|
+
const work_shift_revision_query_1 = require("./work-shift-revision-query");
|
|
10
|
+
/*
|
|
11
|
+
* The weekday rule is exported so consumers read the column through one parser. It is a CSV
|
|
12
|
+
* because array columns are not portable across the five drivers, and a parser written twice
|
|
13
|
+
* disagrees eventually — quietly, since both halves keep computing (§`days-of-week.ts`).
|
|
14
|
+
*/
|
|
15
|
+
tslib_1.__exportStar(require("./days-of-week"), exports);
|
|
16
|
+
exports.entities = [work_shift_1.WorkShift, work_shift_revision_1.WorkShiftRevision];
|
|
17
|
+
exports.resolvers = [work_shift_query_1.DomainWorkShiftQuery, work_shift_query_1.WorkShiftQuery, work_shift_mutation_1.WorkShiftMutation, work_shift_revision_query_1.WorkShiftRevisionQuery];
|
|
9
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/service/work-shift/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/service/work-shift/index.ts"],"names":[],"mappings":";;;;AAAA,yDAAyE;AAEzE,6CAAwC;AACxC,+DAAyD;AACzD,+DAAyD;AACzD,2EAAoE;AAEpE;;;;GAIG;AACH,yDAA8B;AAEjB,QAAA,QAAQ,GAAG,CAAC,sBAAS,EAAE,uCAAiB,CAAC,CAAA;AACzC,QAAA,SAAS,GAAG,CAAC,uCAAoB,EAAE,iCAAc,EAAE,uCAAiB,EAAE,kDAAsB,CAAC,CAAA","sourcesContent":["import { DomainWorkShiftQuery, WorkShiftQuery } from './work-shift-query'\n\nimport { WorkShift } from './work-shift'\nimport { WorkShiftMutation } from './work-shift-mutation'\nimport { WorkShiftRevision } from './work-shift-revision'\nimport { WorkShiftRevisionQuery } from './work-shift-revision-query'\n\n/*\n * The weekday rule is exported so consumers read the column through one parser. It is a CSV\n * because array columns are not portable across the five drivers, and a parser written twice\n * disagrees eventually — quietly, since both halves keep computing (§`days-of-week.ts`).\n */\nexport * from './days-of-week'\n\nexport const entities = [WorkShift, WorkShiftRevision]\nexport const resolvers = [DomainWorkShiftQuery, WorkShiftQuery, WorkShiftMutation, WorkShiftRevisionQuery]\n"]}
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { WorkShift } from './work-shift';
|
|
2
2
|
import { WorkShiftPatch } from './work-shift-type';
|
|
3
|
+
import { WorkShiftRevision } from './work-shift-revision';
|
|
3
4
|
export declare class WorkShiftMutation {
|
|
4
5
|
updateMultipleWorkShift(patches: WorkShiftPatch[], context: ResolverContext): Promise<WorkShift[]>;
|
|
6
|
+
/**
|
|
7
|
+
* 앞으로 쓸 편성을 미리 적어 둔다 — 「다음 달 1일부터 3교대」.
|
|
8
|
+
*
|
|
9
|
+
* 그날이 오면 **저절로** 그 편성이 답이 된다. 옮기는 일감이 없으므로 그날 서버가 내려가 있어도
|
|
10
|
+
* 편성은 제 시각에 바뀐다.
|
|
11
|
+
*/
|
|
12
|
+
announceWorkShift(effectiveFrom: Date, patches: WorkShiftPatch[], context: ResolverContext): Promise<WorkShiftRevision>;
|
|
13
|
+
/** 예고를 물린다. 아직 시작하지 않은 것만 물릴 수 있다. */
|
|
14
|
+
cancelWorkShiftAnnouncement(id: string, context: ResolverContext): Promise<boolean>;
|
|
5
15
|
deleteWorkShifts(ids: string[], context: ResolverContext): Promise<boolean>;
|
|
6
16
|
}
|
|
@@ -6,11 +6,22 @@ const type_graphql_1 = require("type-graphql");
|
|
|
6
6
|
const typeorm_1 = require("typeorm");
|
|
7
7
|
const work_shift_1 = require("./work-shift");
|
|
8
8
|
const work_shift_type_1 = require("./work-shift-type");
|
|
9
|
+
const work_shift_revision_service_1 = require("./work-shift-revision-service");
|
|
10
|
+
const work_shift_revision_1 = require("./work-shift-revision");
|
|
9
11
|
let WorkShiftMutation = class WorkShiftMutation {
|
|
10
12
|
async updateMultipleWorkShift(patches, context) {
|
|
11
13
|
const { domain, user, tx } = context.state;
|
|
12
14
|
let results = [];
|
|
13
15
|
const workShiftRepo = tx.getRepository(work_shift_1.WorkShift);
|
|
16
|
+
/*
|
|
17
|
+
* 지우기 **전에** 지금 편성을 남긴다.
|
|
18
|
+
*
|
|
19
|
+
* 이 저장은 그 도메인의 교대를 전부 지우고 다시 넣는다. 그래서 오탈자 하나를 고쳐도 이전 편성이
|
|
20
|
+
* 데이터베이스에서 없어졌고, 「6월의 주간은 몇 시부터였나」에 답할 방법이 없었다.
|
|
21
|
+
*
|
|
22
|
+
* 지운 뒤에 남기려 하면 남길 것이 없다. 순서가 이 한 줄의 전부다.
|
|
23
|
+
*/
|
|
24
|
+
await (0, work_shift_revision_service_1.recordRevision)(tx, domain, (0, work_shift_revision_service_1.shiftSetOf)(patches), user);
|
|
14
25
|
await workShiftRepo.delete({ domain: { id: domain.id } });
|
|
15
26
|
for (let i = 0; i < patches.length; i++) {
|
|
16
27
|
const patch = patches[i];
|
|
@@ -24,8 +35,26 @@ let WorkShiftMutation = class WorkShiftMutation {
|
|
|
24
35
|
}
|
|
25
36
|
return results;
|
|
26
37
|
}
|
|
27
|
-
|
|
38
|
+
/**
|
|
39
|
+
* 앞으로 쓸 편성을 미리 적어 둔다 — 「다음 달 1일부터 3교대」.
|
|
40
|
+
*
|
|
41
|
+
* 그날이 오면 **저절로** 그 편성이 답이 된다. 옮기는 일감이 없으므로 그날 서버가 내려가 있어도
|
|
42
|
+
* 편성은 제 시각에 바뀐다.
|
|
43
|
+
*/
|
|
44
|
+
async announceWorkShift(effectiveFrom, patches, context) {
|
|
45
|
+
const { domain, user, tx } = context.state;
|
|
46
|
+
return await (0, work_shift_revision_service_1.announceShiftSet)(tx, domain, effectiveFrom, (0, work_shift_revision_service_1.shiftSetOf)(patches), user);
|
|
47
|
+
}
|
|
48
|
+
/** 예고를 물린다. 아직 시작하지 않은 것만 물릴 수 있다. */
|
|
49
|
+
async cancelWorkShiftAnnouncement(id, context) {
|
|
28
50
|
const { domain, tx } = context.state;
|
|
51
|
+
return await (0, work_shift_revision_service_1.cancelAnnouncement)(tx, domain, id);
|
|
52
|
+
}
|
|
53
|
+
async deleteWorkShifts(ids, context) {
|
|
54
|
+
const { domain, tx, user } = context.state;
|
|
55
|
+
/* 지우는 것도 편성이 바뀌는 것이다. 이 길로 지우면 이력이 안 남던 구멍이 있었다. */
|
|
56
|
+
const remaining = (await tx.getRepository(work_shift_1.WorkShift).find({ where: { domain: { id: domain.id } } })).filter(shift => !ids.includes(shift.id));
|
|
57
|
+
await (0, work_shift_revision_service_1.recordRevision)(tx, domain, (0, work_shift_revision_service_1.shiftSetOf)(remaining), user);
|
|
29
58
|
await tx.getRepository(work_shift_1.WorkShift).delete({
|
|
30
59
|
domain: { id: domain.id },
|
|
31
60
|
id: (0, typeorm_1.In)(ids)
|
|
@@ -44,6 +73,27 @@ tslib_1.__decorate([
|
|
|
44
73
|
tslib_1.__metadata("design:paramtypes", [Array, Object]),
|
|
45
74
|
tslib_1.__metadata("design:returntype", Promise)
|
|
46
75
|
], WorkShiftMutation.prototype, "updateMultipleWorkShift", null);
|
|
76
|
+
tslib_1.__decorate([
|
|
77
|
+
(0, type_graphql_1.Directive)('@privilege(category: "work-shift", privilege: "mutation", domainOwnerGranted: true)'),
|
|
78
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
79
|
+
(0, type_graphql_1.Mutation)(returns => work_shift_revision_1.WorkShiftRevision, { description: 'To announce a work shift arrangement that starts later' }),
|
|
80
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('effectiveFrom')),
|
|
81
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('patches', type => [work_shift_type_1.WorkShiftPatch])),
|
|
82
|
+
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
|
83
|
+
tslib_1.__metadata("design:type", Function),
|
|
84
|
+
tslib_1.__metadata("design:paramtypes", [Date, Array, Object]),
|
|
85
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
86
|
+
], WorkShiftMutation.prototype, "announceWorkShift", null);
|
|
87
|
+
tslib_1.__decorate([
|
|
88
|
+
(0, type_graphql_1.Directive)('@privilege(category: "work-shift", privilege: "mutation", domainOwnerGranted: true)'),
|
|
89
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
90
|
+
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To cancel an announced work shift arrangement' }),
|
|
91
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
92
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
93
|
+
tslib_1.__metadata("design:type", Function),
|
|
94
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
95
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
96
|
+
], WorkShiftMutation.prototype, "cancelWorkShiftAnnouncement", null);
|
|
47
97
|
tslib_1.__decorate([
|
|
48
98
|
(0, type_graphql_1.Directive)('@privilege(category: "work-shift", privilege: "mutation", domainOwnerGranted: true)'),
|
|
49
99
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"work-shift-mutation.js","sourceRoot":"","sources":["../../../server/service/work-shift/work-shift-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,6CAAwC;AACxC,uDAAkD;
|
|
1
|
+
{"version":3,"file":"work-shift-mutation.js","sourceRoot":"","sources":["../../../server/service/work-shift/work-shift-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,6CAAwC;AACxC,uDAAkD;AAClD,+EAKsC;AACtC,+DAAyD;AAGlD,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAItB,AAAN,KAAK,CAAC,uBAAuB,CACe,OAAyB,EAC5D,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,IAAI,OAAO,GAAG,EAAE,CAAA;QAChB,MAAM,aAAa,GAAG,EAAE,CAAC,aAAa,CAAC,sBAAS,CAAC,CAAA;QAEjD;;;;;;;WAOG;QACH,MAAM,IAAA,4CAAc,EAAC,EAAE,EAAE,MAAM,EAAE,IAAA,wCAAU,EAAC,OAAiC,CAAC,EAAE,IAAI,CAAC,CAAA;QAErF,MAAM,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;QAEzD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;YAExB,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC;gBACtC,GAAG,KAAK;gBACR,MAAM;gBACN,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,IAAI;aACd,CAAC,CAAA;YAEF,OAAO,CAAC,IAAI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C,IAAI,CAAC,CAAA;IACT,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;oEAKP;AAKK;IAHL,IAAA,wBAAS,EAAC,qFAAqF,CAAC;IAChG,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,+BAA+B,EAAE,CAAC;IAE5E,mBAAA,IAAA,kBAAG,EAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;yDAiBP;4BA/FU,iBAAiB;IAD7B,IAAA,uBAAQ,EAAC,sBAAS,CAAC;GACP,iBAAiB,CAgG7B","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { WorkShift } from './work-shift'\nimport { WorkShiftPatch } from './work-shift-type'\nimport {\n announceShiftSet,\n cancelAnnouncement,\n recordRevision,\n shiftSetOf\n} from './work-shift-revision-service'\nimport { WorkShiftRevision } from './work-shift-revision'\n\n@Resolver(WorkShift)\nexport class WorkShiftMutation {\n @Directive('@privilege(category: \"work-shift\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => [WorkShift], { description: \"To modify multiple WorkShifts' information\" })\n async updateMultipleWorkShift(\n @Arg('patches', type => [WorkShiftPatch]) patches: WorkShiftPatch[],\n @Ctx() context: ResolverContext\n ): Promise<WorkShift[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const workShiftRepo = tx.getRepository(WorkShift)\n\n /*\n * 지우기 **전에** 지금 편성을 남긴다.\n *\n * 이 저장은 그 도메인의 교대를 전부 지우고 다시 넣는다. 그래서 오탈자 하나를 고쳐도 이전 편성이\n * 데이터베이스에서 없어졌고, 「6월의 주간은 몇 시부터였나」에 답할 방법이 없었다.\n *\n * 지운 뒤에 남기려 하면 남길 것이 없다. 순서가 이 한 줄의 전부다.\n */\n await recordRevision(tx, domain, shiftSetOf(patches as unknown as WorkShift[]), user)\n\n await workShiftRepo.delete({ domain: { id: domain.id } })\n\n for (let i = 0; i < patches.length; i++) {\n const patch = patches[i]\n\n const result = await workShiftRepo.save({\n ...patch,\n domain,\n creator: user,\n updater: user\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n\n return results\n }\n\n /**\n * 앞으로 쓸 편성을 미리 적어 둔다 — 「다음 달 1일부터 3교대」.\n *\n * 그날이 오면 **저절로** 그 편성이 답이 된다. 옮기는 일감이 없으므로 그날 서버가 내려가 있어도\n * 편성은 제 시각에 바뀐다.\n */\n @Directive('@privilege(category: \"work-shift\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => WorkShiftRevision, { description: 'To announce a work shift arrangement that starts later' })\n async announceWorkShift(\n @Arg('effectiveFrom') effectiveFrom: Date,\n @Arg('patches', type => [WorkShiftPatch]) patches: WorkShiftPatch[],\n @Ctx() context: ResolverContext\n ): Promise<WorkShiftRevision> {\n const { domain, user, tx } = context.state\n\n return await announceShiftSet(tx, domain, effectiveFrom, shiftSetOf(patches as unknown as WorkShift[]), user)\n }\n\n /** 예고를 물린다. 아직 시작하지 않은 것만 물릴 수 있다. */\n @Directive('@privilege(category: \"work-shift\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To cancel an announced work shift arrangement' })\n async cancelWorkShiftAnnouncement(\n @Arg('id') id: string,\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n return await cancelAnnouncement(tx, domain, id)\n }\n\n @Directive('@privilege(category: \"work-shift\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete multiple workShifts' })\n async deleteWorkShifts(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx, user } = context.state\n\n /* 지우는 것도 편성이 바뀌는 것이다. 이 길로 지우면 이력이 안 남던 구멍이 있었다. */\n const remaining = (await tx.getRepository(WorkShift).find({ where: { domain: { id: domain.id } } })).filter(\n shift => !ids.includes(shift.id)\n )\n\n await recordRevision(tx, domain, shiftSetOf(remaining), user)\n\n await tx.getRepository(WorkShift).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n return true\n }\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { User } from '@things-factory/auth-base';
|
|
2
|
+
import { Domain, ListParam } from '@things-factory/shell';
|
|
3
|
+
import { WorkShiftRevision } from './work-shift-revision';
|
|
4
|
+
import { WorkShiftRevisionList } from './work-shift-type';
|
|
5
|
+
/**
|
|
6
|
+
* 지나간 편성을 읽는다. **읽기만 있다** — 지나간 것은 고치는 것이 아니다.
|
|
7
|
+
*/
|
|
8
|
+
export declare class WorkShiftRevisionQuery {
|
|
9
|
+
workShiftRevisions(params: ListParam, context: ResolverContext): Promise<WorkShiftRevisionList>;
|
|
10
|
+
/**
|
|
11
|
+
* 편성 한 벌을 **JSON 글자로** 내보낸다.
|
|
12
|
+
*
|
|
13
|
+
* 이 칸은 `simple-json` 이라 값이 배열이다. 스키마에 `String` 으로 적어 두고 배열을 그대로 내보내면
|
|
14
|
+
* GraphQL 이 「String cannot represent value」로 응답을 통째로 버린다 — 화면에서 예고를 넣고 나서야
|
|
15
|
+
* 드러났다. 목록이 비어 있는 동안에는 이 자리를 지나지 않기 때문이다.
|
|
16
|
+
*/
|
|
17
|
+
shifts(revision: WorkShiftRevision): string;
|
|
18
|
+
domain(revision: WorkShiftRevision): Promise<Domain>;
|
|
19
|
+
creator(revision: WorkShiftRevision): Promise<User | null>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkShiftRevisionQuery = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const type_graphql_1 = require("type-graphql");
|
|
6
|
+
const auth_base_1 = require("@things-factory/auth-base");
|
|
7
|
+
const shell_1 = require("@things-factory/shell");
|
|
8
|
+
const work_shift_revision_1 = require("./work-shift-revision");
|
|
9
|
+
const work_shift_type_1 = require("./work-shift-type");
|
|
10
|
+
/**
|
|
11
|
+
* 지나간 편성을 읽는다. **읽기만 있다** — 지나간 것은 고치는 것이 아니다.
|
|
12
|
+
*/
|
|
13
|
+
let WorkShiftRevisionQuery = class WorkShiftRevisionQuery {
|
|
14
|
+
async workShiftRevisions(params, context) {
|
|
15
|
+
const { domain } = context.state;
|
|
16
|
+
const queryBuilder = (0, shell_1.getQueryBuilderFromListParams)({
|
|
17
|
+
repository: (0, shell_1.getRepository)(work_shift_revision_1.WorkShiftRevision),
|
|
18
|
+
params,
|
|
19
|
+
domain
|
|
20
|
+
});
|
|
21
|
+
const [items, total] = await queryBuilder.getManyAndCount();
|
|
22
|
+
return { items, total };
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 편성 한 벌을 **JSON 글자로** 내보낸다.
|
|
26
|
+
*
|
|
27
|
+
* 이 칸은 `simple-json` 이라 값이 배열이다. 스키마에 `String` 으로 적어 두고 배열을 그대로 내보내면
|
|
28
|
+
* GraphQL 이 「String cannot represent value」로 응답을 통째로 버린다 — 화면에서 예고를 넣고 나서야
|
|
29
|
+
* 드러났다. 목록이 비어 있는 동안에는 이 자리를 지나지 않기 때문이다.
|
|
30
|
+
*/
|
|
31
|
+
shifts(revision) {
|
|
32
|
+
return JSON.stringify(revision.shifts ?? []);
|
|
33
|
+
}
|
|
34
|
+
async domain(revision) {
|
|
35
|
+
return await (0, shell_1.getRepository)(shell_1.Domain).findOneBy({ id: revision.domainId });
|
|
36
|
+
}
|
|
37
|
+
async creator(revision) {
|
|
38
|
+
return revision.creatorId ? await (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: revision.creatorId }) : null;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.WorkShiftRevisionQuery = WorkShiftRevisionQuery;
|
|
42
|
+
tslib_1.__decorate([
|
|
43
|
+
(0, type_graphql_1.Query)(returns => work_shift_type_1.WorkShiftRevisionList, { description: 'To fetch work shift arrangements that used to be in force' }),
|
|
44
|
+
tslib_1.__param(0, (0, type_graphql_1.Args)(type => shell_1.ListParam)),
|
|
45
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
46
|
+
tslib_1.__metadata("design:type", Function),
|
|
47
|
+
tslib_1.__metadata("design:paramtypes", [shell_1.ListParam, Object]),
|
|
48
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
49
|
+
], WorkShiftRevisionQuery.prototype, "workShiftRevisions", null);
|
|
50
|
+
tslib_1.__decorate([
|
|
51
|
+
(0, type_graphql_1.FieldResolver)(type => String),
|
|
52
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
53
|
+
tslib_1.__metadata("design:type", Function),
|
|
54
|
+
tslib_1.__metadata("design:paramtypes", [work_shift_revision_1.WorkShiftRevision]),
|
|
55
|
+
tslib_1.__metadata("design:returntype", String)
|
|
56
|
+
], WorkShiftRevisionQuery.prototype, "shifts", null);
|
|
57
|
+
tslib_1.__decorate([
|
|
58
|
+
(0, type_graphql_1.FieldResolver)(type => shell_1.Domain),
|
|
59
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
60
|
+
tslib_1.__metadata("design:type", Function),
|
|
61
|
+
tslib_1.__metadata("design:paramtypes", [work_shift_revision_1.WorkShiftRevision]),
|
|
62
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
63
|
+
], WorkShiftRevisionQuery.prototype, "domain", null);
|
|
64
|
+
tslib_1.__decorate([
|
|
65
|
+
(0, type_graphql_1.FieldResolver)(type => auth_base_1.User, { nullable: true }),
|
|
66
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
67
|
+
tslib_1.__metadata("design:type", Function),
|
|
68
|
+
tslib_1.__metadata("design:paramtypes", [work_shift_revision_1.WorkShiftRevision]),
|
|
69
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
70
|
+
], WorkShiftRevisionQuery.prototype, "creator", null);
|
|
71
|
+
exports.WorkShiftRevisionQuery = WorkShiftRevisionQuery = tslib_1.__decorate([
|
|
72
|
+
(0, type_graphql_1.Resolver)(work_shift_revision_1.WorkShiftRevision)
|
|
73
|
+
], WorkShiftRevisionQuery);
|
|
74
|
+
//# sourceMappingURL=work-shift-revision-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"work-shift-revision-query.js","sourceRoot":"","sources":["../../../server/service/work-shift/work-shift-revision-query.ts"],"names":[],"mappings":";;;;AAAA,+CAA8E;AAE9E,yDAAgD;AAChD,iDAAuG;AAEvG,+DAAyD;AACzD,uDAAyD;AAEzD;;GAEG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAE3B,AAAN,KAAK,CAAC,kBAAkB,CACG,MAAiB,EACnC,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEhC,MAAM,YAAY,GAAG,IAAA,qCAA6B,EAAC;YACjD,UAAU,EAAE,IAAA,qBAAa,EAAC,uCAAiB,CAAC;YAC5C,MAAM;YACN,MAAM;SACP,CAAC,CAAA;QAEF,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,YAAY,CAAC,eAAe,EAAE,CAAA;QAE3D,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;IACzB,CAAC;IAED;;;;;;OAMG;IAEH,MAAM,CAAS,QAA2B;QACxC,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,IAAI,EAAE,CAAC,CAAA;IAC9C,CAAC;IAGK,AAAN,KAAK,CAAC,MAAM,CAAS,QAA2B;QAC9C,OAAO,MAAM,IAAA,qBAAa,EAAC,cAAM,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAA;IACzE,CAAC;IAGK,AAAN,KAAK,CAAC,OAAO,CAAS,QAA2B;QAC/C,OAAO,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,IAAA,qBAAa,EAAC,gBAAI,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IACpG,CAAC;CACF,CAAA;AAxCY,wDAAsB;AAE3B;IADL,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,uCAAqB,EAAE,EAAE,WAAW,EAAE,2DAA2D,EAAE,CAAC;IAEnH,mBAAA,IAAA,mBAAI,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAS,CAAC,CAAA;IACvB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;6CAD2B,iBAAS;;gEAc3C;AAUD;IADC,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC;IACtB,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAW,uCAAiB;;oDAEzC;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,CAAC;IAChB,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAW,uCAAiB;;oDAE/C;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACjC,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAW,uCAAiB;;qDAEhD;iCAvCU,sBAAsB;IADlC,IAAA,uBAAQ,EAAC,uCAAiB,CAAC;GACf,sBAAsB,CAwClC","sourcesContent":["import { 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 { WorkShiftRevision } from './work-shift-revision'\nimport { WorkShiftRevisionList } from './work-shift-type'\n\n/**\n * 지나간 편성을 읽는다. **읽기만 있다** — 지나간 것은 고치는 것이 아니다.\n */\n@Resolver(WorkShiftRevision)\nexport class WorkShiftRevisionQuery {\n @Query(returns => WorkShiftRevisionList, { description: 'To fetch work shift arrangements that used to be in force' })\n async workShiftRevisions(\n @Args(type => ListParam) params: ListParam,\n @Ctx() context: ResolverContext\n ): Promise<WorkShiftRevisionList> {\n const { domain } = context.state\n\n const queryBuilder = getQueryBuilderFromListParams({\n repository: getRepository(WorkShiftRevision),\n params,\n domain\n })\n\n const [items, total] = await queryBuilder.getManyAndCount()\n\n return { items, total }\n }\n\n /**\n * 편성 한 벌을 **JSON 글자로** 내보낸다.\n *\n * 이 칸은 `simple-json` 이라 값이 배열이다. 스키마에 `String` 으로 적어 두고 배열을 그대로 내보내면\n * GraphQL 이 「String cannot represent value」로 응답을 통째로 버린다 — 화면에서 예고를 넣고 나서야\n * 드러났다. 목록이 비어 있는 동안에는 이 자리를 지나지 않기 때문이다.\n */\n @FieldResolver(type => String)\n shifts(@Root() revision: WorkShiftRevision): string {\n return JSON.stringify(revision.shifts ?? [])\n }\n\n @FieldResolver(type => Domain)\n async domain(@Root() revision: WorkShiftRevision): Promise<Domain> {\n return await getRepository(Domain).findOneBy({ id: revision.domainId })\n }\n\n @FieldResolver(type => User, { nullable: true })\n async creator(@Root() revision: WorkShiftRevision): Promise<User | null> {\n return revision.creatorId ? await getRepository(User).findOneBy({ id: revision.creatorId }) : null\n }\n}\n"]}
|