@shisyamo4131/air-guard-v2-schemas 1.3.1-dev.19 → 1.3.1-dev.21

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shisyamo4131/air-guard-v2-schemas",
3
- "version": "1.3.1-dev.19",
3
+ "version": "1.3.1-dev.21",
4
4
  "description": "Schemas for AirGuard V2",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -41,7 +41,6 @@
41
41
  * - Setter: Splits array into employees and outsourcers based on `isEmployee` property
42
42
  * @prop {string|null} siteOperationScheduleId - Associated SiteOperationSchedule document ID
43
43
  * - If this OperationResult was created from a SiteOperationSchedule, this property holds that ID.
44
- * - If this property is set, the instance cannot be deleted.
45
44
  * @prop {boolean} useAdjustedQuantity - Flag to indicate if adjusted quantities are used for billing
46
45
  * @prop {number} adjustedQuantityBase - Adjusted quantity for base workers
47
46
  * - Quantity used for billing base workers when `useAdjustedQuantity` is true.
@@ -132,9 +131,6 @@
132
131
  * @getter {number} endMinute - End minute (0-59) (read-only)
133
132
  * - Extracted from `endTime`.
134
133
  *
135
- * @method beforeDelete - Override method to prevent deletion with siteOperationScheduleId
136
- * - Prevents deletion if the instance has `siteOperationScheduleId`.
137
- * - Throws an error if deletion is attempted on an instance created from SiteOperationSchedule.
138
134
  * @method refreshBillingDateAt - Refresh billingDateAt based on dateAt and cutoffDate
139
135
  * - Updates `billingDateAt` based on the current `dateAt` and `cutoffDate` values.
140
136
  * @method addWorker - Adds a new worker (employee or outsourcer)
@@ -5,7 +5,6 @@
5
5
  *
6
6
  * - Extends Operation class to represent the result of an operation.
7
7
  * - Also incorporates Agreement class properties for pricing and billing information.
8
- * - Prevents deletion if the instance has `siteOperationScheduleId`.
9
8
  * - Provides comprehensive billing calculations including statistics, sales amounts, and tax.
10
9
  * - Supports both daily and hourly billing with adjusted quantities.
11
10
  * - Automatically updates `billingDateAt` based on `dateAt` and `cutoffDate`.
@@ -41,7 +40,6 @@
41
40
  * - Setter: Splits array into employees and outsourcers based on `isEmployee` property
42
41
  * @prop {string|null} siteOperationScheduleId - Associated SiteOperationSchedule document ID
43
42
  * - If this OperationResult was created from a SiteOperationSchedule, this property holds that ID.
44
- * - If this property is set, the instance cannot be deleted.
45
43
  * @prop {boolean} useAdjustedQuantity - Flag to indicate if adjusted quantities are used for billing
46
44
  * @prop {number} adjustedQuantityBase - Adjusted quantity for base workers
47
45
  * - Quantity used for billing base workers when `useAdjustedQuantity` is true.
@@ -131,9 +129,6 @@
131
129
  * @getter {number} endMinute - End minute (0-59) (read-only)
132
130
  * - Extracted from `endTime`.
133
131
  *
134
- * @method beforeDelete - Override method to prevent deletion with siteOperationScheduleId
135
- * - Prevents deletion if the instance has `siteOperationScheduleId`.
136
- * - Throws an error if deletion is attempted on an instance created from SiteOperationSchedule.
137
132
  * @method refreshBillingDateAt - Refresh billingDateAt based on dateAt and cutoffDate
138
133
  * - Updates `billingDateAt` based on the current `dateAt` and `cutoffDate` values.
139
134
  * @method addWorker - Adds a new worker (employee or outsourcer)
@@ -172,7 +167,11 @@
172
167
  * - @returns {Array<string>} - Array containing [siteId, shiftType, date]
173
168
  * - @throws {Error} - If the key is invalid.
174
169
  *
175
- * @override setDateAtCallback - Updates `billingDateAt` based on the new `dateAt` value.
170
+ * @override
171
+ * @method setDateAtCallback - Updates `billingDateAt` based on the new `dateAt` value.
172
+ * @method beforeCreate - Override to sync customerId from siteId
173
+ * @method beforeUpdate - Override to sync customerId from siteId when siteId changes
174
+ * @method beforeDelete - Override to prevent deletion if isLocked is true
176
175
  *****************************************************************************/
177
176
  import Operation from "./Operation.js";
178
177
  import Agreement from "./Agreement.js";
@@ -183,6 +182,7 @@ import Tax from "./tax.js";
183
182
  import { BILLING_UNIT_TYPE_PER_HOUR } from "./constants/billing-unit-type.js";
184
183
  import RoundSetting from "./RoundSetting.js";
185
184
  import CutoffDate from "./utils/CutoffDate.js";
185
+ import Site from "./Site.js";
186
186
 
187
187
  const classProps = {
188
188
  ...Operation.classProps,
@@ -221,6 +221,13 @@ const classProps = {
221
221
  label: "取極めなしを許容",
222
222
  default: false,
223
223
  }),
224
+
225
+ /**
226
+ * siteId から自動同期されるプロパティ
227
+ * - 従属する取引先の変更を不可としているため、ドキュメントの更新時に取得するだけで問題ない。
228
+ * - 但し、siteId が変更された時は再取得する必要がある。
229
+ */
230
+ customerId: defField("customerId", { required: true, hidden: true }),
224
231
  };
225
232
 
226
233
  const INVALID_REASON = {
@@ -525,40 +532,65 @@ export default class OperationResult extends Operation {
525
532
  }
526
533
 
527
534
  /**
528
- * Override create method to validate billingDateAt when allowEmptyAgreement is true
529
- * @param {*} options
530
- * @returns {Promise<DocumentReference>}
535
+ * Synchronize customerId from siteId
536
+ * @returns {Promise<void>}
537
+ * @throws {Error} If the specified siteId does not exist
538
+ */
539
+ async _syncCustomerId() {
540
+ if (!this.siteId) return;
541
+ const siteInstance = new Site();
542
+ const siteExists = await siteInstance.fetch({ docId: this.siteId });
543
+ if (!siteExists) {
544
+ throw new Error(
545
+ `[OperationResult] The specified siteId (${this.siteId}) does not exist.`
546
+ );
547
+ }
548
+ this.customerId = siteInstance.customerId;
549
+ }
550
+
551
+ /**
552
+ * Override beforeCreate to sync customerId
553
+ * @returns {Promise<void>}
531
554
  */
532
- async create(options = {}) {
533
- return await super.create(options);
555
+ async beforeCreate() {
556
+ await super.beforeCreate();
557
+
558
+ // Sync customerId
559
+ await this._syncCustomerId();
534
560
  }
535
561
 
536
562
  /**
537
- * Override update method to prevent editing if isLocked is true
538
- * - Also validate billingDateAt when allowEmptyAgreement is true
539
- * @param {*} options
563
+ * Override beforeUpdate to sync customerId if siteId changed
540
564
  * @returns {Promise<void>}
541
565
  */
542
- async update(options = {}) {
566
+ async beforeUpdate() {
567
+ await super.beforeUpdate();
568
+
569
+ // Prevent editing if isLocked is true
543
570
  if (this.isLocked) {
544
571
  throw new Error(
545
572
  "[OperationResult] This OperationResult is locked and cannot be edited."
546
573
  );
547
574
  }
548
- return await super.update(options);
575
+
576
+ // Sync customerId if siteId changed
577
+ if (this.siteId === this._beforeData.siteId && this.customerId) return;
578
+ await this._syncCustomerId();
549
579
  }
550
580
 
551
581
  /**
552
- * Override delete method to prevent deletion if isLocked is true
553
- * @param {*} options
582
+ * Override beforeDelete to prevent deletion if isLocked is true
554
583
  * @returns {Promise<void>}
584
+ * @throws {Error} If isLocked is true
555
585
  */
556
- async delete(options = {}) {
586
+ async beforeDelete() {
587
+ await super.beforeDelete();
588
+
589
+ // Prevent deletion if isLocked is true
557
590
  if (this.isLocked) {
558
591
  throw new Error(
559
592
  "[OperationResult] This OperationResult is locked and cannot be deleted."
560
593
  );
561
594
  }
562
- return await super.delete(options);
563
595
  }
564
596
  }