@shisyamo4131/air-guard-v2-schemas 2.4.2-dev.10 → 2.4.2-dev.11

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Company.js +102 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shisyamo4131/air-guard-v2-schemas",
3
- "version": "2.4.2-dev.10",
3
+ "version": "2.4.2-dev.11",
4
4
  "description": "Schemas for AirGuard V2",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/src/Company.js CHANGED
@@ -1,14 +1,7 @@
1
- /**
1
+ /*****************************************************************************
2
2
  * Company Model
3
- * @version 1.0.0
4
3
  * @author shisyamo4131
5
- * @update 2026-01-06 - Add `firstDayOfWeek` property.
6
- * @update 2025-12-29 - Add `isCompleteRequiredFields` computed property.
7
- * @update 2025-12-02 - Add maintenance information properties.
8
- * @update 2025-12-01 - Add Stripe integration fields (stripeCustomerId, subscription).
9
- * @update 2025-11-27 - Add bank information fields for billing.
10
- * @update 2025-11-23 - Set `usePrefix` to false.
11
- */
4
+ *****************************************************************************/
12
5
  import FireModel from "@shisyamo4131/air-firebase-v2";
13
6
  import { defField } from "./parts/fieldDefinitions.js";
14
7
  import { defAccessor } from "./parts/accessorDefinitions.js";
@@ -56,11 +49,19 @@ const classProps = {
56
49
  }),
57
50
 
58
51
  /**
59
- * Field to manage the display order of site-shift type pairs for placement management.
52
+ * Property to manage the display order of site-shift type pairs for arrangement management.
60
53
  * Format: { siteId, shiftType }
54
+ * NOTE: `key` is a unique identifier combined from siteId and shiftType.
61
55
  */
62
56
  siteOrder: defField("array", { customClass: SiteOrder, hidden: true }),
63
57
 
58
+ /**
59
+ * Property to manage the display order of site-shift type pairs for site-operation-schedule.
60
+ * Format: { siteId, shiftType, key }
61
+ * NOTE: `key` is a unique identifier combined from siteId and shiftType.
62
+ */
63
+ scheduleOrder: defField("array", { customClass: SiteOrder, hidden: true }),
64
+
64
65
  /** Geolocation */
65
66
  location: defField("location", { hidden: true }),
66
67
 
@@ -203,7 +204,7 @@ export default class Company extends GeocodableMixin(FireModel) {
203
204
  const newOrder = new SiteOrder({ siteId, shiftType });
204
205
  if (this.some((order) => order.key === newOrder.key)) {
205
206
  throw new Error(
206
- `SiteOrder with key ${newOrder.key} already exists.`
207
+ `SiteOrder with key ${newOrder.key} already exists.`,
207
208
  );
208
209
  }
209
210
  index === -1 ? this.push(newOrder) : this.splice(index, 0, newOrder);
@@ -253,13 +254,101 @@ export default class Company extends GeocodableMixin(FireModel) {
253
254
  key = `${arg.siteId}-${arg.shiftType}`;
254
255
  } else {
255
256
  throw new Error(
256
- "Invalid argument for remove. Must be a string key or an object with siteId and shiftType."
257
+ "Invalid argument for remove. Must be a string key or an object with siteId and shiftType.",
258
+ );
259
+ }
260
+
261
+ const index = this.findIndex((order) => order.key === key);
262
+ if (index === -1) {
263
+ throw new Error(`ScheduleOrder with key ${key} does not exist.`);
264
+ }
265
+
266
+ this.splice(index, 1);
267
+ },
268
+ writable: false,
269
+ enumerable: false,
270
+ configurable: true,
271
+ },
272
+ });
273
+
274
+ /*************************************************************************
275
+ * CUSTOM METHODS FOR scheduleOrder ARRAY
276
+ * Note: These methods modify the scheduleOrder array directly.
277
+ * The Company instance itself is not updated by these methods.
278
+ * Use the provided public methods to interact with scheduleOrder.
279
+ *************************************************************************/
280
+ Object.defineProperties(this.scheduleOrder, {
281
+ /**
282
+ * Inserts a new ScheduleOrder into the `scheduleOrder` array.
283
+ * @param {Object} params - The parameters for the ScheduleOrder.
284
+ * @param {string} params.siteId - The ID of the site.
285
+ * @param {string} params.shiftType - The shift type associated with the site.
286
+ * @param {number} [index=-1] - The position to insert the new ScheduleOrder. Defaults to the end.
287
+ * @returns {ScheduleOrder} The newly created ScheduleOrder instance.
288
+ * @throws {Error} If a ScheduleOrder with the same key already exists.
289
+ */
290
+ add: {
291
+ value: function ({ siteId, shiftType }, index = -1) {
292
+ const newOrder = new ScheduleOrder({ siteId, shiftType });
293
+ if (this.some((order) => order.key === newOrder.key)) {
294
+ throw new Error(
295
+ `ScheduleOrder with key ${newOrder.key} already exists.`,
296
+ );
297
+ }
298
+ index === -1 ? this.push(newOrder) : this.splice(index, 0, newOrder);
299
+ return newOrder;
300
+ },
301
+ writable: false,
302
+ enumerable: false,
303
+ configurable: true,
304
+ },
305
+ /**
306
+ * Changes the order of a ScheduleOrder in the scheduleOrder array.
307
+ * Note: Company instance does not be updated by this method.
308
+ * @param {number} oldIndex - The current index of the ScheduleOrder.
309
+ * @param {number} newIndex - The new index to move the ScheduleOrder to.
310
+ * @returns {void}
311
+ * @throws {Error} If oldIndex or newIndex are out of bounds.
312
+ */
313
+ change: {
314
+ value: function (oldIndex, newIndex) {
315
+ const length = this.length;
316
+ if (oldIndex < 0 || oldIndex >= length) {
317
+ throw new Error("Invalid oldIndex for site order change.");
318
+ }
319
+ if (newIndex < 0 || newIndex >= length) {
320
+ throw new Error("Invalid newIndex for site order change.");
321
+ }
322
+ const [movedOrder] = this.splice(oldIndex, 1);
323
+ this.splice(newIndex, 0, movedOrder);
324
+ },
325
+ writable: false,
326
+ enumerable: false,
327
+ configurable: true,
328
+ },
329
+ /**
330
+ * Removes a ScheduleOrder from the scheduleOrder array.
331
+ * Note: Company instance does not be updated by this method.
332
+ * @param {string|Object} arg - The key or {siteId, shiftType} of the ScheduleOrder to remove.
333
+ * @returns {void}
334
+ * @throws {Error} If the ScheduleOrder does not exist or if the argument is invalid.
335
+ */
336
+ remove: {
337
+ value: function (arg) {
338
+ let key = "";
339
+ if (typeof arg === "string") {
340
+ key = arg;
341
+ } else if (typeof arg === "object" && arg.siteId && arg.shiftType) {
342
+ key = `${arg.siteId}-${arg.shiftType}`;
343
+ } else {
344
+ throw new Error(
345
+ "Invalid argument for remove. Must be a string key or an object with siteId and shiftType.",
257
346
  );
258
347
  }
259
348
 
260
349
  const index = this.findIndex((order) => order.key === key);
261
350
  if (index === -1) {
262
- throw new Error(`SiteOrder with key ${key} does not exist.`);
351
+ throw new Error(`ScheduleOrder with key ${key} does not exist.`);
263
352
  }
264
353
 
265
354
  this.splice(index, 1);