@things-factory/work-shift 5.0.0-alpha.24

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE.md +21 -0
  3. package/client/bootstrap.js +3 -0
  4. package/client/index.js +1 -0
  5. package/client/pages/work-shift.js +95 -0
  6. package/client/route.js +7 -0
  7. package/dist-server/controllers/index.js +53 -0
  8. package/dist-server/controllers/index.js.map +1 -0
  9. package/dist-server/index.js +22 -0
  10. package/dist-server/index.js.map +1 -0
  11. package/dist-server/middlewares/index.js +8 -0
  12. package/dist-server/middlewares/index.js.map +1 -0
  13. package/dist-server/migrations/index.js +12 -0
  14. package/dist-server/migrations/index.js.map +1 -0
  15. package/dist-server/routes.js +25 -0
  16. package/dist-server/routes.js.map +1 -0
  17. package/dist-server/service/index.js +32 -0
  18. package/dist-server/service/index.js.map +1 -0
  19. package/dist-server/service/work-shift/index.js +9 -0
  20. package/dist-server/service/work-shift/index.js.map +1 -0
  21. package/dist-server/service/work-shift/work-shift-mutation.js +66 -0
  22. package/dist-server/service/work-shift/work-shift-mutation.js.map +1 -0
  23. package/dist-server/service/work-shift/work-shift-query.js +110 -0
  24. package/dist-server/service/work-shift/work-shift-query.js.map +1 -0
  25. package/dist-server/service/work-shift/work-shift-type.js +73 -0
  26. package/dist-server/service/work-shift/work-shift-type.js.map +1 -0
  27. package/dist-server/service/work-shift/work-shift.js +117 -0
  28. package/dist-server/service/work-shift/work-shift.js.map +1 -0
  29. package/package.json +32 -0
  30. package/server/controllers/index.ts +69 -0
  31. package/server/index.ts +6 -0
  32. package/server/middlewares/index.ts +3 -0
  33. package/server/migrations/index.ts +9 -0
  34. package/server/routes.ts +28 -0
  35. package/server/service/index.ts +18 -0
  36. package/server/service/work-shift/index.ts +7 -0
  37. package/server/service/work-shift/work-shift-mutation.ts +51 -0
  38. package/server/service/work-shift/work-shift-query.ts +58 -0
  39. package/server/service/work-shift/work-shift-type.ts +41 -0
  40. package/server/service/work-shift/work-shift.ts +96 -0
  41. package/things-factory.config.js +13 -0
  42. package/translations/en.json +3 -0
  43. package/translations/ko.json +3 -0
  44. package/translations/ms.json +3 -0
  45. package/translations/zh.json +3 -0
  46. package/tsconfig.json +9 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6
+ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
+
8
+ <!-- ## [Unreleased] -->
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Hatiolab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ import { store } from '@things-factory/shell'
2
+
3
+ export default function bootstrap() {}
@@ -0,0 +1 @@
1
+ export * from './actions/main'
@@ -0,0 +1,95 @@
1
+ import '@operato/input/ox-input-work-shift.js'
2
+
3
+ import { PageView, store } from '@things-factory/shell'
4
+
5
+ import { CommonButtonStyles } from '@operato/styles'
6
+ import { client } from '@operato/graphql'
7
+ import { connect } from 'pwa-helpers/connect-mixin.js'
8
+ import gql from 'graphql-tag'
9
+ import { html } from 'lit-element'
10
+ import { i18next } from '@operato/i18n'
11
+
12
+ class WorkShift extends connect(store)(PageView) {
13
+ constructor() {
14
+ super()
15
+
16
+ this.workShifts = []
17
+ }
18
+
19
+ static get properties() {
20
+ return {
21
+ workShifts: Object
22
+ }
23
+ }
24
+
25
+ get context() {
26
+ return {
27
+ title: i18next.t('title.work-shift'),
28
+ actions: [
29
+ {
30
+ title: i18next.t('button.update'),
31
+ action: this._updateWorkShift.bind(this),
32
+ ...CommonButtonStyles.update
33
+ }
34
+ ],
35
+ help: 'page/work-shift'
36
+ }
37
+ }
38
+
39
+ render() {
40
+ return html`
41
+ <h2>WorkShift</h2>
42
+ <ox-input-work-shift .value=${this.workShifts}></ox-input-work-shift>
43
+ `
44
+ }
45
+
46
+ async pageUpdated(changes, after, before) {
47
+ /* refresh always page revisited */
48
+ if (this.active) {
49
+ const response = await client.query({
50
+ query: gql`
51
+ query {
52
+ workShifts(sortings: [{ name: "fromDate" }, { name: "fromTime" }]) {
53
+ items {
54
+ name
55
+ fromDate
56
+ fromTime
57
+ toDate
58
+ toTime
59
+ }
60
+ }
61
+ }
62
+ `
63
+ })
64
+
65
+ this.workShifts = response.data.workShifts.items
66
+ }
67
+ }
68
+
69
+ async _updateWorkShift() {
70
+ const input = this.renderRoot.querySelector('ox-input-work-shift')
71
+
72
+ const response = await client.mutate({
73
+ mutation: gql`
74
+ mutation ($patches: [WorkShiftPatch!]!) {
75
+ updateMultipleWorkShift(patches: $patches) {
76
+ name
77
+ fromDate
78
+ fromTime
79
+ toDate
80
+ toTime
81
+ }
82
+ }
83
+ `,
84
+ variables: {
85
+ patches: input.value
86
+ }
87
+ })
88
+
89
+ this.workShifts = response.data.updateMultipleWorkShift
90
+ }
91
+
92
+ stateChanged(state) {}
93
+ }
94
+
95
+ window.customElements.define('work-shift', WorkShift)
@@ -0,0 +1,7 @@
1
+ export default function route(page) {
2
+ switch (page) {
3
+ case 'work-shift':
4
+ import('./pages/work-shift')
5
+ return page
6
+ }
7
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWorkDateAndShift = void 0;
4
+ const work_shift_1 = require("../service/work-shift/work-shift");
5
+ const typeorm_1 = require("typeorm");
6
+ const env_1 = require("@things-factory/env");
7
+ function between(fromDate, fromTime /* hh:mm */, toDate, toTime /* hh:mm */, theDay, dateTime) {
8
+ const convertedFromDate = new Date(theDay.getTime() + fromDate * (24 * 60 * 60 * 1000));
9
+ const convertedToDate = new Date(theDay.getTime() + toDate * (24 * 60 * 60 * 1000));
10
+ const from = new Date(`${convertedFromDate.toISOString().split('T')[0]}T${fromTime}`);
11
+ const to = new Date(`${convertedToDate.toISOString().split('T')[0]}T${toTime}`);
12
+ return dateTime >= from && to > dateTime;
13
+ }
14
+ async function getWorkDateAndShift(domain, dateTime) {
15
+ const givenDate = dateTime.toISOString().split('T')[0];
16
+ /* 1. get work-shift list for the domain */
17
+ const workShifts = await (0, typeorm_1.getRepository)(work_shift_1.WorkShift).find({
18
+ where: {
19
+ domain
20
+ },
21
+ order: {
22
+ fromDate: 'ASC',
23
+ fromTime: 'ASC'
24
+ }
25
+ });
26
+ /* 2. compare given date-time to every work-shift */
27
+ if (workShifts && workShifts.length > 0) {
28
+ const theDay = new Date(givenDate);
29
+ const theDayBefore = new Date(theDay.getTime() - 24 * 60 * 60 * 1000);
30
+ const theDayAfter = new Date(theDay.getTime() + 24 * 60 * 60 * 1000);
31
+ const days = [theDayBefore, theDay, theDayAfter];
32
+ for (let i = 0; i < days.length; i++) {
33
+ const theDay = days[i];
34
+ for (let j = 0; j < workShifts.length; j++) {
35
+ const { name, fromDate, fromTime, toDate, toTime } = workShifts[j];
36
+ if (between(fromDate, fromTime, toDate, toTime, theDay, dateTime)) {
37
+ return {
38
+ workDate: givenDate,
39
+ workShift: name
40
+ };
41
+ }
42
+ }
43
+ }
44
+ env_1.logger.error(new Error('shift not found'));
45
+ }
46
+ /* 3. in case there are no work-shift, just give date and empty shift */
47
+ return {
48
+ workDate: givenDate,
49
+ workShift: ''
50
+ };
51
+ }
52
+ exports.getWorkDateAndShift = getWorkDateAndShift;
53
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/controllers/index.ts"],"names":[],"mappings":";;;AAAA,iEAA+E;AAI/E,qCAAuC;AACvC,6CAA4C;AAE5C,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,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAA;IACnF,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,iBAAiB,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAA;IACrF,MAAM,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,eAAe,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC,CAAA;IAE/E,OAAO,QAAQ,IAAI,IAAI,IAA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AAC,CAAA;gBAElE,IAAI,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE;oBACjE,OAAO;wBACL,QAAQ,EAAE,SAAS;wBACnB,SAAS,EAAE,IAAI;qBAChB,CAAA;iBACF;aACF;SACF;QAED,YAAM,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAA;KAC3C;IAED,wEAAwE;IACxE,OAAO;QACL,QAAQ,EAAE,SAAS;QACnB,SAAS,EAAE,EAAE;KACd,CAAA;AACH,CAAC;AA7CD,kDA6CC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./controllers"), exports);
18
+ __exportStar(require("./migrations"), exports);
19
+ __exportStar(require("./middlewares"), exports);
20
+ __exportStar(require("./service"), exports);
21
+ require("./routes");
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B;AAC7B,+CAA4B;AAC5B,gDAA6B;AAC7B,4CAAyB;AAEzB,oBAAiB"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initMiddlewares = void 0;
4
+ function initMiddlewares(app) {
5
+ /* can add middlewares into app */
6
+ }
7
+ exports.initMiddlewares = initMiddlewares;
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/middlewares/index.ts"],"names":[],"mappings":";;;AAAA,SAAgB,eAAe,CAAC,GAAG;IACjC,kCAAkC;AACpC,CAAC;AAFD,0CAEC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.migrations = void 0;
4
+ const glob = require('glob');
5
+ const path = require('path');
6
+ exports.migrations = [];
7
+ glob.sync(path.resolve(__dirname, '.', '**', '*.js')).forEach(function (file) {
8
+ if (file.indexOf('index.js') !== -1)
9
+ return;
10
+ exports.migrations = exports.migrations.concat(Object.values(require(path.resolve(file))) || []);
11
+ });
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/migrations/index.ts"],"names":[],"mappings":";;;AAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAC5B,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAEjB,QAAA,UAAU,GAAG,EAAE,CAAA;AAE1B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,UAAS,IAAI;IACzE,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAAE,OAAM;IAC3C,kBAAU,GAAG,kBAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;AAClF,CAAC,CAAC,CAAA"}
@@ -0,0 +1,25 @@
1
+ const debug = require('debug')('things-factory:work-shift:routes');
2
+ process.on('bootstrap-module-global-public-route', (app, globalPublicRouter) => {
3
+ /*
4
+ * can add global public routes to application (auth not required, tenancy not required)
5
+ *
6
+ * ex) routes.get('/path', async(context, next) => {})
7
+ * ex) routes.post('/path', async(context, next) => {})
8
+ */
9
+ });
10
+ process.on('bootstrap-module-global-private-route', (app, globalPrivateRouter) => {
11
+ /*
12
+ * can add global private routes to application (auth required, tenancy not required)
13
+ */
14
+ });
15
+ process.on('bootstrap-module-domain-public-route', (app, domainPublicRouter) => {
16
+ /*
17
+ * can add domain public routes to application (auth not required, tenancy required)
18
+ */
19
+ });
20
+ process.on('bootstrap-module-domain-private-route', (app, domainPrivateRouter) => {
21
+ /*
22
+ * can add domain private routes to application (auth required, tenancy required)
23
+ */
24
+ });
25
+ //# sourceMappingURL=routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,kCAAkC,CAAC,CAAA;AAElE,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAE;IACpF;;;;;OAKG;AACL,CAAC,CAAC,CAAA;AAEF,OAAO,CAAC,EAAE,CAAC,uCAA8C,EAAE,CAAC,GAAG,EAAE,mBAAmB,EAAE,EAAE;IACtF;;OAEG;AACL,CAAC,CAAC,CAAA;AAEF,OAAO,CAAC,EAAE,CAAC,sCAA6C,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAE;IACpF;;OAEG;AACL,CAAC,CAAC,CAAA;AAEF,OAAO,CAAC,EAAE,CAAC,uCAA8C,EAAE,CAAC,GAAG,EAAE,mBAAmB,EAAE,EAAE;IACtF;;OAEG;AACL,CAAC,CAAC,CAAA"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.schema = exports.entities = void 0;
18
+ /* EXPORT ENTITY TYPES */
19
+ __exportStar(require("./work-shift/work-shift"), exports);
20
+ /* IMPORT ENTITIES AND RESOLVERS */
21
+ const work_shift_1 = require("./work-shift");
22
+ exports.entities = [
23
+ /* ENTITIES */
24
+ ...work_shift_1.entities,
25
+ ];
26
+ exports.schema = {
27
+ resolverClasses: [
28
+ /* RESOLVER CLASSES */
29
+ ...work_shift_1.resolvers,
30
+ ]
31
+ };
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/service/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yBAAyB;AACzB,0DAAuC;AAEvC,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"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolvers = exports.entities = void 0;
4
+ const work_shift_query_1 = require("./work-shift-query");
5
+ const work_shift_1 = require("./work-shift");
6
+ const work_shift_mutation_1 = require("./work-shift-mutation");
7
+ exports.entities = [work_shift_1.WorkShift];
8
+ exports.resolvers = [work_shift_query_1.DomainWorkShiftQuery, work_shift_query_1.WorkShiftQuery, work_shift_mutation_1.WorkShiftMutation];
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/service/work-shift/index.ts"],"names":[],"mappings":";;;AAAA,yDAAyE;AAEzE,6CAAwC;AACxC,+DAAyD;AAE5C,QAAA,QAAQ,GAAG,CAAC,sBAAS,CAAC,CAAA;AACtB,QAAA,SAAS,GAAG,CAAC,uCAAoB,EAAE,iCAAc,EAAE,uCAAiB,CAAC,CAAA"}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.WorkShiftMutation = void 0;
16
+ const type_graphql_1 = require("type-graphql");
17
+ const typeorm_1 = require("typeorm");
18
+ const work_shift_1 = require("./work-shift");
19
+ const work_shift_type_1 = require("./work-shift-type");
20
+ let WorkShiftMutation = class WorkShiftMutation {
21
+ async updateMultipleWorkShift(patches, context) {
22
+ const { domain, user, tx } = context.state;
23
+ let results = [];
24
+ const workShiftRepo = tx.getRepository(work_shift_1.WorkShift);
25
+ await workShiftRepo.delete({ domain });
26
+ for (let i = 0; i < patches.length; i++) {
27
+ const patch = patches[i];
28
+ const result = await workShiftRepo.save(Object.assign(Object.assign({}, patch), { domain, creator: user, updater: user }));
29
+ results.push(Object.assign(Object.assign({}, result), { cuFlag: '+' }));
30
+ }
31
+ return results;
32
+ }
33
+ async deleteWorkShifts(ids, context) {
34
+ const { domain, tx } = context.state;
35
+ await tx.getRepository(work_shift_1.WorkShift).delete({
36
+ domain,
37
+ id: (0, typeorm_1.In)(ids)
38
+ });
39
+ return true;
40
+ }
41
+ };
42
+ __decorate([
43
+ (0, type_graphql_1.Directive)('@privilege(category: "system", privilege: "mutation", domainOwnerGranted: true)'),
44
+ (0, type_graphql_1.Directive)('@transaction'),
45
+ (0, type_graphql_1.Mutation)(returns => [work_shift_1.WorkShift], { description: "To modify multiple WorkShifts' information" }),
46
+ __param(0, (0, type_graphql_1.Arg)('patches', type => [work_shift_type_1.WorkShiftPatch])),
47
+ __param(1, (0, type_graphql_1.Ctx)()),
48
+ __metadata("design:type", Function),
49
+ __metadata("design:paramtypes", [Array, Object]),
50
+ __metadata("design:returntype", Promise)
51
+ ], WorkShiftMutation.prototype, "updateMultipleWorkShift", null);
52
+ __decorate([
53
+ (0, type_graphql_1.Directive)('@privilege(category: "system", privilege: "mutation", domainOwnerGranted: true)'),
54
+ (0, type_graphql_1.Directive)('@transaction'),
55
+ (0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To delete multiple workShifts' }),
56
+ __param(0, (0, type_graphql_1.Arg)('ids', type => [String])),
57
+ __param(1, (0, type_graphql_1.Ctx)()),
58
+ __metadata("design:type", Function),
59
+ __metadata("design:paramtypes", [Array, Object]),
60
+ __metadata("design:returntype", Promise)
61
+ ], WorkShiftMutation.prototype, "deleteWorkShifts", null);
62
+ WorkShiftMutation = __decorate([
63
+ (0, type_graphql_1.Resolver)(work_shift_1.WorkShift)
64
+ ], WorkShiftMutation);
65
+ exports.WorkShiftMutation = WorkShiftMutation;
66
+ //# sourceMappingURL=work-shift-mutation.js.map
@@ -0,0 +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;AAC5B,6CAAwC;AACxC,uDAAkD;AAGlD,IAAa,iBAAiB,GAA9B,MAAa,iBAAiB;IAI5B,KAAK,CAAC,uBAAuB,CACe,OAAyB,EAC5D,OAAY;QAEnB,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,MAAM,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;QAEtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACvC,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;YAExB,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,IAAI,iCAClC,KAAK,KACR,MAAM,EACN,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,IAAI,IACb,CAAA;YAEF,OAAO,CAAC,IAAI,iCAAM,MAAM,KAAE,MAAM,EAAE,GAAG,IAAG,CAAA;SACzC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;IAKD,KAAK,CAAC,gBAAgB,CAA+B,GAAa,EAAS,OAAY;QACrF,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEpC,MAAM,EAAE,CAAC,aAAa,CAAC,sBAAS,CAAC,CAAC,MAAM,CAAC;YACvC,MAAM;YACN,EAAE,EAAE,IAAA,YAAE,EAAC,GAAG,CAAC;SACZ,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC;CACF,CAAA;AAxCC;IAHC,IAAA,wBAAS,EAAC,iFAAiF,CAAC;IAC5F,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,CAAC,sBAAS,CAAC,EAAE,EAAE,WAAW,EAAE,4CAA4C,EAAE,CAAC;IAE7F,WAAA,IAAA,kBAAG,EAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,gCAAc,CAAC,CAAC,CAAA;IACxC,WAAA,IAAA,kBAAG,GAAE,CAAA;;;;gEAuBP;AAKD;IAHC,IAAA,wBAAS,EAAC,iFAAiF,CAAC;IAC5F,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,+BAA+B,EAAE,CAAC;IACvD,WAAA,IAAA,kBAAG,EAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAAiB,WAAA,IAAA,kBAAG,GAAE,CAAA;;;;yDASzE;AA3CU,iBAAiB;IAD7B,IAAA,uBAAQ,EAAC,sBAAS,CAAC;GACP,iBAAiB,CA4C7B;AA5CY,8CAAiB"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var _a, _b;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.WorkShiftQuery = exports.DomainWorkShiftQuery = void 0;
17
+ const type_graphql_1 = require("type-graphql");
18
+ const typeorm_1 = require("typeorm");
19
+ const shell_1 = require("@things-factory/shell");
20
+ const auth_base_1 = require("@things-factory/auth-base");
21
+ const work_shift_1 = require("./work-shift");
22
+ const work_shift_type_1 = require("./work-shift-type");
23
+ const index_1 = require("../../controllers/index");
24
+ let DomainWorkShiftQuery = class DomainWorkShiftQuery {
25
+ async getWorkDateAndShift(dateTime, context) {
26
+ const { domain } = context.state;
27
+ return await (0, index_1.getWorkDateAndShift)(domain, dateTime);
28
+ }
29
+ async workShifts(domain) {
30
+ return await (0, typeorm_1.getRepository)(work_shift_1.WorkShift).find({
31
+ where: {
32
+ domain
33
+ },
34
+ order: {
35
+ fromDate: 'ASC',
36
+ fromTime: 'ASC'
37
+ }
38
+ });
39
+ }
40
+ };
41
+ __decorate([
42
+ (0, type_graphql_1.Query)(returns => work_shift_type_1.WorkDateWorkShiftPair, { description: 'To fetch a work date and work shift for given datetime' }),
43
+ __param(0, (0, type_graphql_1.Arg)('dateTime')),
44
+ __param(1, (0, type_graphql_1.Ctx)()),
45
+ __metadata("design:type", Function),
46
+ __metadata("design:paramtypes", [Date, Object]),
47
+ __metadata("design:returntype", Promise)
48
+ ], DomainWorkShiftQuery.prototype, "getWorkDateAndShift", null);
49
+ __decorate([
50
+ (0, type_graphql_1.FieldResolver)(type => [work_shift_1.WorkShift]),
51
+ __param(0, (0, type_graphql_1.Root)()),
52
+ __metadata("design:type", Function),
53
+ __metadata("design:paramtypes", [typeof (_a = typeof shell_1.Domain !== "undefined" && shell_1.Domain) === "function" ? _a : Object]),
54
+ __metadata("design:returntype", Promise)
55
+ ], DomainWorkShiftQuery.prototype, "workShifts", null);
56
+ DomainWorkShiftQuery = __decorate([
57
+ (0, type_graphql_1.Resolver)(shell_1.Domain)
58
+ ], DomainWorkShiftQuery);
59
+ exports.DomainWorkShiftQuery = DomainWorkShiftQuery;
60
+ let WorkShiftQuery = class WorkShiftQuery {
61
+ async workShifts(params, context) {
62
+ const { domain } = context.state;
63
+ const convertedParams = (0, shell_1.convertListParams)(params, domain.id);
64
+ const [items, total] = await (0, typeorm_1.getRepository)(work_shift_1.WorkShift).findAndCount(convertedParams);
65
+ return { items, total };
66
+ }
67
+ async domain(workShift) {
68
+ return await (0, typeorm_1.getRepository)(shell_1.Domain).findOne(workShift.domainId);
69
+ }
70
+ async updater(workShift) {
71
+ return await (0, typeorm_1.getRepository)(auth_base_1.User).findOne(workShift.updaterId);
72
+ }
73
+ async creator(workShift) {
74
+ return await (0, typeorm_1.getRepository)(auth_base_1.User).findOne(workShift.creatorId);
75
+ }
76
+ };
77
+ __decorate([
78
+ (0, type_graphql_1.Query)(returns => work_shift_type_1.WorkShiftList, { description: 'To fetch multiple WorkShifts' }),
79
+ __param(0, (0, type_graphql_1.Args)()),
80
+ __param(1, (0, type_graphql_1.Ctx)()),
81
+ __metadata("design:type", Function),
82
+ __metadata("design:paramtypes", [typeof (_b = typeof shell_1.ListParam !== "undefined" && shell_1.ListParam) === "function" ? _b : Object, Object]),
83
+ __metadata("design:returntype", Promise)
84
+ ], WorkShiftQuery.prototype, "workShifts", null);
85
+ __decorate([
86
+ (0, type_graphql_1.FieldResolver)(type => shell_1.Domain),
87
+ __param(0, (0, type_graphql_1.Root)()),
88
+ __metadata("design:type", Function),
89
+ __metadata("design:paramtypes", [work_shift_1.WorkShift]),
90
+ __metadata("design:returntype", Promise)
91
+ ], WorkShiftQuery.prototype, "domain", null);
92
+ __decorate([
93
+ (0, type_graphql_1.FieldResolver)(type => auth_base_1.User),
94
+ __param(0, (0, type_graphql_1.Root)()),
95
+ __metadata("design:type", Function),
96
+ __metadata("design:paramtypes", [work_shift_1.WorkShift]),
97
+ __metadata("design:returntype", Promise)
98
+ ], WorkShiftQuery.prototype, "updater", null);
99
+ __decorate([
100
+ (0, type_graphql_1.FieldResolver)(type => auth_base_1.User),
101
+ __param(0, (0, type_graphql_1.Root)()),
102
+ __metadata("design:type", Function),
103
+ __metadata("design:paramtypes", [work_shift_1.WorkShift]),
104
+ __metadata("design:returntype", Promise)
105
+ ], WorkShiftQuery.prototype, "creator", null);
106
+ WorkShiftQuery = __decorate([
107
+ (0, type_graphql_1.Resolver)(work_shift_1.WorkShift)
108
+ ], WorkShiftQuery);
109
+ exports.WorkShiftQuery = WorkShiftQuery;
110
+ //# sourceMappingURL=work-shift-query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"work-shift-query.js","sourceRoot":"","sources":["../../../server/service/work-shift/work-shift-query.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA8F;AAC9F,qCAAuC;AACvC,iDAA4E;AAC5E,yDAAgD;AAChD,6CAAwC;AACxC,uDAAwE;AACxE,mDAA6D;AAG7D,IAAa,oBAAoB,GAAjC,MAAa,oBAAoB;IAE/B,KAAK,CAAC,mBAAmB,CAAkB,QAAc,EAAS,OAAY;QAC5E,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEhC,OAAO,MAAM,IAAA,2BAAmB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IACpD,CAAC;IAGD,KAAK,CAAC,UAAU,CAAS,MAAc;QACrC,OAAO,MAAM,IAAA,uBAAa,EAAC,sBAAS,CAAC,CAAC,IAAI,CAAC;YACzC,KAAK,EAAE;gBACL,MAAM;aACP;YACD,KAAK,EAAE;gBACL,QAAQ,EAAE,KAAK;gBACf,QAAQ,EAAE,KAAK;aA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IAGD,KAAK,CAAC,OAAO,CAAS,SAAoB;QACxC,OAAO,MAAM,IAAA,uBAAa,EAAC,gBAAI,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;IAC/D,CAAC;CACF,CAAA;AAvBC;IADC,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,+BAAa,EAAE,EAAE,WAAW,EAAE,8BAA8B,EAAE,CAAC;IAC/D,WAAA,IAAA,mBAAI,GAAE,CAAA;IAAqB,WAAA,IAAA,kBAAG,GAAE,CAAA;;yDAAjB,iBAAS,oBAAT,iBAAS;;gDAOzC;AAGD;IADC,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,CAAC;IAChB,WAAA,IAAA,mBAAI,GAAE,CAAA;;qCAAY,sBAAS;;4CAExC;AAGD;IADC,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,CAAC;IACb,WAAA,IAAA,mBAAI,GAAE,CAAA;;qCAAY,sBAAS;;6CAEzC;AAGD;IADC,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,CAAC;IACb,WAAA,IAAA,mBAAI,GAAE,CAAA;;qCAAY,sBAAS;;6CAEzC;AAxBU,cAAc;IAD1B,IAAA,uBAAQ,EAAC,sBAAS,CAAC;GACP,cAAc,CAyB1B;AAzBY,wCAAc"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.WorkDateWorkShiftPair = exports.WorkShiftList = exports.WorkShiftPatch = void 0;
13
+ const type_graphql_1 = require("type-graphql");
14
+ const work_shift_1 = require("./work-shift");
15
+ let WorkShiftPatch = class WorkShiftPatch {
16
+ };
17
+ __decorate([
18
+ (0, type_graphql_1.Field)(),
19
+ __metadata("design:type", String)
20
+ ], WorkShiftPatch.prototype, "name", void 0);
21
+ __decorate([
22
+ (0, type_graphql_1.Field)({ nullable: true }),
23
+ __metadata("design:type", String)
24
+ ], WorkShiftPatch.prototype, "description", void 0);
25
+ __decorate([
26
+ (0, type_graphql_1.Field)(),
27
+ __metadata("design:type", Number)
28
+ ], WorkShiftPatch.prototype, "fromDate", void 0);
29
+ __decorate([
30
+ (0, type_graphql_1.Field)(),
31
+ __metadata("design:type", String)
32
+ ], WorkShiftPatch.prototype, "fromTime", void 0);
33
+ __decorate([
34
+ (0, type_graphql_1.Field)(),
35
+ __metadata("design:type", Number)
36
+ ], WorkShiftPatch.prototype, "toDate", void 0);
37
+ __decorate([
38
+ (0, type_graphql_1.Field)(),
39
+ __metadata("design:type", String)
40
+ ], WorkShiftPatch.prototype, "toTime", void 0);
41
+ WorkShiftPatch = __decorate([
42
+ (0, type_graphql_1.InputType)()
43
+ ], WorkShiftPatch);
44
+ exports.WorkShiftPatch = WorkShiftPatch;
45
+ let WorkShiftList = class WorkShiftList {
46
+ };
47
+ __decorate([
48
+ (0, type_graphql_1.Field)(type => [work_shift_1.WorkShift]),
49
+ __metadata("design:type", Array)
50
+ ], WorkShiftList.prototype, "items", void 0);
51
+ __decorate([
52
+ (0, type_graphql_1.Field)(type => type_graphql_1.Int),
53
+ __metadata("design:type", Number)
54
+ ], WorkShiftList.prototype, "total", void 0);
55
+ WorkShiftList = __decorate([
56
+ (0, type_graphql_1.ObjectType)()
57
+ ], WorkShiftList);
58
+ exports.WorkShiftList = WorkShiftList;
59
+ let WorkDateWorkShiftPair = class WorkDateWorkShiftPair {
60
+ };
61
+ __decorate([
62
+ (0, type_graphql_1.Field)(),
63
+ __metadata("design:type", String)
64
+ ], WorkDateWorkShiftPair.prototype, "workDate", void 0);
65
+ __decorate([
66
+ (0, type_graphql_1.Field)(),
67
+ __metadata("design:type", String)
68
+ ], WorkDateWorkShiftPair.prototype, "workShift", void 0);
69
+ WorkDateWorkShiftPair = __decorate([
70
+ (0, type_graphql_1.ObjectType)()
71
+ ], WorkDateWorkShiftPair);
72
+ exports.WorkDateWorkShiftPair = WorkDateWorkShiftPair;
73
+ //# sourceMappingURL=work-shift-type.js.map
@@ -0,0 +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;AAG3D,IAAa,cAAc,GAA3B,MAAa,cAAc;CAkB1B,CAAA;AAhBC;IADC,IAAA,oBAAK,GAAE;;4CACI;AAGZ;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;mDACN;AAGpB;IADC,IAAA,oBAAK,GAAE;;gDACmB;AAG3B;IADC,IAAA,oBAAK,GAAE;;gDACQ;AAGhB;IADC,IAAA,oBAAK,GAAE;;8CACiB;AAGzB;IADC,IAAA,oBAAK,GAAE;;8CACM;AAjBH,cAAc;IAD1B,IAAA,wBAAS,GAAE;GACC,cAAc,CAkB1B;AAlBY,wCAAc;AAqB3B,IAAa,aAAa,GAA1B,MAAa,aAAa;CAMzB,CAAA;AAJC;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,sBAAS,CAAC,CAAC;;4CACT;AAGlB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,CAAC;;4CACN;AALF,aAAa;IADzB,IAAA,yBAAU,GAAE;GACA,aAAa,CAMzB;AANY,sCAAa;AAS1B,IAAa,qBAAqB,GAAlC,MAAa,qBAAqB;CAMjC,CAAA;AAJC;IADC,IAAA,oBAAK,GAAE;;uDACQ;AAGhB;IADC,IAAA,oBAAK,GAAE;;wDACS;AALN,qBAAqB;IADjC,IAAA,yBAAU,GAAE;GACA,qBAAqB,CAMjC;AANY,sDAAqB"}
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var _a, _b, _c;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.WorkShift = exports.WorkShiftDateType = void 0;
14
+ const typeorm_1 = require("typeorm");
15
+ const type_graphql_1 = require("type-graphql");
16
+ const shell_1 = require("@things-factory/shell");
17
+ const auth_base_1 = require("@things-factory/auth-base");
18
+ var WorkShiftDateType;
19
+ (function (WorkShiftDateType) {
20
+ WorkShiftDateType[WorkShiftDateType["TheDayBefore"] = -1] = "TheDayBefore";
21
+ WorkShiftDateType[WorkShiftDateType["TheDay"] = 0] = "TheDay";
22
+ WorkShiftDateType[WorkShiftDateType["TheDayAfter"] = 1] = "TheDayAfter";
23
+ })(WorkShiftDateType = exports.WorkShiftDateType || (exports.WorkShiftDateType = {}));
24
+ (0, type_graphql_1.registerEnumType)(WorkShiftDateType, {
25
+ name: 'WorkShiftDateType',
26
+ description: 'enumeration of a shift date'
27
+ });
28
+ let WorkShift = class WorkShift {
29
+ };
30
+ __decorate([
31
+ (0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
32
+ (0, type_graphql_1.Field)(type => type_graphql_1.ID),
33
+ __metadata("design:type", String)
34
+ ], WorkShift.prototype, "id", void 0);
35
+ __decorate([
36
+ (0, typeorm_1.ManyToOne)(type => shell_1.Domain),
37
+ (0, type_graphql_1.Field)({ nullable: true }),
38
+ __metadata("design:type", typeof (_a = typeof shell_1.Domain !== "undefined" && shell_1.Domain) === "function" ? _a : Object)
39
+ ], WorkShift.prototype, "domain", void 0);
40
+ __decorate([
41
+ (0, typeorm_1.RelationId)((workShift) => workShift.domain),
42
+ __metadata("design:type", String)
43
+ ], WorkShift.prototype, "domainId", void 0);
44
+ __decorate([
45
+ (0, typeorm_1.Column)(),
46
+ (0, type_graphql_1.Field)(),
47
+ __metadata("design:type", String)
48
+ ], WorkShift.prototype, "name", void 0);
49
+ __decorate([
50
+ (0, typeorm_1.Column)({
51
+ nullable: true
52
+ }),
53
+ (0, type_graphql_1.Field)({ nullable: true }),
54
+ __metadata("design:type", String)
55
+ ], WorkShift.prototype, "description", void 0);
56
+ __decorate([
57
+ (0, typeorm_1.Column)(),
58
+ (0, type_graphql_1.Field)({ nullable: true }),
59
+ __metadata("design:type", Number)
60
+ ], WorkShift.prototype, "fromDate", void 0);
61
+ __decorate([
62
+ (0, typeorm_1.Column)(),
63
+ (0, type_graphql_1.Field)({ nullable: true }),
64
+ __metadata("design:type", String)
65
+ ], WorkShift.prototype, "fromTime", void 0);
66
+ __decorate([
67
+ (0, typeorm_1.Column)(),
68
+ (0, type_graphql_1.Field)({ nullable: true }),
69
+ __metadata("design:type", Number)
70
+ ], WorkShift.prototype, "toDate", void 0);
71
+ __decorate([
72
+ (0, typeorm_1.Column)(),
73
+ (0, type_graphql_1.Field)({ nullable: true }),
74
+ __metadata("design:type", String)
75
+ ], WorkShift.prototype, "toTime", void 0);
76
+ __decorate([
77
+ (0, typeorm_1.CreateDateColumn)(),
78
+ (0, type_graphql_1.Field)({ nullable: true }),
79
+ __metadata("design:type", Date)
80
+ ], WorkShift.prototype, "createdAt", void 0);
81
+ __decorate([
82
+ (0, typeorm_1.UpdateDateColumn)(),
83
+ (0, type_graphql_1.Field)({ nullable: true }),
84
+ __metadata("design:type", Date)
85
+ ], WorkShift.prototype, "updatedAt", void 0);
86
+ __decorate([
87
+ (0, typeorm_1.ManyToOne)(type => auth_base_1.User, {
88
+ nullable: true
89
+ }),
90
+ (0, type_graphql_1.Field)({ nullable: true }),
91
+ __metadata("design:type", typeof (_b = typeof auth_base_1.User !== "undefined" && auth_base_1.User) === "function" ? _b : Object)
92
+ ], WorkShift.prototype, "creator", void 0);
93
+ __decorate([
94
+ (0, typeorm_1.RelationId)((workShift) => workShift.creator),
95
+ __metadata("design:type", String)
96
+ ], WorkShift.prototype, "creatorId", void 0);
97
+ __decorate([
98
+ (0, typeorm_1.ManyToOne)(type => auth_base_1.User, {
99
+ nullable: true
100
+ }),
101
+ (0, type_graphql_1.Field)({ nullable: true }),
102
+ __metadata("design:type", typeof (_c = typeof auth_base_1.User !== "undefined" && auth_base_1.User) === "function" ? _c : Object)
103
+ ], WorkShift.prototype, "updater", void 0);
104
+ __decorate([
105
+ (0, typeorm_1.RelationId)((workShift) => workShift.creator),
106
+ __metadata("design:type", String)
107
+ ], WorkShift.prototype, "updaterId", void 0);
108
+ WorkShift = __decorate([
109
+ (0, typeorm_1.Entity)(),
110
+ (0, typeorm_1.Index)('ix_work_shift_0', (workShift) => [workShift.domain, workShift.name], { unique: true }),
111
+ (0, typeorm_1.Index)('ix_work_shift_1', (workShift) => [workShift.domain, workShift.fromDate, workShift.fromTime], {
112
+ unique: true
113
+ }),
114
+ (0, type_graphql_1.ObjectType)({ description: 'Entity for WorkShift' })
115
+ ], WorkShift);
116
+ exports.WorkShift = WorkShift;
117
+ //# sourceMappingURL=work-shift.js.map
@@ -0,0 +1 @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AM,EAAE,IAAI,EAAE,CAAC;IACxG,IAAA,eAAK,EAAC,iBAAiB,EAAE,CAAC,SAAoB,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,QAAQ,CAAC,EAAE;QAC9G,MAAM,EAAE,IAAI;KACb,CAAC;IACD,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,sBAAsB,EAAE,CAAC;GACvC,SAAS,CA+DrB;AA/DY,8BAAS"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@things-factory/work-shift",
3
+ "version": "5.0.0-alpha.24",
4
+ "main": "dist-server/index.js",
5
+ "browser": "client/index.js",
6
+ "things-factory": true,
7
+ "license": "MIT",
8
+ "author": "heartyoh",
9
+ "description": "Module to handle work shift",
10
+ "publishConfig": {
11
+ "access": "public",
12
+ "@things-factory:registry": "https://registry.npmjs.org"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/hatiolab/things-factory.git",
17
+ "directory": "packages/work-shift"
18
+ },
19
+ "scripts": {
20
+ "build": "tsc --p tsconfig.json",
21
+ "build:server": "npm run clean:server && tsc",
22
+ "clean:server": "rm -rf dist-server",
23
+ "clean": "npm run clean:server",
24
+ "migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
25
+ },
26
+ "dependencies": {
27
+ "@things-factory/auth-base": "^5.0.0-alpha.24",
28
+ "@things-factory/env": "^5.0.0-alpha.24",
29
+ "@things-factory/shell": "^5.0.0-alpha.24"
30
+ },
31
+ "gitHead": "077d90d32fa548afd4925ce07f8f7f27c6b3399a"
32
+ }
@@ -0,0 +1,69 @@
1
+ import { WorkShift, WorkShiftDateType } from '../service/work-shift/work-shift'
2
+
3
+ import { Domain } from '@things-factory/shell'
4
+ import { WorkDateWorkShiftPair } from 'server/service/work-shift/work-shift-type'
5
+ import { getRepository } from 'typeorm'
6
+ import { logger } from '@things-factory/env'
7
+
8
+ function between(
9
+ fromDate: WorkShiftDateType,
10
+ fromTime: string /* hh:mm */,
11
+ toDate: WorkShiftDateType,
12
+ toTime: string /* hh:mm */,
13
+ theDay: Date,
14
+ dateTime: Date
15
+ ): boolean {
16
+ const convertedFromDate = new Date(theDay.getTime() + fromDate * (24 * 60 * 60 * 1000))
17
+ const convertedToDate = new Date(theDay.getTime() + toDate * (24 * 60 * 60 * 1000))
18
+ const from = new Date(`${convertedFromDate.toISOString().split('T')[0]}T${fromTime}`)
19
+ const to = new Date(`${convertedToDate.toISOString().split('T')[0]}T${toTime}`)
20
+
21
+ return dateTime >= from && to > dateTime
22
+ }
23
+
24
+ export async function getWorkDateAndShift(domain: Domain, dateTime: Date): Promise<WorkDateWorkShiftPair> {
25
+ const givenDate = dateTime.toISOString().split('T')[0]
26
+
27
+ /* 1. get work-shift list for the domain */
28
+ const workShifts = await getRepository(WorkShift).find({
29
+ where: {
30
+ domain
31
+ },
32
+ order: {
33
+ fromDate: 'ASC',
34
+ fromTime: 'ASC'
35
+ }
36
+ })
37
+
38
+ /* 2. compare given date-time to every work-shift */
39
+ if (workShifts && workShifts.length > 0) {
40
+ const theDay = new Date(givenDate)
41
+ const theDayBefore = new Date(theDay.getTime() - 24 * 60 * 60 * 1000)
42
+ const theDayAfter = new Date(theDay.getTime() + 24 * 60 * 60 * 1000)
43
+
44
+ const days = [theDayBefore, theDay, theDayAfter]
45
+
46
+ for (let i = 0; i < days.length; i++) {
47
+ const theDay = days[i]
48
+
49
+ for (let j = 0; j < workShifts.length; j++) {
50
+ const { name, fromDate, fromTime, toDate, toTime } = workShifts[j]
51
+
52
+ if (between(fromDate, fromTime, toDate, toTime, theDay, dateTime)) {
53
+ return {
54
+ workDate: givenDate,
55
+ workShift: name
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ logger.error(new Error('shift not found'))
62
+ }
63
+
64
+ /* 3. in case there are no work-shift, just give date and empty shift */
65
+ return {
66
+ workDate: givenDate,
67
+ workShift: ''
68
+ }
69
+ }
@@ -0,0 +1,6 @@
1
+ export * from './controllers'
2
+ export * from './migrations'
3
+ export * from './middlewares'
4
+ export * from './service'
5
+
6
+ import './routes'
@@ -0,0 +1,3 @@
1
+ export function initMiddlewares(app) {
2
+ /* can add middlewares into app */
3
+ }
@@ -0,0 +1,9 @@
1
+ const glob = require('glob')
2
+ const path = require('path')
3
+
4
+ export var migrations = []
5
+
6
+ glob.sync(path.resolve(__dirname, '.', '**', '*.js')).forEach(function(file) {
7
+ if (file.indexOf('index.js') !== -1) return
8
+ migrations = migrations.concat(Object.values(require(path.resolve(file))) || [])
9
+ })
@@ -0,0 +1,28 @@
1
+ const debug = require('debug')('things-factory:work-shift:routes')
2
+
3
+ process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
4
+ /*
5
+ * can add global public routes to application (auth not required, tenancy not required)
6
+ *
7
+ * ex) routes.get('/path', async(context, next) => {})
8
+ * ex) routes.post('/path', async(context, next) => {})
9
+ */
10
+ })
11
+
12
+ process.on('bootstrap-module-global-private-route' as any, (app, globalPrivateRouter) => {
13
+ /*
14
+ * can add global private routes to application (auth required, tenancy not required)
15
+ */
16
+ })
17
+
18
+ process.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {
19
+ /*
20
+ * can add domain public routes to application (auth not required, tenancy required)
21
+ */
22
+ })
23
+
24
+ process.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {
25
+ /*
26
+ * can add domain private routes to application (auth required, tenancy required)
27
+ */
28
+ })
@@ -0,0 +1,18 @@
1
+ /* EXPORT ENTITY TYPES */
2
+ export * from './work-shift/work-shift'
3
+
4
+ /* IMPORT ENTITIES AND RESOLVERS */
5
+ import { entities as WorkShiftEntities, resolvers as WorkShiftResolvers } from './work-shift'
6
+
7
+ export const entities = [
8
+ /* ENTITIES */
9
+ ...WorkShiftEntities,
10
+ ]
11
+
12
+
13
+ export const schema = {
14
+ resolverClasses: [
15
+ /* RESOLVER CLASSES */
16
+ ...WorkShiftResolvers,
17
+ ]
18
+ }
@@ -0,0 +1,7 @@
1
+ import { DomainWorkShiftQuery, WorkShiftQuery } from './work-shift-query'
2
+
3
+ import { WorkShift } from './work-shift'
4
+ import { WorkShiftMutation } from './work-shift-mutation'
5
+
6
+ export const entities = [WorkShift]
7
+ export const resolvers = [DomainWorkShiftQuery, WorkShiftQuery, WorkShiftMutation]
@@ -0,0 +1,51 @@
1
+ import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
2
+ import { In } from 'typeorm'
3
+ import { WorkShift } from './work-shift'
4
+ import { WorkShiftPatch } from './work-shift-type'
5
+
6
+ @Resolver(WorkShift)
7
+ export class WorkShiftMutation {
8
+ @Directive('@privilege(category: "system", privilege: "mutation", domainOwnerGranted: true)')
9
+ @Directive('@transaction')
10
+ @Mutation(returns => [WorkShift], { description: "To modify multiple WorkShifts' information" })
11
+ async updateMultipleWorkShift(
12
+ @Arg('patches', type => [WorkShiftPatch]) patches: WorkShiftPatch[],
13
+ @Ctx() context: any
14
+ ): Promise<WorkShift[]> {
15
+ const { domain, user, tx } = context.state
16
+
17
+ let results = []
18
+ const workShiftRepo = tx.getRepository(WorkShift)
19
+
20
+ await workShiftRepo.delete({ domain })
21
+
22
+ for (let i = 0; i < patches.length; i++) {
23
+ const patch = patches[i]
24
+
25
+ const result = await workShiftRepo.save({
26
+ ...patch,
27
+ domain,
28
+ creator: user,
29
+ updater: user
30
+ })
31
+
32
+ results.push({ ...result, cuFlag: '+' })
33
+ }
34
+
35
+ return results
36
+ }
37
+
38
+ @Directive('@privilege(category: "system", privilege: "mutation", domainOwnerGranted: true)')
39
+ @Directive('@transaction')
40
+ @Mutation(returns => Boolean, { description: 'To delete multiple workShifts' })
41
+ async deleteWorkShifts(@Arg('ids', type => [String]) ids: string[], @Ctx() context: any): Promise<boolean> {
42
+ const { domain, tx } = context.state
43
+
44
+ await tx.getRepository(WorkShift).delete({
45
+ domain,
46
+ id: In(ids)
47
+ })
48
+
49
+ return true
50
+ }
51
+ }
@@ -0,0 +1,58 @@
1
+ import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
2
+ import { getRepository } from 'typeorm'
3
+ import { Domain, ListParam, convertListParams } from '@things-factory/shell'
4
+ import { User } from '@things-factory/auth-base'
5
+ import { WorkShift } from './work-shift'
6
+ import { WorkShiftList, WorkDateWorkShiftPair } from './work-shift-type'
7
+ import { getWorkDateAndShift } from '../../controllers/index'
8
+
9
+ @Resolver(Domain)
10
+ export class DomainWorkShiftQuery {
11
+ @Query(returns => WorkDateWorkShiftPair, { description: 'To fetch a work date and work shift for given datetime' })
12
+ async getWorkDateAndShift(@Arg('dateTime') dateTime: Date, @Ctx() context: any): Promise<WorkDateWorkShiftPair> {
13
+ const { domain } = context.state
14
+
15
+ return await getWorkDateAndShift(domain, dateTime)
16
+ }
17
+
18
+ @FieldResolver(type => [WorkShift])
19
+ async workShifts(@Root() domain: Domain): Promise<WorkShift[]> {
20
+ return await getRepository(WorkShift).find({
21
+ where: {
22
+ domain
23
+ },
24
+ order: {
25
+ fromDate: 'ASC',
26
+ fromTime: 'ASC'
27
+ }
28
+ })
29
+ }
30
+ }
31
+
32
+ @Resolver(WorkShift)
33
+ export class WorkShiftQuery {
34
+ @Query(returns => WorkShiftList, { description: 'To fetch multiple WorkShifts' })
35
+ async workShifts(@Args() params: ListParam, @Ctx() context: any): Promise<WorkShiftList> {
36
+ const { domain } = context.state
37
+
38
+ const convertedParams = convertListParams(params, domain.id)
39
+ const [items, total] = await getRepository(WorkShift).findAndCount(convertedParams)
40
+
41
+ return { items, total }
42
+ }
43
+
44
+ @FieldResolver(type => Domain)
45
+ async domain(@Root() workShift: WorkShift): Promise<Domain> {
46
+ return await getRepository(Domain).findOne(workShift.domainId)
47
+ }
48
+
49
+ @FieldResolver(type => User)
50
+ async updater(@Root() workShift: WorkShift): Promise<User> {
51
+ return await getRepository(User).findOne(workShift.updaterId)
52
+ }
53
+
54
+ @FieldResolver(type => User)
55
+ async creator(@Root() workShift: WorkShift): Promise<User> {
56
+ return await getRepository(User).findOne(workShift.creatorId)
57
+ }
58
+ }
@@ -0,0 +1,41 @@
1
+ import { Field, ID, InputType, Int, ObjectType, registerEnumType } from 'type-graphql'
2
+ import { WorkShift, WorkShiftDateType } from './work-shift'
3
+
4
+ @InputType()
5
+ export class WorkShiftPatch {
6
+ @Field()
7
+ name: string
8
+
9
+ @Field({ nullable: true })
10
+ description?: string
11
+
12
+ @Field()
13
+ fromDate: WorkShiftDateType
14
+
15
+ @Field()
16
+ fromTime: string
17
+
18
+ @Field()
19
+ toDate: WorkShiftDateType
20
+
21
+ @Field()
22
+ toTime: string
23
+ }
24
+
25
+ @ObjectType()
26
+ export class WorkShiftList {
27
+ @Field(type => [WorkShift])
28
+ items: WorkShift[]
29
+
30
+ @Field(type => Int)
31
+ total: number
32
+ }
33
+
34
+ @ObjectType()
35
+ export class WorkDateWorkShiftPair {
36
+ @Field()
37
+ workDate: string
38
+
39
+ @Field()
40
+ workShift: string
41
+ }
@@ -0,0 +1,96 @@
1
+ import {
2
+ Column,
3
+ CreateDateColumn,
4
+ Entity,
5
+ Index,
6
+ ManyToOne,
7
+ PrimaryGeneratedColumn,
8
+ RelationId,
9
+ UpdateDateColumn
10
+ } from 'typeorm'
11
+ import { Field, ID, Int, ObjectType, registerEnumType } from 'type-graphql'
12
+
13
+ import { Domain } from '@things-factory/shell'
14
+ import { User } from '@things-factory/auth-base'
15
+
16
+ export enum WorkShiftDateType {
17
+ TheDayBefore = -1,
18
+ TheDay = 0,
19
+ TheDayAfter = 1
20
+ }
21
+
22
+ registerEnumType(WorkShiftDateType, {
23
+ name: 'WorkShiftDateType',
24
+ description: 'enumeration of a shift date'
25
+ })
26
+
27
+ @Entity()
28
+ @Index('ix_work_shift_0', (workShift: WorkShift) => [workShift.domain, workShift.name], { unique: true })
29
+ @Index('ix_work_shift_1', (workShift: WorkShift) => [workShift.domain, workShift.fromDate, workShift.fromTime], {
30
+ unique: true
31
+ })
32
+ @ObjectType({ description: 'Entity for WorkShift' })
33
+ export class WorkShift {
34
+ @PrimaryGeneratedColumn('uuid')
35
+ @Field(type => ID)
36
+ readonly id: string
37
+
38
+ @ManyToOne(type => Domain)
39
+ @Field({ nullable: true })
40
+ domain?: Domain
41
+
42
+ @RelationId((workShift: WorkShift) => workShift.domain)
43
+ domainId?: string
44
+
45
+ @Column()
46
+ @Field()
47
+ name: string
48
+
49
+ @Column({
50
+ nullable: true
51
+ })
52
+ @Field({ nullable: true })
53
+ description?: string
54
+
55
+ @Column()
56
+ @Field({ nullable: true })
57
+ fromDate: WorkShiftDateType
58
+
59
+ @Column()
60
+ @Field({ nullable: true })
61
+ fromTime: string
62
+
63
+ @Column()
64
+ @Field({ nullable: true })
65
+ toDate: WorkShiftDateType
66
+
67
+ @Column()
68
+ @Field({ nullable: true })
69
+ toTime: string
70
+
71
+ @CreateDateColumn()
72
+ @Field({ nullable: true })
73
+ createdAt?: Date
74
+
75
+ @UpdateDateColumn()
76
+ @Field({ nullable: true })
77
+ updatedAt?: Date
78
+
79
+ @ManyToOne(type => User, {
80
+ nullable: true
81
+ })
82
+ @Field({ nullable: true })
83
+ creator?: User
84
+
85
+ @RelationId((workShift: WorkShift) => workShift.creator)
86
+ creatorId?: string
87
+
88
+ @ManyToOne(type => User, {
89
+ nullable: true
90
+ })
91
+ @Field({ nullable: true })
92
+ updater?: User
93
+
94
+ @RelationId((workShift: WorkShift) => workShift.creator)
95
+ updaterId?: string
96
+ }
@@ -0,0 +1,13 @@
1
+ import bootstrap from './client/bootstrap'
2
+ import route from './client/route'
3
+
4
+ export default {
5
+ route,
6
+ routes: [
7
+ {
8
+ tagname: 'work-shift',
9
+ page: 'work-shift'
10
+ }
11
+ ],
12
+ bootstrap
13
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "title.work-shift": "work shift"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "title.work-shift": "교대 작업조"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "title.work-shift": "work shift"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "title.work-shift": "work shift"
3
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../tsconfig-base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist-server",
5
+ "baseUrl": "./"
6
+ },
7
+ "include": ["./server/**/*"],
8
+ "exclude": ["**/*.spec.ts"]
9
+ }