@shisyamo4131/air-guard-v2-schemas 2.3.7-dev.21 → 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.21",
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.
@@ -154,30 +163,50 @@ export default class Employee extends FireModel {
154
163
 
155
164
  /**
156
165
  * 生年月日から年齢を計算します。
157
- * @returns {number|null} 年齢。dateOfBirthが設定されていない場合はnull。
166
+ * @returns {{years: number, months: number}|null} 年齢(年数と月数)。dateOfBirthが設定されていない場合はnull。
158
167
  */
159
168
  get age() {
160
169
  if (!this.dateOfBirth) return null;
161
170
  const today = new Date();
162
- let age = today.getUTCFullYear() - this.dateOfBirth.getUTCFullYear();
163
- const m = today.getUTCMonth() - this.dateOfBirth.getUTCMonth();
164
- const d = today.getUTCDate() - this.dateOfBirth.getUTCDate();
165
- if (m < 0 || (m === 0 && d < 0)) age--;
166
- return age;
171
+
172
+ let years = today.getUTCFullYear() - this.dateOfBirth.getUTCFullYear();
173
+ let months = today.getUTCMonth() - this.dateOfBirth.getUTCMonth();
174
+ const days = today.getUTCDate() - this.dateOfBirth.getUTCDate();
175
+
176
+ if (days < 0) {
177
+ months--;
178
+ }
179
+
180
+ if (months < 0) {
181
+ years--;
182
+ months += 12;
183
+ }
184
+
185
+ return { years, months };
167
186
  }
168
187
 
169
188
  /**
170
189
  * 入社日からの勤続年数を計算します。
171
- * @returns {number|null} 勤続年数。dateOfHireが設定されていない場合はnull。
190
+ * @returns {{years: number, months: number}|null} 勤続年数(年数と月数)。dateOfHireが設定されていない場合はnull。
172
191
  */
173
192
  get yearsOfService() {
174
193
  if (!this.dateOfHire) return null;
175
194
  const today = new Date();
195
+
176
196
  let years = today.getUTCFullYear() - this.dateOfHire.getUTCFullYear();
177
- const m = today.getUTCMonth() - this.dateOfHire.getUTCMonth();
178
- const d = today.getUTCDate() - this.dateOfHire.getUTCDate();
179
- if (m < 0 || (m === 0 && d < 0)) years--;
180
- return years;
197
+ let months = today.getUTCMonth() - this.dateOfHire.getUTCMonth();
198
+ const days = today.getUTCDate() - this.dateOfHire.getUTCDate();
199
+
200
+ if (days < 0) {
201
+ months--;
202
+ }
203
+
204
+ if (months < 0) {
205
+ years--;
206
+ months += 12;
207
+ }
208
+
209
+ return { years, months };
181
210
  }
182
211
 
183
212
  /**
@@ -225,7 +254,10 @@ export default class Employee extends FireModel {
225
254
  /**
226
255
  * 退職済である場合の必須フィールドを検証します。
227
256
  * - エラーがある場合は例外をスローします。
228
- * - `employmentStatus` が `active` の場合、`dateOfTermination` を初期化します。
257
+ * - `employmentStatus` が `terminated` の場合、以下のプロパティを必須とします。
258
+ * - `dateOfTermination`
259
+ * - `reasonOfTermination`
260
+ * - `employmentStatus` が `active` の場合、`dateOfTermination`, `reasonOfTermination` を初期化します。
229
261
  * @returns {void}
230
262
  * @throws {Error} 退職済の場合に必須フィールドが未入力の場合。
231
263
  */
@@ -236,8 +268,14 @@ export default class Employee extends FireModel {
236
268
  "[Employee.js] dateOfTermination is required when employmentStatus is 'terminated'."
237
269
  );
238
270
  }
271
+ if (!this.reasonOfTermination) {
272
+ throw new Error(
273
+ "[Employee.js] reasonOfTermination is required when employmentStatus is 'terminated'."
274
+ );
275
+ }
239
276
  } else {
240
277
  this.dateOfTermination = null;
278
+ this.reasonOfTermination = null;
241
279
  }
242
280
  }
243
281
 
@@ -281,6 +319,7 @@ export default class Employee extends FireModel {
281
319
  /**
282
320
  * 現在インスタンスに読み込まれている従業員を退職状態に変更します。
283
321
  * @param {Date} dateOfTermination - 退職日(Dateオブジェクト)
322
+ * @param {string} reasonOfTermination - 退職理由
284
323
  * @param {Object} options - パラメータオブジェクト
285
324
  * @param {Function|null} [options.transaction=null] - Firestore トランザクション関数
286
325
  * @param {Function|null} [options.callBack=null] - カスタム処理用コールバック
@@ -288,7 +327,7 @@ export default class Employee extends FireModel {
288
327
  * @returns {Promise<DocumentReference>} 更新されたドキュメントの参照
289
328
  * @throws {Error} docIdが存在しない場合、または有効なdateOfTerminationが提供されていない場合。
290
329
  */
291
- async toTerminated(dateOfTermination, options = {}) {
330
+ async toTerminated(dateOfTermination, reasonOfTermination, options = {}) {
292
331
  if (!this.docId) {
293
332
  throw new Error(
294
333
  "[Employee.js] docId is required to terminate an employee."
@@ -299,14 +338,29 @@ export default class Employee extends FireModel {
299
338
  "[Employee.js] A valid dateOfTermination is required to terminate an employee."
300
339
  );
301
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
+ }
302
352
 
303
353
  this.employmentStatus = Employee.STATUS_TERMINATED;
304
354
  this.dateOfTermination = dateOfTermination;
355
+ this.reasonOfTermination = reasonOfTermination;
305
356
 
306
357
  this._skipToTerminatedCheck = true;
307
358
 
308
359
  try {
309
360
  return await this.update(options);
361
+ } catch (error) {
362
+ this.rollback();
363
+ throw error;
310
364
  } finally {
311
365
  this._skipToTerminatedCheck = false;
312
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: "現場",