@things-factory/work-shift 8.0.0-beta.9 → 8.0.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/client/bootstrap.ts +1 -0
- package/client/index.ts +0 -0
- package/client/pages/work-shift.ts +108 -0
- package/client/route.ts +7 -0
- package/client/tsconfig.json +13 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/server/controllers/index.ts +2 -0
- package/server/controllers/work-shift-range.ts +250 -0
- package/server/controllers/work-shift-schedule.ts +79 -0
- package/server/index.ts +2 -0
- package/server/service/index.ts +18 -0
- package/server/service/work-shift/index.ts +7 -0
- package/server/service/work-shift/work-shift-mutation.ts +55 -0
- package/server/service/work-shift/work-shift-query.ts +67 -0
- package/server/service/work-shift/work-shift-type.ts +47 -0
- package/server/service/work-shift/work-shift.ts +92 -0
- package/server/tsconfig.json +10 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/work-shift",
|
|
3
|
-
"version": "8.0.0
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "dist-client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create ./server/migrations/migration"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@things-factory/auth-base": "^8.0.0
|
|
31
|
-
"@things-factory/env": "^8.0.0
|
|
32
|
-
"@things-factory/shell": "^8.0.0
|
|
30
|
+
"@things-factory/auth-base": "^8.0.0",
|
|
31
|
+
"@things-factory/env": "^8.0.0",
|
|
32
|
+
"@things-factory/shell": "^8.0.0",
|
|
33
33
|
"moment-timezone": "^0.5.40"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "07ef27d272dd9a067a9648ac7013748510556a18"
|
|
36
36
|
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import moment from 'moment-timezone'
|
|
2
|
+
|
|
3
|
+
import { logger } from '@things-factory/env'
|
|
4
|
+
import { Domain, getRepository } from '@things-factory/shell'
|
|
5
|
+
|
|
6
|
+
import { WorkShift } from '../service/work-shift/work-shift'
|
|
7
|
+
import { WorkShiftInfo } from '../service/work-shift/work-shift-type'
|
|
8
|
+
|
|
9
|
+
export async function getDateRangeForWorkShift(
|
|
10
|
+
domain: Domain,
|
|
11
|
+
workDate: string,
|
|
12
|
+
workShiftName: string,
|
|
13
|
+
options?: { timezone?: string; format?: string }
|
|
14
|
+
): Promise<Date[]> {
|
|
15
|
+
const dateOptions = { timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD', ...options }
|
|
16
|
+
const { timezone, format } = dateOptions
|
|
17
|
+
|
|
18
|
+
const workShift = await getRepository(WorkShift).findOne({
|
|
19
|
+
where: {
|
|
20
|
+
domain: { id: domain.id },
|
|
21
|
+
name: workShiftName
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
if (!workShift) {
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
const theDay = moment.tz(workDate, timezone)
|
|
29
|
+
const { name, fromDate, fromTime, toDate, toTime } = workShift
|
|
30
|
+
|
|
31
|
+
const convertedFromDate = theDay.clone().add(fromDate, 'day')
|
|
32
|
+
const convertedToDate = theDay.clone().add(toDate, 'day')
|
|
33
|
+
const from = moment
|
|
34
|
+
.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)
|
|
35
|
+
.toDate()
|
|
36
|
+
const to = moment.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone).toDate()
|
|
37
|
+
|
|
38
|
+
return [from, to]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function getDateRangeForWorkDate(
|
|
42
|
+
domain: Domain,
|
|
43
|
+
workDate: string,
|
|
44
|
+
options?: { timezone?: string; format?: string }
|
|
45
|
+
) {
|
|
46
|
+
const dateOptions = { timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD', ...options }
|
|
47
|
+
const { timezone, format } = dateOptions
|
|
48
|
+
|
|
49
|
+
var beginDate
|
|
50
|
+
var endDate
|
|
51
|
+
|
|
52
|
+
/* 1. get work-shift list for the domain */
|
|
53
|
+
const workShifts = await getRepository(WorkShift).find({
|
|
54
|
+
where: {
|
|
55
|
+
domain: { id: domain.id }
|
|
56
|
+
},
|
|
57
|
+
order: {
|
|
58
|
+
fromDate: 'ASC',
|
|
59
|
+
fromTime: 'ASC'
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
/* 2. get date-time for every work-shift */
|
|
64
|
+
if (workShifts && workShifts.length > 0) {
|
|
65
|
+
const theDay = moment.tz(workDate, timezone)
|
|
66
|
+
|
|
67
|
+
for (let j = 0; j < workShifts.length; j++) {
|
|
68
|
+
const { name, fromDate, fromTime, toDate, toTime } = workShifts[j]
|
|
69
|
+
|
|
70
|
+
const convertedFromDate = theDay.clone().add(fromDate, 'day')
|
|
71
|
+
const convertedToDate = theDay.clone().add(toDate, 'day')
|
|
72
|
+
const from = moment
|
|
73
|
+
.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)
|
|
74
|
+
.toDate()
|
|
75
|
+
const to = moment
|
|
76
|
+
.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)
|
|
77
|
+
.toDate()
|
|
78
|
+
|
|
79
|
+
if (!beginDate) {
|
|
80
|
+
beginDate = from
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
endDate = to
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* 3. in case there are no work-shift, just give date and default shift '' */
|
|
90
|
+
return [beginDate, endDate]
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function getWorkDateAndShift(domain: Domain, dateTime: Date, options?: any): Promise<WorkShiftInfo> {
|
|
94
|
+
const dateOptions = { timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD', ...options }
|
|
95
|
+
const { timezone, format } = dateOptions
|
|
96
|
+
|
|
97
|
+
const givenDate = moment(dateTime).tz(timezone)
|
|
98
|
+
/* 1. get work-shift list for the domain */
|
|
99
|
+
const workShifts = await getRepository(WorkShift).find({
|
|
100
|
+
where: {
|
|
101
|
+
domain: { id: domain.id }
|
|
102
|
+
},
|
|
103
|
+
order: {
|
|
104
|
+
fromDate: 'ASC',
|
|
105
|
+
fromTime: 'ASC'
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
/* 2. compare given date-time to every work-shift */
|
|
110
|
+
const theDay = givenDate.clone().startOf('day')
|
|
111
|
+
const theDayBefore = theDay.clone().subtract(1, 'day')
|
|
112
|
+
const theDayAfter = theDay.clone().add(1, 'day')
|
|
113
|
+
|
|
114
|
+
if (workShifts && workShifts.length > 0) {
|
|
115
|
+
const days = [theDayBefore, theDay, theDayAfter]
|
|
116
|
+
let dateBegin, dateEnd
|
|
117
|
+
|
|
118
|
+
for (let i = 0; i < days.length; i++) {
|
|
119
|
+
const day = days[i]
|
|
120
|
+
dateBegin = null
|
|
121
|
+
|
|
122
|
+
for (let j = 0; j < workShifts.length; j++) {
|
|
123
|
+
const { name, fromDate, fromTime, toDate, toTime } = workShifts[j]
|
|
124
|
+
|
|
125
|
+
const convertedFromDate = day.clone().add(fromDate, 'day')
|
|
126
|
+
const convertedToDate = day.clone().add(toDate, 'day')
|
|
127
|
+
|
|
128
|
+
const from = moment.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)
|
|
129
|
+
const to = moment.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)
|
|
130
|
+
|
|
131
|
+
dateBegin = dateBegin || from
|
|
132
|
+
dateEnd = from.clone().add(1, 'day')
|
|
133
|
+
|
|
134
|
+
if (dateTime >= from.toDate() && to.toDate() > dateTime) {
|
|
135
|
+
return {
|
|
136
|
+
workDate: moment(day).format(format),
|
|
137
|
+
workShift: name,
|
|
138
|
+
dateRange: [dateBegin.toDate(), dateEnd.toDate()],
|
|
139
|
+
shiftRange: [from.toDate(), to.toDate()]
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
logger.error(new Error('shift not found'))
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* 3. in case there are no work-shift, just give date and default shift '' */
|
|
149
|
+
return {
|
|
150
|
+
workDate: givenDate.format(format),
|
|
151
|
+
workShift: '',
|
|
152
|
+
dateRange: [theDay.toDate(), theDayAfter.toDate()]
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export async function getLatestWorkDateAndShift(domain: Domain, dateTime: Date, options?: any): Promise<WorkShiftInfo> {
|
|
157
|
+
const dateOptions = { timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD', ...options }
|
|
158
|
+
const { timezone, format } = dateOptions
|
|
159
|
+
|
|
160
|
+
const givenDate = moment(dateTime).tz(timezone)
|
|
161
|
+
|
|
162
|
+
/* 1. get work-shift list for the domain */
|
|
163
|
+
const workShifts = await getRepository(WorkShift).find({
|
|
164
|
+
where: {
|
|
165
|
+
domain: { id: domain.id }
|
|
166
|
+
},
|
|
167
|
+
order: {
|
|
168
|
+
fromDate: 'ASC',
|
|
169
|
+
fromTime: 'ASC'
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
/* 2. compare given date-time to every work-shift */
|
|
174
|
+
const theDay = givenDate.clone().startOf('day')
|
|
175
|
+
const theDayBefore = theDay.clone().subtract(1, 'day')
|
|
176
|
+
const theDayAfter = theDay.clone().add(1, 'day')
|
|
177
|
+
|
|
178
|
+
if (workShifts && workShifts.length > 0) {
|
|
179
|
+
const days = [theDayBefore, theDay, theDayAfter]
|
|
180
|
+
let dateBegin, dateEnd
|
|
181
|
+
|
|
182
|
+
for (let i = 0; i < days.length; i++) {
|
|
183
|
+
const day = days[i]
|
|
184
|
+
dateBegin = null
|
|
185
|
+
|
|
186
|
+
for (let j = 0; j < workShifts.length; j++) {
|
|
187
|
+
const { name, fromDate, fromTime, toDate, toTime } = workShifts[j]
|
|
188
|
+
|
|
189
|
+
const convertedFromDate = day.clone().add(fromDate, 'day')
|
|
190
|
+
const convertedToDate = day.clone().add(toDate, 'day')
|
|
191
|
+
|
|
192
|
+
const from = moment.tz(`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)
|
|
193
|
+
const to = moment.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)
|
|
194
|
+
|
|
195
|
+
dateBegin = dateBegin || from
|
|
196
|
+
dateEnd = from.clone().add(1, 'day')
|
|
197
|
+
|
|
198
|
+
if (dateTime < from.toDate()) {
|
|
199
|
+
if (j > 0) {
|
|
200
|
+
const { name, fromDate, fromTime, toDate, toTime } = workShifts[j - 1]
|
|
201
|
+
|
|
202
|
+
const from = moment.tz(
|
|
203
|
+
`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`,
|
|
204
|
+
'YYYY-MM-DD HH:mm:ss',
|
|
205
|
+
timezone
|
|
206
|
+
)
|
|
207
|
+
const to = moment.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)
|
|
208
|
+
|
|
209
|
+
return {
|
|
210
|
+
workDate: moment(day).format(format),
|
|
211
|
+
workShift: name,
|
|
212
|
+
dateRange: [dateBegin.toDate(), dateEnd.toDate()],
|
|
213
|
+
shiftRange: [from.toDate(), to.toDate()]
|
|
214
|
+
}
|
|
215
|
+
} else if (i > 0) {
|
|
216
|
+
const { name, fromDate, fromTime, toDate, toTime } = workShifts[0]
|
|
217
|
+
|
|
218
|
+
const convertedFromDate = days[i - 1].clone().add(fromDate, 'day')
|
|
219
|
+
const convertedToDate = days[i - 1].clone().add(toDate, 'day')
|
|
220
|
+
|
|
221
|
+
const from = moment.tz(
|
|
222
|
+
`${convertedFromDate.format('YYYY-MM-DD')} ${fromTime}`,
|
|
223
|
+
'YYYY-MM-DD HH:mm:ss',
|
|
224
|
+
timezone
|
|
225
|
+
)
|
|
226
|
+
const to = moment.tz(`${convertedToDate.format('YYYY-MM-DD')} ${toTime}`, 'YYYY-MM-DD HH:mm:ss', timezone)
|
|
227
|
+
|
|
228
|
+
return {
|
|
229
|
+
workDate: moment(day).format(format),
|
|
230
|
+
workShift: name,
|
|
231
|
+
dateRange: [dateBegin.clone().subtract(1, 'day').toDate(), dateBegin.toDate()],
|
|
232
|
+
shiftRange: [from.toDate(), to.toDate()]
|
|
233
|
+
}
|
|
234
|
+
} else {
|
|
235
|
+
return
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
logger.error(new Error('shift not found'))
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/* 3. in case there are no work-shift, just give date and default shift '' */
|
|
245
|
+
return {
|
|
246
|
+
workDate: givenDate.clone().subtract(1, 'day').format(format),
|
|
247
|
+
workShift: '',
|
|
248
|
+
dateRange: [theDayBefore.toDate(), theDay.toDate()]
|
|
249
|
+
}
|
|
250
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Domain, getRepository } from '@things-factory/shell'
|
|
2
|
+
|
|
3
|
+
import { WorkShift } from '../service/work-shift/work-shift'
|
|
4
|
+
|
|
5
|
+
export async function getSummaryScheduleForWorkShift(domain: Domain): Promise<string> {
|
|
6
|
+
const workShifts = await getRepository(WorkShift).find({
|
|
7
|
+
where: {
|
|
8
|
+
domain: { id: domain.id }
|
|
9
|
+
}
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
if (!workShifts || workShifts.length == 0) {
|
|
13
|
+
return ''
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const hours = workShifts
|
|
17
|
+
.map(workShift => workShift.toTime)
|
|
18
|
+
.map(getNextHourIn24HourFormat)
|
|
19
|
+
.join(',')
|
|
20
|
+
|
|
21
|
+
return `10 ${hours} * * * *`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function getSummaryScheduleForWorkDate(domain: Domain): Promise<string> {
|
|
25
|
+
/* 1. 도메인의 워크시프트를 모두 가져온다. */
|
|
26
|
+
const workShifts = await getRepository(WorkShift).find({
|
|
27
|
+
where: {
|
|
28
|
+
domain: { id: domain.id }
|
|
29
|
+
},
|
|
30
|
+
order: {
|
|
31
|
+
fromDate: 'ASC',
|
|
32
|
+
fromTime: 'ASC'
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
/* 2. 워크데이의 마지막 시간을 구한 뒤, 그 30분뒤 시간에 매일 수행하는 crontab을 계산한다. */
|
|
37
|
+
if (workShifts && workShifts.length > 0) {
|
|
38
|
+
const { toTime } = workShifts[workShifts.length - 1]
|
|
39
|
+
return timePlusThirtyMinutesToCron(toTime)
|
|
40
|
+
} else {
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function timePlusThirtyMinutesToCron(time: string): string {
|
|
46
|
+
const isPM = time.toUpperCase().includes('PM')
|
|
47
|
+
const [hours, minutes] = time
|
|
48
|
+
.toUpperCase()
|
|
49
|
+
.replace(/(AM|PM)/, '')
|
|
50
|
+
.split(':')
|
|
51
|
+
.map(Number)
|
|
52
|
+
|
|
53
|
+
// 기준 날짜와 시간 정보를 사용하여 Date 객체를 생성합니다.
|
|
54
|
+
let date = new Date(1970, 0, 1, isPM ? (hours % 12) + 12 : hours % 12, minutes)
|
|
55
|
+
|
|
56
|
+
// 30분을 추가합니다.
|
|
57
|
+
date.setMinutes(date.getMinutes() + 30)
|
|
58
|
+
|
|
59
|
+
// 결과 시간을 얻습니다.
|
|
60
|
+
const resultHours = String(date.getHours()).padStart(2, '0')
|
|
61
|
+
const resultMinutes = String(date.getMinutes()).padStart(2, '0')
|
|
62
|
+
|
|
63
|
+
// 결과 시간을 사용하여 crontab 항목을 반환합니다.
|
|
64
|
+
return `${resultMinutes} ${resultHours} * * * *`
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function getNextHourIn24HourFormat(time: string): string {
|
|
68
|
+
const isPM = time.toUpperCase().includes('PM')
|
|
69
|
+
const hours = Number(time.split(':')[0])
|
|
70
|
+
|
|
71
|
+
// 기준 날짜와 시간 정보를 사용하여 Date 객체를 생성합니다.
|
|
72
|
+
let date = new Date(1970, 0, 1, isPM ? (hours % 12) + 12 : hours % 12, 0)
|
|
73
|
+
|
|
74
|
+
// 시간 값을 1 증가시킵니다.
|
|
75
|
+
date.setHours(date.getHours() + 1)
|
|
76
|
+
|
|
77
|
+
// 결과 시간을 얻습니다.
|
|
78
|
+
return String(date.getHours()).padStart(2, '0')
|
|
79
|
+
}
|
package/server/index.ts
ADDED
|
@@ -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,55 @@
|
|
|
1
|
+
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
+
import { In } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { WorkShift } from './work-shift'
|
|
5
|
+
import { WorkShiftPatch } from './work-shift-type'
|
|
6
|
+
|
|
7
|
+
@Resolver(WorkShift)
|
|
8
|
+
export class WorkShiftMutation {
|
|
9
|
+
@Directive('@privilege(category: "work-shift", privilege: "mutation", domainOwnerGranted: true)')
|
|
10
|
+
@Directive('@transaction')
|
|
11
|
+
@Mutation(returns => [WorkShift], { description: "To modify multiple WorkShifts' information" })
|
|
12
|
+
async updateMultipleWorkShift(
|
|
13
|
+
@Arg('patches', type => [WorkShiftPatch]) patches: WorkShiftPatch[],
|
|
14
|
+
@Ctx() context: ResolverContext
|
|
15
|
+
): Promise<WorkShift[]> {
|
|
16
|
+
const { domain, user, tx } = context.state
|
|
17
|
+
|
|
18
|
+
let results = []
|
|
19
|
+
const workShiftRepo = tx.getRepository(WorkShift)
|
|
20
|
+
|
|
21
|
+
await workShiftRepo.delete({ domain: { id: domain.id } })
|
|
22
|
+
|
|
23
|
+
for (let i = 0; i < patches.length; i++) {
|
|
24
|
+
const patch = patches[i]
|
|
25
|
+
|
|
26
|
+
const result = await workShiftRepo.save({
|
|
27
|
+
...patch,
|
|
28
|
+
domain,
|
|
29
|
+
creator: user,
|
|
30
|
+
updater: user
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
results.push({ ...result, cuFlag: '+' })
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return results
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Directive('@privilege(category: "work-shift", privilege: "mutation", domainOwnerGranted: true)')
|
|
40
|
+
@Directive('@transaction')
|
|
41
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple workShifts' })
|
|
42
|
+
async deleteWorkShifts(
|
|
43
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
44
|
+
@Ctx() context: ResolverContext
|
|
45
|
+
): Promise<boolean> {
|
|
46
|
+
const { domain, tx } = context.state
|
|
47
|
+
|
|
48
|
+
await tx.getRepository(WorkShift).delete({
|
|
49
|
+
domain: { id: domain.id },
|
|
50
|
+
id: In(ids)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
return true
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { User } from '@things-factory/auth-base'
|
|
4
|
+
import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
5
|
+
|
|
6
|
+
import { getWorkDateAndShift } from '../../controllers/index'
|
|
7
|
+
import { WorkShift } from './work-shift'
|
|
8
|
+
import { WorkShiftInfo, WorkShiftList } from './work-shift-type'
|
|
9
|
+
|
|
10
|
+
@Resolver(Domain)
|
|
11
|
+
export class DomainWorkShiftQuery {
|
|
12
|
+
@Query(returns => WorkShiftInfo, { description: 'To fetch a work date and work shift for given datetime' })
|
|
13
|
+
async getWorkDateAndShift(@Arg('dateTime') dateTime: Date, @Ctx() context: ResolverContext): Promise<WorkShiftInfo> {
|
|
14
|
+
const { domain } = context.state
|
|
15
|
+
|
|
16
|
+
return await getWorkDateAndShift(domain, dateTime)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@FieldResolver(type => [WorkShift])
|
|
20
|
+
async workShifts(@Root() domain: Domain): Promise<WorkShift[]> {
|
|
21
|
+
return await getRepository(WorkShift).find({
|
|
22
|
+
where: {
|
|
23
|
+
domain: { id: domain.id }
|
|
24
|
+
},
|
|
25
|
+
order: {
|
|
26
|
+
fromDate: 'ASC',
|
|
27
|
+
fromTime: 'ASC'
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Resolver(WorkShift)
|
|
34
|
+
export class WorkShiftQuery {
|
|
35
|
+
@Query(returns => WorkShiftList, { description: 'To fetch multiple WorkShifts' })
|
|
36
|
+
async workShifts(
|
|
37
|
+
@Args(type => ListParam) params: ListParam,
|
|
38
|
+
@Ctx() context: ResolverContext
|
|
39
|
+
): Promise<WorkShiftList> {
|
|
40
|
+
const { domain } = context.state
|
|
41
|
+
|
|
42
|
+
const queryBuilder = getQueryBuilderFromListParams({
|
|
43
|
+
repository: getRepository(WorkShift),
|
|
44
|
+
params,
|
|
45
|
+
domain
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const [items, total] = await queryBuilder.getManyAndCount()
|
|
49
|
+
|
|
50
|
+
return { items, total }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@FieldResolver(type => Domain)
|
|
54
|
+
async domain(@Root() workShift: WorkShift): Promise<Domain> {
|
|
55
|
+
return await getRepository(Domain).findOneBy({ id: workShift.domainId })
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@FieldResolver(type => User)
|
|
59
|
+
async updater(@Root() workShift: WorkShift): Promise<User> {
|
|
60
|
+
return await getRepository(User).findOneBy({ id: workShift.updaterId })
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@FieldResolver(type => User)
|
|
64
|
+
async creator(@Root() workShift: WorkShift): Promise<User> {
|
|
65
|
+
return await getRepository(User).findOneBy({ id: workShift.creatorId })
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 WorkShiftInfo {
|
|
36
|
+
@Field({ nullable: true })
|
|
37
|
+
workDate?: string
|
|
38
|
+
|
|
39
|
+
@Field({ nullable: true })
|
|
40
|
+
workShift?: string
|
|
41
|
+
|
|
42
|
+
@Field(type => [Date], { nullable: true })
|
|
43
|
+
dateRange?: Date[]
|
|
44
|
+
|
|
45
|
+
@Field(type => [Date], { nullable: true })
|
|
46
|
+
shiftRange?: Date[]
|
|
47
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
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(type => Domain)
|
|
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, { nullable: true })
|
|
80
|
+
@Field(type => User, { nullable: true })
|
|
81
|
+
creator?: User
|
|
82
|
+
|
|
83
|
+
@RelationId((workShift: WorkShift) => workShift.creator)
|
|
84
|
+
creatorId?: string
|
|
85
|
+
|
|
86
|
+
@ManyToOne(type => User, { nullable: true })
|
|
87
|
+
@Field(type => User, { nullable: true })
|
|
88
|
+
updater?: User
|
|
89
|
+
|
|
90
|
+
@RelationId((workShift: WorkShift) => workShift.updater)
|
|
91
|
+
updaterId?: string
|
|
92
|
+
}
|