@shisyamo4131/air-guard-v2-schemas 2.3.7-dev.16 → 2.3.7-dev.18

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.16",
3
+ "version": "2.3.7-dev.18",
4
4
  "description": "Schemas for AirGuard V2",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/src/Employee.js CHANGED
@@ -15,9 +15,8 @@ const classProps = {
15
15
  lastNameKana: defField("lastNameKana", { required: true }),
16
16
  firstNameKana: defField("firstNameKana", { required: true }),
17
17
  displayName: defField("displayName", { required: true }),
18
- title: defField("oneLine", { label: "肩書", required: true }),
19
18
  gender: defField("gender", { required: true }),
20
- dateOfBirth: defField("dateAt", { label: "生年月日", required: true }),
19
+ dateOfBirth: defField("dateOfBirth", { required: true }),
21
20
  zipcode: defField("zipcode", { required: true }),
22
21
  prefCode: defField("prefCode", { required: true }),
23
22
  city: defField("city", { required: true }),
@@ -26,10 +25,10 @@ const classProps = {
26
25
  location: defField("location", { hidden: true }), // 非表示でOK
27
26
  mobile: defField("mobile", { required: true }),
28
27
  email: defField("email", { required: false }),
29
- dateOfHire: defField("dateAt", { label: "入社日", required: true }),
28
+ dateOfHire: defField("dateOfHire", { required: true }),
30
29
  employmentStatus: defField("employmentStatus", { required: true }),
31
- dateOfTermination: defField("dateAt", {
32
- label: "退職日",
30
+ title: defField("title"),
31
+ dateOfTermination: defField("dateOfTermination", {
33
32
  default: null,
34
33
  component: {
35
34
  attrs: {
@@ -42,6 +41,7 @@ const classProps = {
42
41
  component: {
43
42
  attrs: {
44
43
  required: (item) => item.isForeigner,
44
+ disabled: (item) => !item.isForeigner,
45
45
  },
46
46
  },
47
47
  }),
@@ -52,60 +52,61 @@ const classProps = {
52
52
  },
53
53
  },
54
54
  }),
55
- residenceStatus: {
56
- type: String,
57
- default: null,
58
- label: "在留資格",
59
- required: undefined,
55
+ residenceStatus: defField("residenceStatus", {
60
56
  component: {
61
- name: "air-text-field",
62
57
  attrs: {
63
58
  required: (item) => item.isForeigner,
64
59
  },
65
60
  },
66
- },
67
- periodOfStay: defField("dateAt", {
68
- label: "在留期間満了日",
61
+ }),
62
+ periodOfStay: defField("periodOfStay", {
69
63
  component: {
70
64
  attrs: {
71
65
  required: (item) => item.isForeigner,
72
66
  },
73
67
  },
74
68
  }),
75
- remarks: defField("multipleLine", { label: "備考" }),
69
+ remarks: defField("remarks"),
76
70
  };
77
71
 
78
72
  /*****************************************************************************
79
- * Employee Model
80
- * @props {string} code - Employee code.
81
- * @props {string} lastName - Last name.
82
- * @props {string} firstName - First name.
83
- * @props {string} lastNameKana - Last name in Kana.
84
- * @props {string} firstNameKana - First name in Kana.
85
- * @props {string} displayName - Display name.
86
- * @props {string} title - Job title.
87
- * @props {string} gender - Gender.
88
- * @props {Date} dateOfBirth - Date of birth.
89
- * @props {string} zipcode - Postal code.
90
- * @props {string} prefCode - Prefecture code.
91
- * @props {string} city - City name.
92
- * @props {string} address - Address details.
93
- * @props {string} building - Building name.
94
- * @props {object} location - Geographical location.
95
- * @props {string} mobile - Mobile phone number.
96
- * @props {string} email - Email address.
97
- * @props {Date} dateOfHire - Date of hire.
98
- * @props {string} employmentStatus - Employment status.
99
- * @props {Date} dateOfTermination - Date of termination.
100
- * @props {boolean} isForeigner - Is the employee a foreigner.
101
- * @props {string} foreignName - Foreign name.
102
- * @props {string} nationality - Nationality.
103
- * @props {string} residenceStatus - Residence status.
104
- * @props {Date} periodOfStay - Period of stay expiration date.
105
- * @props {string} remarks - Additional remarks.
106
- * @computed {string} fullName - Full name combining last and first names (read-only)
107
- * @computed {string} fullAddress - Full address combining prefecture, city, and address (read-only)
108
- * @computed {string} prefecture - Prefecture name derived from `prefCode` (read-only)
73
+ * @prop {string} code - Employee code.
74
+ * @prop {string} lastName - Last name.
75
+ * @prop {string} firstName - First name.
76
+ * @prop {string} lastNameKana - Last name in Kana.
77
+ * @prop {string} firstNameKana - First name in Kana.
78
+ * @prop {string} displayName - Display name.
79
+ * @prop {string} gender - Gender.
80
+ * @prop {Date} dateOfBirth - Date of birth.
81
+ * @prop {string} zipcode - Postal code.
82
+ * @prop {string} prefCode - Prefecture code.
83
+ * @prop {string} city - City name.
84
+ * @prop {string} address - Address details.
85
+ * @prop {string} building - Building name.
86
+ * @prop {object} location - Geographical location.
87
+ * @prop {string} mobile - Mobile phone number.
88
+ * @prop {string} email - Email address.
89
+ * @prop {Date} dateOfHire - Date of hire.
90
+ * @prop {string} employmentStatus - Employment status.
91
+ * @prop {string} title - Job title.
92
+ * @prop {Date} dateOfTermination - Date of termination.
93
+ * @prop {boolean} isForeigner - Is the employee a foreigner.
94
+ * @prop {string} foreignName - Foreign name.
95
+ * @prop {string} nationality - Nationality.
96
+ * @prop {string} residenceStatus - Residence status.
97
+ * @prop {Date} periodOfStay - Period of stay expiration date.
98
+ * @prop {string} remarks - Additional remarks.
99
+ *
100
+ * @prop {string} fullName - Full name combining last and first names (read-only)
101
+ * @prop {string} fullNameKana - Full name in Kana combining last and first names (read-only)
102
+ * @prop {string} fullAddress - Full address combining prefecture, city, and address (read-only)
103
+ * @prop {string} prefecture - Prefecture name derived from `prefCode` (read-only)
104
+ * @prop {number} age - Age calculated from `dateOfBirth` (read-only)
105
+ * @prop {number} yearsOfService - Years of service calculated from `dateOfHire` (read-only)
106
+ *
107
+ * @static
108
+ * @prop {string} STATUS_ACTIVE - constant for active employment status
109
+ * @prop {string} STATUS_TERMINATED - constant for terminated employment status
109
110
  *****************************************************************************/
110
111
  export default class Employee extends FireModel {
111
112
  static className = "従業員";
@@ -114,6 +115,7 @@ export default class Employee extends FireModel {
114
115
  static logicalDelete = true;
115
116
  static classProps = classProps;
116
117
  static tokenFields = [
118
+ "code",
117
119
  "lastName",
118
120
  "firstName",
119
121
  "lastNameKana",
@@ -134,14 +136,50 @@ export default class Employee extends FireModel {
134
136
  super.afterInitialize(item);
135
137
  Object.defineProperties(this, {
136
138
  fullName: defAccessor("fullName"),
139
+ fullNameKana: defAccessor("fullNameKana"),
137
140
  fullAddress: defAccessor("fullAddress"),
138
141
  prefecture: defAccessor("prefecture"),
142
+ age: {
143
+ enumerable: true,
144
+ configurable: true,
145
+ get() {
146
+ if (!this.dateOfBirth) return null;
147
+ const today = new Date();
148
+ let age = today.getUTCFullYear() - this.dateOfBirth.getUTCFullYear();
149
+ const m = today.getUTCMonth() - this.dateOfBirth.getUTCMonth();
150
+ const d = today.getUTCDate() - this.dateOfBirth.getUTCDate();
151
+ if (m < 0 || (m === 0 && d < 0)) age--;
152
+ return age;
153
+ },
154
+ set() {},
155
+ },
156
+ yearsOfService: {
157
+ enumerable: true,
158
+ configurable: true,
159
+ get() {
160
+ if (!this.dateOfHire) return null;
161
+ const today = new Date();
162
+ let years = today.getUTCFullYear() - this.dateOfHire.getUTCFullYear();
163
+ const m = today.getUTCMonth() - this.dateOfHire.getUTCMonth();
164
+ const d = today.getUTCDate() - this.dateOfHire.getUTCDate();
165
+ if (m < 0 || (m === 0 && d < 0)) years--;
166
+ return years;
167
+ },
168
+ set() {},
169
+ },
139
170
  });
140
171
  }
141
172
 
142
173
  /**
143
174
  * 外国籍の場合の必須フィールドを検証します。
144
- * エラーがある場合は例外をスローします。
175
+ * - エラーがある場合は例外をスローします。
176
+ * - `isForeigner` が false の場合、以下のプロパティを初期化します。
177
+ * - `foreignName`
178
+ * - `nationality`
179
+ * - `residenceStatus`
180
+ * - `periodOfStay`
181
+ * @returns {void}
182
+ * @throws {Error} 外国籍の場合に必須フィールドが未入力の場合。
145
183
  */
146
184
  _validateForeignerRequiredFields() {
147
185
  if (this.isForeigner) {
@@ -165,20 +203,31 @@ export default class Employee extends FireModel {
165
203
  "[Employee.js] periodOfStay is required when isForeigner is true."
166
204
  );
167
205
  }
206
+ } else {
207
+ // 外国籍でない場合、関連フィールドを初期化
208
+ this.foreignName = null;
209
+ this.nationality = null;
210
+ this.residenceStatus = null;
211
+ this.periodOfStay = null;
168
212
  }
169
213
  }
170
214
 
171
215
  /**
172
216
  * 退職済である場合の必須フィールドを検証します。
173
- * エラーがある場合は例外をスローします。
217
+ * - エラーがある場合は例外をスローします。
218
+ * - `employmentStatus` が `active` の場合、`dateOfTermination` を初期化します。
219
+ * @returns {void}
220
+ * @throws {Error} 退職済の場合に必須フィールドが未入力の場合。
174
221
  */
175
222
  _validateTerminatedRequiredFields() {
176
- if (this.employmentStatus === "terminated") {
223
+ if (this.employmentStatus === VALUES.TERMINATED.value) {
177
224
  if (!this.dateOfTermination) {
178
225
  throw new Error(
179
226
  "[Employee.js] dateOfTermination is required when employmentStatus is 'terminated'."
180
227
  );
181
228
  }
229
+ } else {
230
+ this.dateOfTermination = null;
182
231
  }
183
232
  }
184
233
 
@@ -11,16 +11,12 @@ import { OPTIONS } from "../constants/prefectures.js";
11
11
  */
12
12
  const accessorImplementations = {
13
13
  customerId: {
14
- enumerable: true,
15
14
  get() {
16
15
  return this?.customer?.docId;
17
16
  },
18
- set(value) {
19
- // No-op setter for read-only access
20
- },
17
+ set() {},
21
18
  },
22
19
  fullAddress: {
23
- enumerable: true,
24
20
  get() {
25
21
  // 同じオブジェクトに 'prefecture' アクセサが定義されていることを前提とします
26
22
  const prefecture = this.prefecture || "";
@@ -28,53 +24,41 @@ const accessorImplementations = {
28
24
  const address = this.address || "";
29
25
  return `${prefecture}${city}${address}`;
30
26
  },
31
- set(value) {
32
- // No-op setter for read-only access
33
- },
27
+ set() {},
34
28
  },
35
29
  fullName: {
36
- enumerable: true,
37
30
  get() {
38
31
  if (!this.lastName || !this.firstName) return "";
39
32
  return `${this.lastName} ${this.firstName}`;
40
33
  },
41
- set(value) {
42
- // No-op setter for read-only access
34
+ set() {},
35
+ },
36
+ fullNameKana: {
37
+ get() {
38
+ if (!this.lastNameKana || !this.firstNameKana) return "";
39
+ return `${this.lastNameKana} ${this.firstNameKana}`;
43
40
  },
41
+ set() {},
44
42
  },
45
43
  prefecture: {
46
- enumerable: true,
47
44
  get() {
48
- // if (!this.hasOwnProperty("prefCode")) {
49
- // console.warn(
50
- // "[アクセサ: prefecture] このオブジェクトに prefCode が定義されていません。"
51
- // );
52
- // return "";
53
- // }
54
-
55
45
  if (!this.prefCode) return ""; // No warning if prefCode is falsy but present
56
-
57
46
  const result = OPTIONS.find(({ value }) => value === this.prefCode);
58
-
59
47
  if (!result) {
60
48
  console.warn(
61
49
  `[アクセサ: prefecture] prefCode '${this.prefCode}' は OPTIONS に見つかりません。`
62
50
  );
63
51
  return "";
64
52
  }
65
-
66
53
  if (!result.hasOwnProperty("title")) {
67
54
  console.warn(
68
55
  `[アクセサ: prefecture] OPTIONS の prefCode '${this.prefCode}' に title が定義されていません。`
69
56
  );
70
57
  return "";
71
58
  }
72
-
73
59
  return result.title;
74
60
  },
75
- set(value) {
76
- // No-op setter for read-only access
77
- },
61
+ set() {},
78
62
  },
79
63
  };
80
64
 
@@ -90,7 +74,7 @@ const accessorImplementations = {
90
74
  */
91
75
  export const defAccessor = (
92
76
  key,
93
- { configurable = false, enumerable = false } = {}
77
+ { configurable = true, enumerable = true } = {}
94
78
  ) => {
95
79
  const implementation = accessorImplementations[key];
96
80
  if (!implementation) {
@@ -147,11 +147,30 @@ export const fieldDefinitions = {
147
147
  code: generalDefinitions.code,
148
148
  /** dateAt */
149
149
  dateAt: generalDefinitions.dateAt,
150
+ dateOfBirth: {
151
+ ...generalDefinitions.dateAt,
152
+ label: "生年月日",
153
+ },
154
+ dateOfHire: {
155
+ ...generalDefinitions.dateAt,
156
+ label: "入社日",
157
+ },
158
+ dateOfTermination: {
159
+ ...generalDefinitions.dateAt,
160
+ label: "退職日",
161
+ },
162
+ periodOfStay: {
163
+ ...generalDefinitions.dateAt,
164
+ label: "在留期間満了日",
165
+ },
150
166
  /** dateTimeAt */
151
167
  dateTimeAt: generalDefinitions.dateTimeAt,
152
168
  /** multiple-line */
153
169
  multipleLine: generalDefinitions.multipleLine,
154
-
170
+ remarks: {
171
+ ...generalDefinitions.multipleLine,
172
+ label: "備考",
173
+ },
155
174
  /** number */
156
175
  number: generalDefinitions.number,
157
176
  breakMinutes: {
@@ -333,6 +352,11 @@ export const fieldDefinitions = {
333
352
  label: "国籍",
334
353
  length: 50,
335
354
  },
355
+ residenceStatus: {
356
+ ...generalDefinitions.oneLine,
357
+ label: "在留資格",
358
+ length: 10,
359
+ },
336
360
  siteId: {
337
361
  ...generalDefinitions.oneLine,
338
362
  label: "現場",
@@ -357,6 +381,11 @@ export const fieldDefinitions = {
357
381
  },
358
382
  },
359
383
  },
384
+ title: {
385
+ ...generalDefinitions.oneLine,
386
+ label: "肩書",
387
+ length: 20,
388
+ },
360
389
  workDescription: {
361
390
  ...generalDefinitions.oneLine,
362
391
  label: "作業内容",