@shisyamo4131/air-guard-v2-schemas 2.1.0 → 2.2.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/package.json
CHANGED
|
@@ -466,12 +466,6 @@ export default class ArrangementNotification extends SiteOperationScheduleDetail
|
|
|
466
466
|
arguments: { ...options, transaction },
|
|
467
467
|
};
|
|
468
468
|
try {
|
|
469
|
-
// すべてのデバッグログを削除;
|
|
470
|
-
console.log("[bulkDelete] this:", this);
|
|
471
|
-
console.log("[bulkDelete] this.type:", this.type);
|
|
472
|
-
console.log("[bulkDelete] this.getAdapter:", this.getAdapter);
|
|
473
|
-
console.log("[bulkDelete] this.getAdapter():", this.getAdapter?.());
|
|
474
|
-
console.log(this);
|
|
475
469
|
// サーバー側での実行を禁止
|
|
476
470
|
if (this.type === "SERVER") {
|
|
477
471
|
throw new Error(
|
|
@@ -492,8 +486,11 @@ export default class ArrangementNotification extends SiteOperationScheduleDetail
|
|
|
492
486
|
const performTransaction = async (txn) => {
|
|
493
487
|
// Delete all notification documents if workerIds is empty.
|
|
494
488
|
if (workerIds.length === 0) {
|
|
495
|
-
|
|
496
|
-
const docs =
|
|
489
|
+
// 関数を変数に代入せず、直接呼び出す
|
|
490
|
+
const docs =
|
|
491
|
+
await ArrangementNotification.fetchDocsBySiteOperationScheduleId(
|
|
492
|
+
siteOperationScheduleId
|
|
493
|
+
);
|
|
497
494
|
if (docs.length === 0) return;
|
|
498
495
|
await Promise.all(
|
|
499
496
|
docs.map((doc) => doc.delete({ transaction: txn }))
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/*****************************************************************************
|
|
2
|
-
* SiteOperationSchedule Model ver 1.
|
|
2
|
+
* SiteOperationSchedule Model ver 1.1.0
|
|
3
|
+
* @version 1.1.0
|
|
3
4
|
* @author shisyamo4131
|
|
4
|
-
*
|
|
5
|
+
*
|
|
6
|
+
* @update 2025-11-22 v1.1.0 - Moved `duplicate`, `notify`, `syncToOperationResult`,
|
|
7
|
+
* and `toEvent` methods from client side code.
|
|
8
|
+
*
|
|
5
9
|
* - Extends Operation class to represent a site operation schedule.
|
|
6
10
|
* - Prevents updates or deletions if an associated OperationResult exists.
|
|
7
11
|
* - Automatically assigns a display order based on existing documents during creation.
|
|
@@ -12,148 +16,193 @@
|
|
|
12
16
|
* [NOTE]
|
|
13
17
|
* `siteId`, `dateAt`, `shiftType`, and `regulationWorkMinutes` are synchronized
|
|
14
18
|
* in the parent `Operation` class.
|
|
15
|
-
*
|
|
19
|
+
*
|
|
16
20
|
* @prop {string|null} operationResultId - Associated OperationResult document ID
|
|
17
21
|
* - If an OperationResult has been created based on this schedule, this property
|
|
18
22
|
* holds the ID of that OperationResult document.
|
|
19
23
|
* - If this property is set, the schedule cannot be updated or deleted.
|
|
20
24
|
* Conversely, if the associated OperationResult is deleted, this property can be set to null.
|
|
25
|
+
*
|
|
21
26
|
* @prop {number} displayOrder - Display order
|
|
22
27
|
* - Property to control the display order of schedules on the same date and shift type.
|
|
23
28
|
* - Automatically assigned during creation based on existing documents.
|
|
24
|
-
*
|
|
29
|
+
*
|
|
25
30
|
* @getter {boolean} isEditable - Indicates whether the instance is editable (read-only)
|
|
26
31
|
* - Returns `false` if `operationResultId` is set, `true` otherwise
|
|
32
|
+
*
|
|
27
33
|
* @getter {boolean} isNotificatedAllWorkers - Indicates whether all workers have been notified (read-only)
|
|
28
34
|
* - Returns `true` if all workers in the `workers` array have `hasNotification` set to `true`
|
|
29
|
-
*
|
|
35
|
+
*
|
|
30
36
|
* @inherited - The following properties are inherited from Operation:
|
|
31
37
|
* @prop {string} siteId - Site document ID (trigger property)
|
|
32
38
|
* - Automatically synchronizes to all `employees` and `outsourcers` when changed.
|
|
39
|
+
*
|
|
33
40
|
* @prop {number} requiredPersonnel - Required number of personnel
|
|
41
|
+
*
|
|
34
42
|
* @prop {boolean} qualificationRequired - Qualification required flag
|
|
43
|
+
*
|
|
35
44
|
* @prop {string} workDescription - Work description
|
|
45
|
+
*
|
|
36
46
|
* @prop {string} remarks - Remarks
|
|
47
|
+
*
|
|
37
48
|
* @prop {Array<SiteOperationScheduleDetail>} employees - Assigned employees
|
|
38
49
|
* - Array of `SiteOperationScheduleDetail` instances representing assigned employees
|
|
50
|
+
*
|
|
39
51
|
* @prop {Array<SiteOperationScheduleDetail>} outsourcers - Assigned outsourcers
|
|
40
52
|
* - Array of `SiteOperationScheduleDetail` instances representing assigned outsourcers
|
|
41
|
-
*
|
|
53
|
+
*
|
|
42
54
|
* @inherited - The following properties are inherited from WorkingResult (via Operation):
|
|
43
55
|
* @prop {Date} dateAt - Date of operation (placement date) (trigger property)
|
|
44
56
|
* - Automatically synchronizes to all `employees` and `outsourcers` when changed.
|
|
57
|
+
*
|
|
45
58
|
* @prop {string} dayType - Day type (e.g., `WEEKDAY`, `WEEKEND`, `HOLIDAY`)
|
|
59
|
+
*
|
|
46
60
|
* @prop {string} shiftType - `DAY` or `NIGHT` (trigger property)
|
|
47
61
|
* - Automatically synchronizes to all `employees` and `outsourcers` when changed.
|
|
62
|
+
*
|
|
48
63
|
* @prop {string} startTime - Start time (HH:MM format) (trigger property)
|
|
49
64
|
* - Automatically synchronizes to all `employees` and `outsourcers` when changed.
|
|
65
|
+
*
|
|
50
66
|
* @prop {boolean} isStartNextDay - Next day start flag (trigger property)
|
|
51
67
|
* - `true` if the actual work starts the day after the placement date `dateAt`
|
|
52
68
|
* - Automatically synchronizes to all `employees` and `outsourcers` when changed.
|
|
69
|
+
*
|
|
53
70
|
* @prop {string} endTime - End time (HH:MM format) (trigger property)
|
|
54
71
|
* - Automatically synchronizes to all `employees` and `outsourcers` when changed.
|
|
72
|
+
*
|
|
55
73
|
* @prop {number} breakMinutes - Break time (minutes) (trigger property)
|
|
56
74
|
* - Automatically synchronizes to all `employees` and `outsourcers` when changed.
|
|
75
|
+
*
|
|
57
76
|
* @prop {number} regulationWorkMinutes - Regulation work minutes (trigger property)
|
|
58
77
|
* - Indicates the maximum working time treated as regular working hours.
|
|
59
78
|
* - Automatically synchronizes to all `employees` and `outsourcers` when changed.
|
|
60
|
-
*
|
|
79
|
+
*
|
|
61
80
|
* @inherited - The following computed properties are inherited from Operation:
|
|
62
|
-
* @
|
|
63
|
-
*
|
|
64
|
-
* @
|
|
65
|
-
*
|
|
66
|
-
* @
|
|
81
|
+
* @prop {Array<string>} employeeIds - Array of employee IDs from `employees` (read-only)
|
|
82
|
+
*
|
|
83
|
+
* @prop {Array<string>} outsourcerIds - Array of outsourcer IDs from `outsourcers` (read-only)
|
|
84
|
+
*
|
|
85
|
+
* @prop {number} employeesCount - Count of assigned employees (read-only)
|
|
86
|
+
*
|
|
87
|
+
* @prop {number} outsourcersCount - Count of assigned outsourcers (sum of amounts) (read-only)
|
|
88
|
+
*
|
|
89
|
+
* @prop {boolean} isPersonnelShortage - Indicates if there is a shortage of personnel (read-only)
|
|
67
90
|
* - `true` if the sum of `employeesCount` and `outsourcersCount` is less than `requiredPersonnel`
|
|
68
|
-
*
|
|
91
|
+
*
|
|
92
|
+
* @prop {Array<SiteOperationScheduleDetail>} workers - Combined array of `employees` and `outsourcers`
|
|
69
93
|
* - Getter: Returns concatenated array of employees and outsourcers
|
|
70
94
|
* - Setter: Splits array into employees and outsourcers based on `isEmployee` property
|
|
71
|
-
*
|
|
95
|
+
*
|
|
72
96
|
* @inherited - The following computed properties are inherited from WorkingResult (via Operation):
|
|
73
|
-
* @
|
|
97
|
+
* @prop {string} date - Date string in YYYY-MM-DD format based on `dateAt` (read-only)
|
|
74
98
|
* - Returns a string in the format YYYY-MM-DD based on `dateAt`.
|
|
75
|
-
*
|
|
99
|
+
*
|
|
100
|
+
* @prop {Date} startAt - Start date and time (Date object) (read-only)
|
|
76
101
|
* - Returns a Date object with `startTime` set based on `dateAt`.
|
|
77
102
|
* - If `isStartNextDay` is true, add 1 day.
|
|
78
|
-
*
|
|
103
|
+
*
|
|
104
|
+
* @prop {Date} endAt - End date and time (Date object) (read-only)
|
|
79
105
|
* - Returns a Date object with `endTime` set based on `dateAt`.
|
|
80
106
|
* - If `isStartNextDay` is true, add 1 day.
|
|
81
107
|
* - If `isSpansNextDay` is true, add 1 day.
|
|
82
|
-
*
|
|
108
|
+
*
|
|
109
|
+
* @prop {boolean} isSpansNextDay - Flag indicating whether the date spans from start date to end date (read-only)
|
|
83
110
|
* - `true` if `startTime` is later than `endTime`
|
|
84
|
-
*
|
|
111
|
+
*
|
|
112
|
+
* @prop {number} totalWorkMinutes - Total working time in minutes (excluding break time) (read-only)
|
|
85
113
|
* - Calculated as the difference between `endAt` and `startAt` minus `breakMinutes`
|
|
86
|
-
*
|
|
114
|
+
*
|
|
115
|
+
* @prop {number} regularTimeWorkMinutes - Regular working time in minutes (read-only)
|
|
87
116
|
* - The portion of `totalWorkMinutes` that is considered within the contract's `regulationWorkMinutes`.
|
|
88
|
-
*
|
|
117
|
+
*
|
|
118
|
+
* @prop {number} overtimeWorkMinutes - Overtime work in minutes (read-only)
|
|
89
119
|
* - Calculated as `totalWorkMinutes` minus `regulationWorkMinutes`
|
|
90
|
-
*
|
|
120
|
+
*
|
|
91
121
|
* @inherited - The following getter properties are inherited from Operation:
|
|
92
122
|
* @getter {string} groupKey - Combines `siteId`, `shiftType`, and `date` to indicate operation grouping (read-only)
|
|
123
|
+
*
|
|
93
124
|
* @getter {boolean} isEmployeesChanged - Indicates whether the employees have changed (read-only)
|
|
94
125
|
* - Returns true if the employee IDs have changed compared to `_beforeData`
|
|
126
|
+
*
|
|
95
127
|
* @getter {boolean} isOutsourcersChanged - Indicates whether the outsourcers have changed (read-only)
|
|
96
128
|
* - Returns true if the outsourcer IDs have changed compared to `_beforeData`
|
|
129
|
+
*
|
|
97
130
|
* @getter {Array<SiteOperationScheduleDetail>} addedWorkers - An array of workers that have been added (read-only)
|
|
98
131
|
* - Workers that exist in current data but not in `_beforeData`
|
|
132
|
+
*
|
|
99
133
|
* @getter {Array<SiteOperationScheduleDetail>} removedWorkers - An array of workers that have been removed (read-only)
|
|
100
134
|
* - Workers that exist in `_beforeData` but not in current data
|
|
135
|
+
*
|
|
101
136
|
* @getter {Array<SiteOperationScheduleDetail>} updatedWorkers - An array of workers that have been updated (read-only)
|
|
102
137
|
* - Workers whose `startTime`, `isStartNextDay`, `endTime`, `breakMinutes`, `isQualified`, or `isOjt` have changed
|
|
103
|
-
*
|
|
138
|
+
*
|
|
104
139
|
* @inherited - The following getter properties are inherited from WorkingResult (via Operation):
|
|
105
140
|
* @getter {number} startHour - Start hour (0-23) (read-only)
|
|
106
141
|
* - Extracted from `startTime`.
|
|
142
|
+
*
|
|
107
143
|
* @getter {number} startMinute - Start minute (0-59) (read-only)
|
|
108
144
|
* - Extracted from `startTime`.
|
|
145
|
+
*
|
|
109
146
|
* @getter {number} endHour - End hour (0-23) (read-only)
|
|
110
147
|
* - Extracted from `endTime`.
|
|
148
|
+
*
|
|
111
149
|
* @getter {number} endMinute - End minute (0-59) (read-only)
|
|
112
150
|
* - Extracted from `endTime`.
|
|
113
|
-
*
|
|
114
|
-
* @method
|
|
115
|
-
* -
|
|
116
|
-
*
|
|
117
|
-
*
|
|
151
|
+
*
|
|
152
|
+
* @method duplicate - Duplicates the SiteOperationSchedule for specified dates
|
|
153
|
+
* - Creates new SiteOperationSchedule documents for each specified date,
|
|
154
|
+
* excluding the original date and avoiding duplicates.
|
|
155
|
+
* - Returns an array of newly created SiteOperationSchedule instances.
|
|
156
|
+
*
|
|
157
|
+
* @method notify - Creates arrangement notifications for workers who have not been notified
|
|
158
|
+
* - Creates ArrangementNotification documents for workers with `hasNotification` set to `false`.
|
|
159
|
+
* - Updates the `hasNotification` flag to `true` for all employees and outsourcers.
|
|
160
|
+
*
|
|
161
|
+
* @method syncToOperationResult - Creates an OperationResult document based on the current SiteOperationSchedule
|
|
162
|
+
* - The OperationResult document ID will be the same as the SiteOperationSchedule document ID.
|
|
163
|
+
* - Sets the `operationResultId` property of the SiteOperationSchedule to the created OperationResult document ID.
|
|
164
|
+
* - Accepts an `agreement` object containing necessary properties for creating the OperationResult.
|
|
165
|
+
*
|
|
166
|
+
* @method toEvent - Converts the SiteOperationSchedule instance to a VCalendar event object
|
|
167
|
+
* - Returns an object with properties required for displaying events in Vuetify's VCalendar component.
|
|
168
|
+
* - Includes `name`, `start`, `end`, `color`, and a reference to the original `SiteOperationSchedule` instance.
|
|
169
|
+
*
|
|
170
|
+
* @override
|
|
171
|
+
* @method create - Creates a new SiteOperationSchedule with automatic display order assignment
|
|
172
|
+
*
|
|
173
|
+
* @method update - Updates the SiteOperationSchedule and manages related notifications
|
|
118
174
|
* - Clears all notifications if related data have been changed during updates.
|
|
119
175
|
* - Updates and deletes notifications for removed or updated employees if employee assignments have changed.
|
|
120
|
-
*
|
|
121
|
-
* @method
|
|
176
|
+
*
|
|
177
|
+
* @method delete - Deletes the SiteOperationSchedule and all related notifications
|
|
122
178
|
* - Deletes all notifications associated with the schedule before deleting the schedule itself.
|
|
123
|
-
*
|
|
124
|
-
* @method
|
|
179
|
+
*
|
|
180
|
+
* @method addWorker - Adds a new worker with automatic siteOperationScheduleId assignment
|
|
125
181
|
* - Overrides parent method to automatically set `siteOperationScheduleId`
|
|
126
|
-
*
|
|
127
|
-
* - @param {number} index - Insertion position
|
|
128
|
-
* ---------------------------------------------------------------------------
|
|
182
|
+
*
|
|
129
183
|
* @inherited - The following methods are inherited from Operation:
|
|
130
|
-
* @method
|
|
131
|
-
*
|
|
132
|
-
* @method
|
|
133
|
-
*
|
|
134
|
-
* @method
|
|
135
|
-
*
|
|
136
|
-
* @method
|
|
184
|
+
* @method moveWorker - Moves the position of a worker (employee or outsourcer)
|
|
185
|
+
*
|
|
186
|
+
* @method changeWorker - Changes the details of a worker
|
|
187
|
+
*
|
|
188
|
+
* @method removeWorker - Removes a worker (employee or outsourcer)
|
|
189
|
+
*
|
|
190
|
+
* @method setSiteIdCallback - Callback method called when `siteId` is set
|
|
137
191
|
* - Override this method in subclasses to add custom behavior when `siteId` changes.
|
|
138
|
-
*
|
|
139
|
-
* @method
|
|
192
|
+
*
|
|
193
|
+
* @method setShiftTypeCallback - Callback method called when `shiftType` is set
|
|
140
194
|
* - Override this method in subclasses to add custom behavior when `shiftType` changes.
|
|
141
|
-
*
|
|
142
|
-
* @method
|
|
195
|
+
*
|
|
196
|
+
* @method setRegulationWorkMinutesCallback - Callback method called when `regulationWorkMinutes` is set
|
|
143
197
|
* - Override this method in subclasses to add custom behavior when `regulationWorkMinutes` changes.
|
|
144
|
-
*
|
|
198
|
+
*
|
|
145
199
|
* @static
|
|
146
|
-
* @method groupKeyDivider
|
|
147
|
-
*
|
|
148
|
-
* @param {Object|string} key - The combined key string or object
|
|
149
|
-
* @returns {Array<string>} - Array containing [siteId, shiftType, date]
|
|
150
|
-
* @throws {Error} - If the key is invalid.
|
|
151
|
-
* ---------------------------------------------------------------------------
|
|
200
|
+
* @method groupKeyDivider Returns an array dividing the key into siteId, shiftType, and date.
|
|
201
|
+
*
|
|
152
202
|
* @inherited - The following method is inherited from WorkingResult (via Operation):
|
|
153
|
-
* @method
|
|
203
|
+
* @method setDateAtCallback - Callback method called when `dateAt` is set
|
|
154
204
|
* - Override this method in subclasses to add custom behavior when `dateAt` changes.
|
|
155
205
|
* - By default, updates `dayType` based on the new `dateAt` value and synchronizes to workers.
|
|
156
|
-
* - @param {Date} v - The new `dateAt` value
|
|
157
206
|
*****************************************************************************/
|
|
158
207
|
import Operation from "./Operation.js";
|
|
159
208
|
import { defField } from "./parts/fieldDefinitions.js";
|
|
@@ -502,4 +551,230 @@ export default class SiteOperationSchedule extends Operation {
|
|
|
502
551
|
addWorker(options = {}, index = 0) {
|
|
503
552
|
super.addWorker({ ...options, siteOperationScheduleId: this.docId }, index);
|
|
504
553
|
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* 現場稼働予定ドキュメントを指定された日付分複製します。
|
|
557
|
+
* - 複製された各ドキュメントは新規作成され、元のドキュメントとは別のIDを持ちます。
|
|
558
|
+
* - 複製先の日付が元のドキュメントの日付と同じ場合、その日付分の複製は行われません。
|
|
559
|
+
* @param {Array<Date|string>} dates - 複製先の日付の配列。Dateオブジェクトまたは日付文字列で指定します。
|
|
560
|
+
* @returns {Promise<Array<SiteOperationSchedule>>}
|
|
561
|
+
*/
|
|
562
|
+
async duplicate(dates = []) {
|
|
563
|
+
if (!this.docId) {
|
|
564
|
+
throw new Error("不正な処理です。作成前のスケジュールは複製できません。");
|
|
565
|
+
}
|
|
566
|
+
if (!Array.isArray(dates) || dates.length === 0) {
|
|
567
|
+
throw new Error("複製する日付を配列で指定してください。");
|
|
568
|
+
}
|
|
569
|
+
if (dates.some((d) => !(d instanceof Date) && typeof d !== "string")) {
|
|
570
|
+
throw new TypeError(
|
|
571
|
+
"日付の指定が無効です。Dateオブジェクトか文字列で指定してください。"
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
if (dates.length > 20) {
|
|
575
|
+
throw new Error("一度に複製できるスケジュールは最大20件です。");
|
|
576
|
+
}
|
|
577
|
+
try {
|
|
578
|
+
// 日付が Date オブジェクトであれば日付文字列に変換しつつ、元のスケジュールと同じ日付は除外し、
|
|
579
|
+
// 加えて重複も除外する。
|
|
580
|
+
const targetDates = dates
|
|
581
|
+
.map((date) => {
|
|
582
|
+
if (date instanceof Date) return dayjs(date).format("YYYY-MM-DD");
|
|
583
|
+
return date;
|
|
584
|
+
})
|
|
585
|
+
.filter((date) => date !== this.date)
|
|
586
|
+
.reduce((unique, date) => {
|
|
587
|
+
if (!unique.includes(date)) unique.push(date);
|
|
588
|
+
return unique;
|
|
589
|
+
}, []);
|
|
590
|
+
|
|
591
|
+
// 複製するための現場稼働予定インスタンスを生成
|
|
592
|
+
const newSchedules = targetDates.map((date) => {
|
|
593
|
+
const instance = this.clone();
|
|
594
|
+
instance.docId = "";
|
|
595
|
+
instance.dateAt = new Date(date);
|
|
596
|
+
instance.operationResultId = null;
|
|
597
|
+
return instance;
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
// トランザクションで一括作成
|
|
601
|
+
await this.constructor.runTransaction(async (transaction) => {
|
|
602
|
+
await Promise.all(
|
|
603
|
+
newSchedules.map((schedule) => schedule.create({ transaction }))
|
|
604
|
+
);
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
return newSchedules;
|
|
608
|
+
} catch (error) {
|
|
609
|
+
throw new ContextualError("現場稼働予定の複製処理に失敗しました。", {
|
|
610
|
+
method: "duplicate",
|
|
611
|
+
className: "SiteOperationSchedule",
|
|
612
|
+
arguments: { dates },
|
|
613
|
+
state: this.toObject(),
|
|
614
|
+
error,
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* 配置通知を作成します。
|
|
621
|
+
* - 現在配置通知がなされてない作業員に対してのみ配置通知ドキュメントを作成します。
|
|
622
|
+
* - 全作業員の配置通知フラグが true に更新されます。
|
|
623
|
+
* @returns {Promise<void>}
|
|
624
|
+
*/
|
|
625
|
+
async notify() {
|
|
626
|
+
try {
|
|
627
|
+
// 未通知である作業員を抽出
|
|
628
|
+
const targetWorkers = this.workers.filter((w) => !w.hasNotification);
|
|
629
|
+
|
|
630
|
+
// 配置通知ドキュメントを作成するためのインスタンス配列を生成
|
|
631
|
+
const notifications = targetWorkers.map((worker) => {
|
|
632
|
+
return new ArrangementNotification({
|
|
633
|
+
...worker,
|
|
634
|
+
actualStartTime: worker.startTime,
|
|
635
|
+
actualEndTime: worker.endTime,
|
|
636
|
+
actualBreakMinutes: worker.breakMinutes,
|
|
637
|
+
});
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
// 配置通知インスタンスがなければ処理終了
|
|
641
|
+
if (notifications.length === 0) {
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// 従業員、外注先の通知済みフラグを更新
|
|
646
|
+
this.employees.forEach((emp) => (emp.hasNotification = true));
|
|
647
|
+
this.outsourcers.forEach((out) => (out.hasNotification = true));
|
|
648
|
+
|
|
649
|
+
// トランザクションで配置通知ドキュメントを一括作成し、作成済みフラグを更新
|
|
650
|
+
await this.constructor.runTransaction(async (transaction) => {
|
|
651
|
+
await Promise.all([
|
|
652
|
+
...notifications.map((n) => n.create({ transaction })),
|
|
653
|
+
this.update({ transaction }),
|
|
654
|
+
]);
|
|
655
|
+
});
|
|
656
|
+
} catch (error) {
|
|
657
|
+
this.undo();
|
|
658
|
+
throw new ContextualError(
|
|
659
|
+
`配置通知作成処理に失敗しました。: ${error.message}`,
|
|
660
|
+
{
|
|
661
|
+
method: "notify",
|
|
662
|
+
className: "SiteOperationSchedule",
|
|
663
|
+
arguments: {},
|
|
664
|
+
state: this.toObject(),
|
|
665
|
+
}
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* 現在のインスタンスから稼働実績ドキュメントを作成します。
|
|
672
|
+
* - 稼働実績ドキュメントの ID は現場稼働予定ドキュメントの ID と同一になります。
|
|
673
|
+
* 既に存在する場合は上書きされます。
|
|
674
|
+
* - 現場稼働予定ドキュメントの `operationResultId` プロパティに
|
|
675
|
+
* 作成された稼働実績ドキュメントの ID が設定されます。(当該ドキュメント ID と同一)
|
|
676
|
+
* @param {Object} agreement - 取極め情報オブジェクト。稼働実績ドキュメントの生成に必要なプロパティを含みます。
|
|
677
|
+
*/
|
|
678
|
+
async syncToOperationResult(agreement, notifications = {}) {
|
|
679
|
+
if (!this.docId) {
|
|
680
|
+
throw new Error(
|
|
681
|
+
"不正な処理です。作成前の現場稼働予定から稼働実績を作成することはできません。"
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
if (!notifications) {
|
|
686
|
+
throw new Error("配置通知の指定が必要です。");
|
|
687
|
+
}
|
|
688
|
+
const converter = (prop) => {
|
|
689
|
+
return this[prop].map((w) => {
|
|
690
|
+
const notification = notifications[w.notificationKey];
|
|
691
|
+
if (!notification) return w;
|
|
692
|
+
const {
|
|
693
|
+
actualStartTime: startTime,
|
|
694
|
+
actualEndTime: endTime,
|
|
695
|
+
actualBreakMinutes: breakMinutes,
|
|
696
|
+
actualIsStartNextDay: isStartNextDay,
|
|
697
|
+
} = notification;
|
|
698
|
+
return new SiteOperationScheduleDetail({
|
|
699
|
+
...w.toObject(),
|
|
700
|
+
startTime,
|
|
701
|
+
endTime,
|
|
702
|
+
breakMinutes,
|
|
703
|
+
isStartNextDay,
|
|
704
|
+
});
|
|
705
|
+
});
|
|
706
|
+
};
|
|
707
|
+
const employees = converter("employees");
|
|
708
|
+
const outsourcers = converter("outsourcers");
|
|
709
|
+
try {
|
|
710
|
+
// Create OperationResult instance based on the current SiteOperationSchedule
|
|
711
|
+
const operationResult = new OperationResult({
|
|
712
|
+
...this.toObject(),
|
|
713
|
+
employees,
|
|
714
|
+
outsourcers,
|
|
715
|
+
agreement: agreement || null,
|
|
716
|
+
siteOperationScheduleId: this.docId,
|
|
717
|
+
});
|
|
718
|
+
operationResult.refreshBillingDateAt();
|
|
719
|
+
await this.constructor.runTransaction(async (transaction) => {
|
|
720
|
+
const docRef = await operationResult.create({
|
|
721
|
+
docId: this.docId,
|
|
722
|
+
transaction,
|
|
723
|
+
});
|
|
724
|
+
this.operationResultId = docRef.id;
|
|
725
|
+
await this.update({ transaction });
|
|
726
|
+
});
|
|
727
|
+
} catch (error) {
|
|
728
|
+
throw new ContextualError(error.message, {
|
|
729
|
+
method: "syncToOperationResult()",
|
|
730
|
+
className: "SiteOperationSchedule",
|
|
731
|
+
arguments: { agreement },
|
|
732
|
+
state: this.toObject(),
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* この現場稼働予定インスタンスを、Vuetify の VCalendar コンポーネントで
|
|
739
|
+
* 表示可能なイベントオブジェクト形式に変換して返します。
|
|
740
|
+
*
|
|
741
|
+
* VCalendar でイベントを表示する際に必要な主要なプロパティ(タイトル、開始日時、
|
|
742
|
+
* 終了日時、色など)を設定します。
|
|
743
|
+
*
|
|
744
|
+
* @returns {object} VCalendar イベントオブジェクト。以下のプロパティを含みます:
|
|
745
|
+
* @property {string} name - イベントのタイトル。`requiredPersonnel`(必要人数)と `workDescription`(作業内容)から生成されます。
|
|
746
|
+
* @property {Date} start - イベントの開始日時。インスタンスの `startAt` プロパティ(Dateオブジェクト)がそのまま使用されます。
|
|
747
|
+
* @property {Date} end - イベントの終了日時。
|
|
748
|
+
* **注意点:** 本来はインスタンスの `endAt` プロパティを使用すべきですが、
|
|
749
|
+
* VCalendar の仕様(または過去のバージョンでの挙動)により、日をまたぐイベントを
|
|
750
|
+
* `endAt` で正確に指定すると、カレンダー上で複数の日にまたがって
|
|
751
|
+
* 同一イベントが複数描画されてしまう問題がありました。
|
|
752
|
+
* これを回避するため、現状では `startAt` と同じ値を設定し、
|
|
753
|
+
* イベントが開始日のみに単一のイベントとして表示されるようにしています。
|
|
754
|
+
* もし将来的に日をまたぐ期間を正確にカレンダー上で表現する必要が生じた場合は、
|
|
755
|
+
* VCalendar のバージョンアップや設定変更、またはこの `end` プロパティの
|
|
756
|
+
* 扱いについて再検討が必要です。
|
|
757
|
+
* @property {string} color - イベントの表示色。`shiftType` プロパティの値に応じて、
|
|
758
|
+
* 日勤 (`day`) の場合は 'orange'、夜勤 (`night`) の場合は 'navy' が設定されます。
|
|
759
|
+
* @property {SiteOperationSchedule} item - この `SiteOperationSchedule` インスタンス自身への参照です。
|
|
760
|
+
* カレンダー上でイベントがクリックされた際などに、元のスケジュールデータへ
|
|
761
|
+
* アクセスするために利用できます。
|
|
762
|
+
*/
|
|
763
|
+
toEvent() {
|
|
764
|
+
const name = `${this.requiredPersonnel} 名: ${
|
|
765
|
+
this.workDescription || "通常警備"
|
|
766
|
+
}`;
|
|
767
|
+
const color = !this.isEditable
|
|
768
|
+
? "grey"
|
|
769
|
+
: this.shiftType === "DAY"
|
|
770
|
+
? "orange"
|
|
771
|
+
: "indigo";
|
|
772
|
+
return {
|
|
773
|
+
name,
|
|
774
|
+
start: this.dateAt,
|
|
775
|
+
end: this.dateAt,
|
|
776
|
+
color,
|
|
777
|
+
item: this,
|
|
778
|
+
};
|
|
779
|
+
}
|
|
505
780
|
}
|