@shisyamo4131/air-guard-v2-schemas 2.3.7-dev.4 → 2.3.7-dev.40

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.
@@ -542,28 +542,40 @@ 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.`
555
561
  );
556
562
  }
557
563
  this.customerId = siteInstance.customerId;
558
- this.agreement = siteInstance.getCurrentAgreement(this);
564
+ this.agreement = siteInstance.getAgreement(this);
559
565
  }
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,32 @@
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";
14
19
  import Agreement from "./Agreement.js";
15
20
  import { VALUES } from "./constants/site-status.js";
16
21
 
17
22
  const classProps = {
18
- customer: defField("customer", {
23
+ customerId: defField("customerId", {
19
24
  required: true,
20
- customClass: CustomerMinimal,
21
25
  component: {
22
26
  attrs: {
23
- api: () => fetchDocsApi(CustomerMinimal),
24
- noFilter: true,
27
+ disabled: ({ editMode }) => {
28
+ return editMode !== "CREATE";
29
+ },
25
30
  },
26
31
  },
27
32
  }),
33
+ customer: defField("customer", { hidden: true, customClass: Customer }),
28
34
  code: defField("code", { label: "現場コード" }),
29
35
  name: defField("name", {
30
36
  label: "現場名",
@@ -118,12 +124,42 @@ export default class Site extends FireModel {
118
124
  static STATUS_ACTIVE = VALUES.ACTIVE.value;
119
125
  static STATUS_TERMINATED = VALUES.TERMINATED.value;
120
126
 
127
+ /**
128
+ * Overrides to fetch and set the customer object before creation.
129
+ * @param {Object} args - Creation options.
130
+ * @param {string} [args.docId] - Document ID to use (optional).
131
+ * @param {boolean} [args.useAutonumber=true] - Whether to use auto-numbering.
132
+ * @param {Object} [args.transaction] - Firestore transaction.
133
+ * @param {Function} [args.callBack] - Callback function.
134
+ * @param {string} [args.prefix] - Path prefix.
135
+ * @returns {Promise<void>}
136
+ */
137
+ async beforeCreate(args = {}) {
138
+ await super.beforeCreate(args);
139
+ if (!this.customerId) return;
140
+ const customerInstance = new Customer();
141
+ const isExist = await customerInstance.fetch({
142
+ ...args,
143
+ docId: this.customerId,
144
+ });
145
+ if (!isExist) {
146
+ return Promise.reject(
147
+ new Error("Invalid customerId: Customer does not exist.")
148
+ );
149
+ }
150
+ this.customer = customerInstance;
151
+ }
152
+
121
153
  /**
122
154
  * Override beforeUpdate to prevent changing customer reference.
155
+ * @param {Object} args - Creation options.
156
+ * @param {Object} [args.transaction] - Firestore transaction.
157
+ * @param {Function} [args.callBack] - Callback function.
158
+ * @param {string} [args.prefix] - Path prefix.
123
159
  * @returns {Promise<void>}
124
160
  */
125
- async beforeUpdate() {
126
- await super.beforeUpdate();
161
+ async beforeUpdate(args = {}) {
162
+ await super.beforeUpdate(args);
127
163
  if (this.customer.docId !== this._beforeData.customer.docId) {
128
164
  return Promise.reject(
129
165
  new Error("Not allowed to change customer reference.")
@@ -135,7 +171,7 @@ export default class Site extends FireModel {
135
171
  super.afterInitialize(item);
136
172
 
137
173
  Object.defineProperties(this, {
138
- customerId: defAccessor("customerId"),
174
+ // customerId: defAccessor("customerId"),
139
175
  fullAddress: defAccessor("fullAddress"),
140
176
  prefecture: defAccessor("prefecture"),
141
177
  });
@@ -1,8 +1,9 @@
1
1
  /*****************************************************************************
2
2
  * SiteOperationSchedule Model ver 1.1.0
3
- * @version 1.1.0
3
+ * @version 1.1.1
4
4
  * @author shisyamo4131
5
5
  *
6
+ * @update 2025-11-28 v1.1.1 - Removed the `agreement` parameter from `syncToOperationResult` method.
6
7
  * @update 2025-11-22 v1.1.0 - Moved `duplicate`, `notify`, `syncToOperationResult`,
7
8
  * and `toEvent` methods from client side code.
8
9
  *
@@ -167,7 +168,8 @@
167
168
  * @method syncToOperationResult - Creates an OperationResult document based on the current SiteOperationSchedule
168
169
  * - The OperationResult document ID will be the same as the SiteOperationSchedule document ID.
169
170
  * - Sets the `operationResultId` property of the SiteOperationSchedule to the created OperationResult document ID.
170
- * - Accepts an `agreement` object containing necessary properties for creating the OperationResult.
171
+ * - If an OperationResult already exists, it will be overwritten.
172
+ * - [UPDATE 2025-11-28] Removed the `agreement` parameter. The agreement is now fetched internally.
171
173
  *
172
174
  * @method toEvent - Converts the SiteOperationSchedule instance to a VCalendar event object
173
175
  * - Returns an object with properties required for displaying events in Vuetify's VCalendar component.
@@ -383,27 +385,35 @@ export default class SiteOperationSchedule extends Operation {
383
385
  /**
384
386
  * Override `beforeUpdate`.
385
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.
386
392
  */
387
- async beforeUpdate() {
393
+ async beforeUpdate(args = {}) {
388
394
  if (this._beforeData.operationResultId) {
389
395
  throw new Error(
390
396
  `Could not update this document. The OperationResult based on this document already exists. OperationResultId: ${this._beforeData.operationResultId}`
391
397
  );
392
398
  }
393
- await super.beforeUpdate();
399
+ await super.beforeUpdate(args);
394
400
  }
395
401
 
396
402
  /**
397
403
  * Override `beforeDelete`.
398
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.
399
409
  */
400
- async beforeDelete() {
410
+ async beforeDelete(args = {}) {
401
411
  if (this._beforeData.operationResultId) {
402
412
  throw new Error(
403
413
  `Could not delete this document. The OperationResult based on this document already exists. OperationResultId: ${this._beforeData.operationResultId}`
404
414
  );
405
415
  }
406
- await super.beforeDelete();
416
+ await super.beforeDelete(args);
407
417
  }
408
418
 
409
419
  /**
@@ -679,9 +689,14 @@ export default class SiteOperationSchedule extends Operation {
679
689
  * 既に存在する場合は上書きされます。
680
690
  * - 現場稼働予定ドキュメントの `operationResultId` プロパティに
681
691
  * 作成された稼働実績ドキュメントの ID が設定されます。(当該ドキュメント ID と同一)
682
- * @param {Object} agreement - 取極め情報オブジェクト。稼働実績ドキュメントの生成に必要なプロパティを含みます。
692
+ * @param {Object} notifications - 配置通知オブジェクトのマップ。
693
+ * - キー: 配置通知の一意キー(`notificationKey` プロパティ)
694
+ * - 値: 配置通知ドキュメントオブジェクト
695
+ * @returns {Promise<void>}
696
+ *
697
+ * @update 2025-11-28 - Removed the `agreement` parameter.
683
698
  */
684
- async syncToOperationResult(agreement, notifications = {}) {
699
+ async syncToOperationResult(notifications = {}) {
685
700
  if (!this.docId) {
686
701
  throw new Error(
687
702
  "不正な処理です。作成前の現場稼働予定から稼働実績を作成することはできません。"
@@ -695,18 +710,12 @@ export default class SiteOperationSchedule extends Operation {
695
710
  return this[prop].map((w) => {
696
711
  const notification = notifications[w.notificationKey];
697
712
  if (!notification) return w;
698
- const {
699
- actualStartTime: startTime,
700
- actualEndTime: endTime,
701
- actualBreakMinutes: breakMinutes,
702
- actualIsStartNextDay: isStartNextDay,
703
- } = notification;
704
713
  return new SiteOperationScheduleDetail({
705
714
  ...w.toObject(),
706
- startTime,
707
- endTime,
708
- breakMinutes,
709
- isStartNextDay,
715
+ startTime: notification.actualStartTime,
716
+ endTime: notification.actualEndTime,
717
+ breakMinutes: notification.actualBreakMinutes,
718
+ isStartNextDay: notification.actualIsStartNextDay,
710
719
  });
711
720
  });
712
721
  };
@@ -718,10 +727,8 @@ export default class SiteOperationSchedule extends Operation {
718
727
  ...this.toObject(),
719
728
  employees,
720
729
  outsourcers,
721
- agreement: agreement || null,
722
730
  siteOperationScheduleId: this.docId,
723
731
  });
724
- operationResult.refreshBillingDateAt();
725
732
  await this.constructor.runTransaction(async (transaction) => {
726
733
  const docRef = await operationResult.create({
727
734
  docId: this.docId,
package/src/System.js ADDED
@@ -0,0 +1,43 @@
1
+ /**
2
+ * System.js
3
+ * @version 1.0.0
4
+ * @description System model
5
+ * @author shisyamo4131
6
+ */
7
+ import FireModel from "@shisyamo4131/air-firebase-v2";
8
+ import { defField } from "./parts/fieldDefinitions.js";
9
+
10
+ const classProps = {
11
+ isMaintenance: defField("check", { default: false, hidden: true }),
12
+ updatedAt: defField("dateAt", { default: null, hidden: true }),
13
+ lastMaintenanceBy: defField("oneLine", {
14
+ default: "admin-sdk",
15
+ hidden: true,
16
+ }),
17
+ };
18
+
19
+ /**
20
+ * @prop {boolean} isMaintenance - maintenance mode flag
21
+ * @prop {Date} updatedAt - last updated timestamp
22
+ * @prop {string} lastMaintenanceBy - identifier of the last maintainer
23
+ */
24
+ export default class System extends FireModel {
25
+ static className = "System";
26
+ static collectionPath = "System";
27
+ static usePrefix = false;
28
+ static useAutonumber = false;
29
+ static logicalDelete = false;
30
+ static classProps = classProps;
31
+
32
+ async create() {
33
+ return Promise.reject(new Error("[System.js] Not implemented."));
34
+ }
35
+
36
+ async update() {
37
+ return Promise.reject(new Error("[System.js] Not implemented."));
38
+ }
39
+
40
+ async delete() {
41
+ return Promise.reject(new Error("[System.js] Not implemented."));
42
+ }
43
+ }
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 });
@@ -0,0 +1,14 @@
1
+ // prettier-ignore
2
+ export const VALUES = Object.freeze({
3
+ A: { title: "A型", value: "A" },
4
+ B: { title: "B型", value: "B" },
5
+ O: { title: "O型", value: "O" },
6
+ AB: { title: "AB型", value: "AB" },
7
+ });
8
+
9
+ export const OPTIONS = [
10
+ { title: VALUES.A.title, value: VALUES.A.value },
11
+ { title: VALUES.B.title, value: VALUES.B.value },
12
+ { title: VALUES.O.title, value: VALUES.O.value },
13
+ { title: VALUES.AB.title, value: VALUES.AB.value },
14
+ ];
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @file src/constants/certification-type.js
3
+ * @description 警備業務資格の種別定義
4
+ *
5
+ * 警備業法に基づく4号区分:
6
+ * - 1号警備業務:施設警備業務
7
+ * - 2号警備業務:交通誘導警備業務、雑踏警備業務
8
+ * - 3号警備業務:貴重品運搬警備業務、核燃料物質等危険物運搬警備業務
9
+ * - 4号警備業務:身辺警備業務
10
+ *
11
+ * 実務上の考慮事項:
12
+ * - 現場ごとに必要な資格タイプが異なる
13
+ * - 1級保有者は2級の業務も対応可能(包括関係)
14
+ * - ユーザビリティを考慮し、タイプ単位で管理
15
+ */
16
+
17
+ // prettier-ignore
18
+ export const VALUES = Object.freeze({
19
+ FACILITY: { title: "施設警備", value: "FACILITY" }, // 1号
20
+ TRAFFIC: { title: "交通誘導警備", value: "TRAFFIC" }, // 2号
21
+ CROWD: { title: "雑踏警備", value: "CROWD" }, // 2号
22
+ VALUABLES: { title: "貴重品運搬警備", value: "VALUABLES" }, // 3号
23
+ BODYGUARD: { title: "身辺警備", value: "BODYGUARD" }, // 4号
24
+ OTHER: { title: "その他", value: "OTHER" },
25
+ });
26
+
27
+ export const OPTIONS = [
28
+ { title: VALUES.FACILITY.title, value: VALUES.FACILITY.value },
29
+ { title: VALUES.TRAFFIC.title, value: VALUES.TRAFFIC.value },
30
+ { title: VALUES.CROWD.title, value: VALUES.CROWD.value },
31
+ { title: VALUES.VALUABLES.title, value: VALUES.VALUABLES.value },
32
+ { title: VALUES.BODYGUARD.title, value: VALUES.BODYGUARD.value },
33
+ { title: VALUES.OTHER.title, value: VALUES.OTHER.value },
34
+ ];
@@ -0,0 +1,16 @@
1
+ // prettier-ignore
2
+ export const VALUES = Object.freeze({
3
+ PARENT: { title: "親", value: "PARENT" },
4
+ SPOUSE: { title: "配偶者", value: "SPOUSE" },
5
+ CHILD: { title: "子", value: "CHILD" },
6
+ SIBLING: { title: "兄弟姉妹", value: "SIBLING" },
7
+ OTHER: { title: "その他", value: "OTHER" },
8
+ });
9
+
10
+ export const OPTIONS = [
11
+ { title: VALUES.PARENT.title, value: VALUES.PARENT.value },
12
+ { title: VALUES.SPOUSE.title, value: VALUES.SPOUSE.value },
13
+ { title: VALUES.CHILD.title, value: VALUES.CHILD.value },
14
+ { title: VALUES.SIBLING.title, value: VALUES.SIBLING.value },
15
+ { title: VALUES.OTHER.title, value: VALUES.OTHER.value },
16
+ ];
@@ -6,6 +6,14 @@ export {
6
6
  VALUES as BILLING_UNIT_TYPE_VALUES,
7
7
  OPTIONS as BILLING_UNIT_TYPE_OPTIONS,
8
8
  } from "./billing-unit-type.js";
9
+ export {
10
+ VALUES as BLOOD_TYPE_VALUES,
11
+ OPTIONS as BLOOD_TYPE_OPTIONS,
12
+ } from "./blood-type.js";
13
+ export {
14
+ VALUES as CERTIFICATION_TYPE_VALUES,
15
+ OPTIONS as CERTIFICATION_TYPE_OPTIONS,
16
+ } from "./certification-type.js";
9
17
  export {
10
18
  VALUES as CONTRACT_STATUS_VALUES,
11
19
  OPTIONS as CONTRACT_STATUS_OPTIONS,
@@ -15,6 +23,10 @@ export {
15
23
  OPTIONS as DAY_TYPE_OPTIONS,
16
24
  getDayType,
17
25
  } from "./day-type.js";
26
+ export {
27
+ VALUES as EMERGENCY_CONTACT_RELATION_VALUES,
28
+ OPTIONS as EMERGENCY_CONTACT_RELATION_OPTIONS,
29
+ } from "./emergency-contact-relation.js";
18
30
  export {
19
31
  VALUES as EMPLOYMENT_STATUS_VALUES,
20
32
  OPTIONS as EMPLOYMENT_STATUS_OPTIONS,
@@ -10,17 +10,15 @@ 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
- enumerable: true,
15
16
  get() {
16
17
  return this?.customer?.docId;
17
18
  },
18
- set(value) {
19
- // No-op setter for read-only access
20
- },
19
+ set() {},
21
20
  },
22
21
  fullAddress: {
23
- enumerable: true,
24
22
  get() {
25
23
  // 同じオブジェクトに 'prefecture' アクセサが定義されていることを前提とします
26
24
  const prefecture = this.prefecture || "";
@@ -28,53 +26,41 @@ const accessorImplementations = {
28
26
  const address = this.address || "";
29
27
  return `${prefecture}${city}${address}`;
30
28
  },
31
- set(value) {
32
- // No-op setter for read-only access
33
- },
29
+ set() {},
34
30
  },
35
31
  fullName: {
36
- enumerable: true,
37
32
  get() {
38
33
  if (!this.lastName || !this.firstName) return "";
39
34
  return `${this.lastName} ${this.firstName}`;
40
35
  },
41
- set(value) {
42
- // No-op setter for read-only access
36
+ set() {},
37
+ },
38
+ fullNameKana: {
39
+ get() {
40
+ if (!this.lastNameKana || !this.firstNameKana) return "";
41
+ return `${this.lastNameKana} ${this.firstNameKana}`;
43
42
  },
43
+ set() {},
44
44
  },
45
45
  prefecture: {
46
- enumerable: true,
47
46
  get() {
48
- // if (!this.hasOwnProperty("prefCode")) {
49
- // console.warn(
50
- // "[アクセサ: prefecture] このオブジェクトに prefCode が定義されていません。"
51
- // );
52
- // return "";
53
- // }
54
-
55
47
  if (!this.prefCode) return ""; // No warning if prefCode is falsy but present
56
-
57
48
  const result = OPTIONS.find(({ value }) => value === this.prefCode);
58
-
59
49
  if (!result) {
60
50
  console.warn(
61
51
  `[アクセサ: prefecture] prefCode '${this.prefCode}' は OPTIONS に見つかりません。`
62
52
  );
63
53
  return "";
64
54
  }
65
-
66
55
  if (!result.hasOwnProperty("title")) {
67
56
  console.warn(
68
57
  `[アクセサ: prefecture] OPTIONS の prefCode '${this.prefCode}' に title が定義されていません。`
69
58
  );
70
59
  return "";
71
60
  }
72
-
73
61
  return result.title;
74
62
  },
75
- set(value) {
76
- // No-op setter for read-only access
77
- },
63
+ set() {},
78
64
  },
79
65
  };
80
66
 
@@ -90,7 +76,7 @@ const accessorImplementations = {
90
76
  */
91
77
  export const defAccessor = (
92
78
  key,
93
- { configurable = false, enumerable = false } = {}
79
+ { configurable = true, enumerable = true } = {}
94
80
  ) => {
95
81
  const implementation = accessorImplementations[key];
96
82
  if (!implementation) {