@shisyamo4131/air-guard-v2-schemas 2.4.2-dev.90 → 2.4.2-dev.92

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.4.2-dev.90",
3
+ "version": "2.4.2-dev.92",
4
4
  "description": "Schemas for AirGuard V2",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/src/Site.js CHANGED
@@ -15,9 +15,11 @@ import { default as FireModel } from "@shisyamo4131/air-firebase-v2";
15
15
  import { defField } from "./parts/fieldDefinitions.js";
16
16
  import { defAccessor } from "./parts/accessorDefinitions.js";
17
17
  import Customer from "./Customer.js";
18
+ import SiteOperationSchedule from "./SiteOperationSchedule.js";
18
19
  import AgreementV2 from "./AgreementV2.js";
19
20
  import { VALUES } from "./constants/site-status.js";
20
21
  import { GeocodableMixin } from "./mixins/GeocodableMixin.js";
22
+ import { formatJstDate } from "./utils/index.js";
21
23
 
22
24
  const classProps = {
23
25
  customerId: defField("customerId", {
@@ -345,4 +347,47 @@ export default class Site extends GeocodableMixin(FireModel) {
345
347
  );
346
348
  return null;
347
349
  }
350
+
351
+ /**
352
+ * 現場を稼働終了状態に更新します。
353
+ * @returns {Promise<DocumentReference>} 更新されたドキュメントリファレンス
354
+ * @throws {Error} ドキュメントが読み込まれていない場合、既に稼働終了している場合、または稼働予定が存在する場合にスローされます。
355
+ */
356
+ async terminate() {
357
+ // 自身が `docId` を持っていない場合はエラーをスロー(インスタンスにドキュメントが読み込まれていない)
358
+ if (!this.docId) {
359
+ throw new Error(
360
+ "ドキュメントが読み込まれていないため、現場を稼働終了できません。",
361
+ );
362
+ }
363
+
364
+ // 既に稼働終了している場合はエラーをスロー
365
+ if (this.status === Site.STATUS_TERMINATED) {
366
+ throw new Error("既に稼働終了している現場です。");
367
+ }
368
+
369
+ // 現在日時の JST 日付文字列を取得
370
+ const nowJst = formatJstDate(new Date(), "YYYY-MM-DD");
371
+
372
+ // 現在日付以降の SiteOperationSchedule ドキュメントを取得
373
+ const scheduleInstance = new SiteOperationSchedule();
374
+ const futureScheduleDocs = await scheduleInstance.fetchDocs({
375
+ constraints: [
376
+ ["where", "siteId", "==", this.docId],
377
+ ["where", "date", ">=", nowJst],
378
+ ["limit", 1],
379
+ ],
380
+ });
381
+
382
+ // SiteOperationSchedule ドキュメントが存在する場合はエラーをスロー
383
+ if (futureScheduleDocs.length > 0) {
384
+ throw new Error(
385
+ "稼働予定が存在するため、現場を終了させることはできません。先に稼働予定を削除する必要があります。",
386
+ );
387
+ }
388
+
389
+ // 状態を稼働終了に更新して保存
390
+ this.status = Site.STATUS_TERMINATED;
391
+ return await this.update();
392
+ }
348
393
  }
@@ -1,3 +1,5 @@
1
+ import { getDateAt } from "../../utils/index.js";
2
+
1
3
  /**
2
4
  * フィールド定義のデフォルト値
3
5
  * - `air-firebase` が提供する `FireModel (BaseClass)` において、クラスが保有するフィールドの定義および値の検証に使用されます。
@@ -55,11 +57,7 @@ export const generalDefinitions = {
55
57
  ...defaultDefinition,
56
58
  type: Object,
57
59
  label: "日付",
58
- default: () => {
59
- const date = new Date();
60
- date.setHours(0, 0, 0, 0);
61
- return date;
62
- },
60
+ default: () => getDateAt(new Date(), "00:00"),
63
61
  component: {
64
62
  name: "air-date-input",
65
63
  },
@@ -72,7 +72,7 @@ export const oneLineFields = {
72
72
  component: {
73
73
  name: generalDefinitions.oneLine.component.name,
74
74
  attrs: {
75
- inputType: "katakana",
75
+ inputType: "katakana-numeric",
76
76
  },
77
77
  },
78
78
  },
@@ -223,7 +223,7 @@ export const oneLineFields = {
223
223
  component: {
224
224
  name: generalDefinitions.oneLine.component.name,
225
225
  attrs: {
226
- inputType: "katakana",
226
+ inputType: "katakana-numeric",
227
227
  },
228
228
  },
229
229
  },
@@ -271,7 +271,7 @@ export const oneLineFields = {
271
271
  component: {
272
272
  name: generalDefinitions.oneLine.component.name,
273
273
  attrs: {
274
- inputType: "katakana",
274
+ inputType: "katakana-numeric",
275
275
  },
276
276
  },
277
277
  },
@@ -313,7 +313,7 @@ export const oneLineFields = {
313
313
  component: {
314
314
  name: generalDefinitions.oneLine.component.name,
315
315
  attrs: {
316
- inputType: "katakana",
316
+ inputType: "katakana-numeric",
317
317
  },
318
318
  },
319
319
  },
@@ -66,7 +66,7 @@ export function getDateAt(date, time, dateOffset = 0) {
66
66
  * @example
67
67
  * // YYYY-MM-DD形式
68
68
  * formatJstDate(new Date('2024-03-04T15:00:00Z')) // '2024-03-05'
69
- *
69
+ *
70
70
  * // YYYY-MM形式
71
71
  * formatJstDate(new Date('2024-03-04T15:00:00Z'), 'YYYY-MM') // '2024-03'
72
72
  */