@shisyamo4131/air-guard-v2-schemas 2.3.7-dev.29 → 2.3.7-dev.30

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": "2.3.7-dev.29",
3
+ "version": "2.3.7-dev.30",
4
4
  "description": "Schemas for AirGuard V2",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/src/Employee.js CHANGED
@@ -414,9 +414,15 @@ export default class Employee extends FireModel {
414
414
  * 新しい従業員ドキュメントが作成される前に実行されるフック。
415
415
  * - 親クラスの `beforeCreate` を呼び出します。
416
416
  * - 従業員が外国人の場合、外国人名と国籍が未入力であればエラーをスローします。
417
+ * @param {Object} args - Creation options.
418
+ * @param {string} [args.docId] - Document ID to use (optional).
419
+ * @param {boolean} [args.useAutonumber=true] - Whether to use auto-numbering.
420
+ * @param {Object} [args.transaction] - Firestore transaction.
421
+ * @param {Function} [args.callBack] - Callback function.
422
+ * @param {string} [args.prefix] - Path prefix.
417
423
  */
418
- async beforeCreate() {
419
- await super.beforeCreate();
424
+ async beforeCreate(args = {}) {
425
+ await super.beforeCreate(args);
420
426
  this._validateForeignerRequiredFields();
421
427
  this._validateTerminatedRequiredFields();
422
428
  this._validateSecurityGuardFields();
@@ -426,9 +432,13 @@ export default class Employee extends FireModel {
426
432
  * 従業員ドキュメントが更新される前に実行されるフック。
427
433
  * - 親クラスの `beforeUpdate` を呼び出します。
428
434
  * - 従業員が外国人の場合、外国人名と国籍が未入力であればエラーをスローします。
435
+ * @param {Object} args - Creation options.
436
+ * @param {Object} [args.transaction] - Firestore transaction.
437
+ * @param {Function} [args.callBack] - Callback function.
438
+ * @param {string} [args.prefix] - Path prefix.
429
439
  */
430
- async beforeUpdate() {
431
- await super.beforeUpdate();
440
+ async beforeUpdate(args = {}) {
441
+ await super.beforeUpdate(args);
432
442
 
433
443
  // `employmentStatus` の `terminated` への直接変更の禁止
434
444
  // - 従業員を退職させる場合、様々なチェックが必要になることが想定されるため、専用メソッドとして `toTerminated` を使用する。
@@ -193,12 +193,17 @@ export default class OperationBilling extends OperationResult {
193
193
 
194
194
  /**
195
195
  * Override beforeUpdate to skip `isLocked` check and sync customerId and apply agreement if key changed
196
+ * @param {Object} args - Creation options.
197
+ * @param {Object} [args.transaction] - Firestore transaction.
198
+ * @param {Function} [args.callBack] - Callback function.
199
+ * @param {string} [args.prefix] - Path prefix.
196
200
  * @returns {Promise<void>}
197
201
  */
198
- async beforeUpdate() {
202
+ async beforeUpdate(args = {}) {
203
+ await super.beforeUpdate(args);
199
204
  // Sync customerId and apply agreement if key changed
200
205
  if (this.key === this._beforeData.key) return;
201
- await this._syncCustomerIdAndApplyAgreement();
206
+ await this._syncCustomerIdAndApplyAgreement(args);
202
207
  }
203
208
 
204
209
  /**
@@ -542,13 +542,19 @@ export default class OperationResult extends Operation {
542
542
 
543
543
  /**
544
544
  * Synchronize customerId and apply (re-apply) agreement from siteId
545
+ * @param {Object} [args.transaction] - Firestore transaction.
546
+ * @param {Function} [args.callBack] - Callback function.
547
+ * @param {string} [args.prefix] - Path prefix.
545
548
  * @returns {Promise<void>}
546
549
  * @throws {Error} If the specified siteId does not exist
547
550
  */
548
- async _syncCustomerIdAndApplyAgreement() {
551
+ async _syncCustomerIdAndApplyAgreement(args = {}) {
549
552
  if (!this.siteId) return;
550
553
  const siteInstance = new Site();
551
- const siteExists = await siteInstance.fetch({ docId: this.siteId });
554
+ const siteExists = await siteInstance.fetch({
555
+ ...args,
556
+ docId: this.siteId,
557
+ });
552
558
  if (!siteExists) {
553
559
  throw new Error(
554
560
  `[OperationResult] The specified siteId (${this.siteId}) does not exist.`
@@ -560,10 +566,16 @@ export default class OperationResult extends Operation {
560
566
 
561
567
  /**
562
568
  * Override beforeCreate to sync customerId
569
+ * @param {Object} args - Creation options.
570
+ * @param {string} [args.docId] - Document ID to use (optional).
571
+ * @param {boolean} [args.useAutonumber=true] - Whether to use auto-numbering.
572
+ * @param {Object} [args.transaction] - Firestore transaction.
573
+ * @param {Function} [args.callBack] - Callback function.
574
+ * @param {string} [args.prefix] - Path prefix.
563
575
  * @returns {Promise<void>}
564
576
  */
565
- async beforeCreate() {
566
- await super.beforeCreate();
577
+ async beforeCreate(args = {}) {
578
+ await super.beforeCreate(args);
567
579
 
568
580
  // Sync customerId and apply agreement
569
581
  await this._syncCustomerIdAndApplyAgreement();
@@ -571,10 +583,14 @@ export default class OperationResult extends Operation {
571
583
 
572
584
  /**
573
585
  * Override beforeUpdate to sync customerId and apply agreement if key changed
586
+ * @param {Object} args - Creation options.
587
+ * @param {Object} [args.transaction] - Firestore transaction.
588
+ * @param {Function} [args.callBack] - Callback function.
589
+ * @param {string} [args.prefix] - Path prefix.
574
590
  * @returns {Promise<void>}
575
591
  */
576
- async beforeUpdate() {
577
- await super.beforeUpdate();
592
+ async beforeUpdate(args = {}) {
593
+ await super.beforeUpdate(args);
578
594
 
579
595
  // Prevent editing if isLocked is true
580
596
  if (this.isLocked) {
@@ -590,12 +606,15 @@ export default class OperationResult extends Operation {
590
606
 
591
607
  /**
592
608
  * Override beforeDelete to prevent deletion if isLocked is true
609
+ * @param {Object} args - Creation options.
610
+ * @param {Object} [args.transaction] - Firestore transaction.
611
+ * @param {Function} [args.callBack] - Callback function.
612
+ * @param {string} [args.prefix] - Path prefix.
593
613
  * @returns {Promise<void>}
594
614
  * @throws {Error} If isLocked is true
595
615
  */
596
- async beforeDelete() {
597
- await super.beforeDelete();
598
-
616
+ async beforeDelete(args = {}) {
617
+ await super.beforeDelete(args);
599
618
  // Prevent deletion if isLocked is true
600
619
  if (this.isLocked) {
601
620
  throw new Error(
package/src/Site.js CHANGED
@@ -5,26 +5,35 @@
5
5
  * @update 2025-11-20 version 0.2.0-bata
6
6
  * - Prevent changing customer reference on update.
7
7
  * - Move `customer` property to the top of classProps for better visibility.
8
+ *
9
+ * NOTE: `customer` プロパティについて
10
+ * 自身の従属先データを持たせる場合に `XxxxxMinimal` クラスを使用するが、アプリ側でオブジェクト選択を行う場合に
11
+ * `Xxxxx` クラスにするのか `XxxxxMinimal` クラスにするのかを判断できないため、docId を持たせて
12
+ * `beforeCreate` フックでオブジェクトを取得するようにする。
13
+ * 尚、取引先は変更できない仕様。
8
14
  */
9
15
  import { default as FireModel } from "@shisyamo4131/air-firebase-v2";
10
16
  import { defField } from "./parts/fieldDefinitions.js";
11
17
  import { defAccessor } from "./parts/accessorDefinitions.js";
12
- import { CustomerMinimal } from "./Customer.js";
13
- import { fetchDocsApi } from "./apis/index.js";
18
+ import Customer from "./Customer.js";
19
+ // import { CustomerMinimal } from "./Customer.js";
20
+ // import { fetchDocsApi } from "./apis/index.js";
14
21
  import Agreement from "./Agreement.js";
15
22
  import { VALUES } from "./constants/site-status.js";
16
23
 
17
24
  const classProps = {
18
- customer: defField("customer", {
19
- required: true,
20
- customClass: CustomerMinimal,
21
- component: {
22
- attrs: {
23
- api: () => fetchDocsApi(CustomerMinimal),
24
- noFilter: true,
25
- },
26
- },
27
- }),
25
+ customerId: defField("customerId", { required: true }),
26
+ customer: defField("customer", { hidden: true, customClass: Customer }),
27
+ // customer: defField("customer", {
28
+ // required: true,
29
+ // customClass: CustomerMinimal,
30
+ // component: {
31
+ // attrs: {
32
+ // api: () => fetchDocsApi(CustomerMinimal),
33
+ // noFilter: true,
34
+ // },
35
+ // },
36
+ // }),
28
37
  code: defField("code", { label: "現場コード" }),
29
38
  name: defField("name", {
30
39
  label: "現場名",
@@ -118,12 +127,42 @@ export default class Site extends FireModel {
118
127
  static STATUS_ACTIVE = VALUES.ACTIVE.value;
119
128
  static STATUS_TERMINATED = VALUES.TERMINATED.value;
120
129
 
130
+ /**
131
+ * Overrides to fetch and set the customer object before creation.
132
+ * @param {Object} args - Creation options.
133
+ * @param {string} [args.docId] - Document ID to use (optional).
134
+ * @param {boolean} [args.useAutonumber=true] - Whether to use auto-numbering.
135
+ * @param {Object} [args.transaction] - Firestore transaction.
136
+ * @param {Function} [args.callBack] - Callback function.
137
+ * @param {string} [args.prefix] - Path prefix.
138
+ * @returns {Promise<void>}
139
+ */
140
+ async beforeCreate(args = {}) {
141
+ await super.beforeCreate(args);
142
+ if (!this.customerId) return;
143
+ const customerInstance = new Customer();
144
+ const isExist = await customerInstance.fetch({
145
+ ...args,
146
+ docId: this.customerId,
147
+ });
148
+ if (!isExist) {
149
+ return Promise.reject(
150
+ new Error("Invalid customerId: Customer does not exist.")
151
+ );
152
+ }
153
+ this.customer = customerInstance;
154
+ }
155
+
121
156
  /**
122
157
  * Override beforeUpdate to prevent changing customer reference.
158
+ * @param {Object} args - Creation options.
159
+ * @param {Object} [args.transaction] - Firestore transaction.
160
+ * @param {Function} [args.callBack] - Callback function.
161
+ * @param {string} [args.prefix] - Path prefix.
123
162
  * @returns {Promise<void>}
124
163
  */
125
- async beforeUpdate() {
126
- await super.beforeUpdate();
164
+ async beforeUpdate(args = {}) {
165
+ await super.beforeUpdate(args);
127
166
  if (this.customer.docId !== this._beforeData.customer.docId) {
128
167
  return Promise.reject(
129
168
  new Error("Not allowed to change customer reference.")
@@ -135,7 +174,7 @@ export default class Site extends FireModel {
135
174
  super.afterInitialize(item);
136
175
 
137
176
  Object.defineProperties(this, {
138
- customerId: defAccessor("customerId"),
177
+ // customerId: defAccessor("customerId"),
139
178
  fullAddress: defAccessor("fullAddress"),
140
179
  prefecture: defAccessor("prefecture"),
141
180
  });
@@ -385,27 +385,35 @@ export default class SiteOperationSchedule extends Operation {
385
385
  /**
386
386
  * Override `beforeUpdate`.
387
387
  * - Prevents updates if an associated OperationResult exists.
388
+ * @param {Object} args - Creation options.
389
+ * @param {Object} [args.transaction] - Firestore transaction.
390
+ * @param {Function} [args.callBack] - Callback function.
391
+ * @param {string} [args.prefix] - Path prefix.
388
392
  */
389
- async beforeUpdate() {
393
+ async beforeUpdate(args = {}) {
390
394
  if (this._beforeData.operationResultId) {
391
395
  throw new Error(
392
396
  `Could not update this document. The OperationResult based on this document already exists. OperationResultId: ${this._beforeData.operationResultId}`
393
397
  );
394
398
  }
395
- await super.beforeUpdate();
399
+ await super.beforeUpdate(args);
396
400
  }
397
401
 
398
402
  /**
399
403
  * Override `beforeDelete`.
400
404
  * - Prevents deletions if an associated OperationResult exists.
405
+ * @param {Object} args - Creation options.
406
+ * @param {Object} [args.transaction] - Firestore transaction.
407
+ * @param {Function} [args.callBack] - Callback function.
408
+ * @param {string} [args.prefix] - Path prefix.
401
409
  */
402
- async beforeDelete() {
410
+ async beforeDelete(args = {}) {
403
411
  if (this._beforeData.operationResultId) {
404
412
  throw new Error(
405
413
  `Could not delete this document. The OperationResult based on this document already exists. OperationResultId: ${this._beforeData.operationResultId}`
406
414
  );
407
415
  }
408
- await super.beforeDelete();
416
+ await super.beforeDelete(args);
409
417
  }
410
418
 
411
419
  /**
package/src/apis/index.js CHANGED
@@ -1,3 +1,7 @@
1
+ // 2025-12-08
2
+ // アプリ側で `useFetchXxxx` コンポーザブルを使用した API 連携を行う為
3
+ // このファイルは不要。
4
+ // 各種関数に依存しているファイルの存在がないことを確認の上、削除予定。
1
5
  export function fetchDocsApi(constructor) {
2
6
  const instance = new constructor();
3
7
  return async (search) => await instance.fetchDocs({ constraints: search });
@@ -10,6 +10,8 @@ import { OPTIONS } from "../constants/prefectures.js";
10
10
  * @type {Object.<string, AccessorImplementation>}
11
11
  */
12
12
  const accessorImplementations = {
13
+ // 2025-12-08 削除可能
14
+ // `defAccessor("customerId")` で使用されていなければ削除。
13
15
  customerId: {
14
16
  get() {
15
17
  return this?.customer?.docId;
@@ -246,6 +246,8 @@ export const fieldDefinitions = {
246
246
  customerId: {
247
247
  ...generalDefinitions.oneLine,
248
248
  label: "取引先",
249
+ // アプリ側で `useFetchXxxx` コンポーザブルを使用するため
250
+ // 使用するクラス側で api 関連の設定は不要。
249
251
  component: {
250
252
  name: "air-autocomplete-api",
251
253
  attrs: {