@shisyamo4131/air-guard-v2-schemas 2.3.7-dev.22 → 2.3.7-dev.23

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.22",
3
+ "version": "2.3.7-dev.23",
4
4
  "description": "Schemas for AirGuard V2",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/src/Employee.js CHANGED
@@ -37,6 +37,14 @@ const classProps = {
37
37
  },
38
38
  },
39
39
  }),
40
+ reasonOfTermination: defField("reasonOfTermination", {
41
+ component: {
42
+ attrs: {
43
+ required: (item) => item.employmentStatus === VALUES.TERMINATED.value,
44
+ disabled: (item) => item.employmentStatus !== VALUES.TERMINATED.value,
45
+ },
46
+ },
47
+ }),
40
48
  isForeigner: defField("isForeigner"),
41
49
  foreignName: defField("foreignName", {
42
50
  component: {
@@ -94,6 +102,7 @@ const classProps = {
94
102
  * @prop {string} employmentStatus - Employment status.
95
103
  * @prop {string} title - Job title.
96
104
  * @prop {Date} dateOfTermination - Date of termination.
105
+ * @prop {string} reasonOfTermination - Reason for termination.
97
106
  * @prop {boolean} isForeigner - Is the employee a foreigner.
98
107
  * @prop {string} foreignName - Foreign name.
99
108
  * @prop {string} nationality - Nationality.
@@ -245,7 +254,10 @@ export default class Employee extends FireModel {
245
254
  /**
246
255
  * 退職済である場合の必須フィールドを検証します。
247
256
  * - エラーがある場合は例外をスローします。
248
- * - `employmentStatus` が `active` の場合、`dateOfTermination` を初期化します。
257
+ * - `employmentStatus` が `terminated` の場合、以下のプロパティを必須とします。
258
+ * - `dateOfTermination`
259
+ * - `reasonOfTermination`
260
+ * - `employmentStatus` が `active` の場合、`dateOfTermination`, `reasonOfTermination` を初期化します。
249
261
  * @returns {void}
250
262
  * @throws {Error} 退職済の場合に必須フィールドが未入力の場合。
251
263
  */
@@ -256,8 +268,14 @@ export default class Employee extends FireModel {
256
268
  "[Employee.js] dateOfTermination is required when employmentStatus is 'terminated'."
257
269
  );
258
270
  }
271
+ if (!this.reasonOfTermination) {
272
+ throw new Error(
273
+ "[Employee.js] reasonOfTermination is required when employmentStatus is 'terminated'."
274
+ );
275
+ }
259
276
  } else {
260
277
  this.dateOfTermination = null;
278
+ this.reasonOfTermination = null;
261
279
  }
262
280
  }
263
281
 
@@ -301,6 +319,7 @@ export default class Employee extends FireModel {
301
319
  /**
302
320
  * 現在インスタンスに読み込まれている従業員を退職状態に変更します。
303
321
  * @param {Date} dateOfTermination - 退職日(Dateオブジェクト)
322
+ * @param {string} reasonOfTermination - 退職理由
304
323
  * @param {Object} options - パラメータオブジェクト
305
324
  * @param {Function|null} [options.transaction=null] - Firestore トランザクション関数
306
325
  * @param {Function|null} [options.callBack=null] - カスタム処理用コールバック
@@ -308,7 +327,7 @@ export default class Employee extends FireModel {
308
327
  * @returns {Promise<DocumentReference>} 更新されたドキュメントの参照
309
328
  * @throws {Error} docIdが存在しない場合、または有効なdateOfTerminationが提供されていない場合。
310
329
  */
311
- async toTerminated(dateOfTermination, options = {}) {
330
+ async toTerminated(dateOfTermination, reasonOfTermination, options = {}) {
312
331
  if (!this.docId) {
313
332
  throw new Error(
314
333
  "[Employee.js] docId is required to terminate an employee."
@@ -319,14 +338,29 @@ export default class Employee extends FireModel {
319
338
  "[Employee.js] A valid dateOfTermination is required to terminate an employee."
320
339
  );
321
340
  }
341
+ if (dateOfTermination < this.dateOfHire) {
342
+ throw new Error(
343
+ "[Employee.js] dateOfTermination cannot be earlier than dateOfHire."
344
+ );
345
+ }
346
+
347
+ if (!reasonOfTermination || typeof reasonOfTermination !== "string") {
348
+ throw new Error(
349
+ "[Employee.js] A valid reasonOfTermination is required to terminate an employee."
350
+ );
351
+ }
322
352
 
323
353
  this.employmentStatus = Employee.STATUS_TERMINATED;
324
354
  this.dateOfTermination = dateOfTermination;
355
+ this.reasonOfTermination = reasonOfTermination;
325
356
 
326
357
  this._skipToTerminatedCheck = true;
327
358
 
328
359
  try {
329
360
  return await this.update(options);
361
+ } catch (error) {
362
+ this.rollback();
363
+ throw error;
330
364
  } finally {
331
365
  this._skipToTerminatedCheck = false;
332
366
  }
@@ -357,6 +357,11 @@ export const fieldDefinitions = {
357
357
  label: "在留資格",
358
358
  length: 10,
359
359
  },
360
+ reasonOfTermination: {
361
+ ...generalDefinitions.oneLine,
362
+ label: "退職理由",
363
+ length: 20,
364
+ },
360
365
  siteId: {
361
366
  ...generalDefinitions.oneLine,
362
367
  label: "現場",