@shisyamo4131/air-guard-v2-schemas 2.3.7-dev.19 → 2.3.7-dev.20
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 +1 -1
- package/src/Employee.js +23 -0
package/package.json
CHANGED
package/src/Employee.js
CHANGED
|
@@ -253,7 +253,30 @@ export default class Employee extends FireModel {
|
|
|
253
253
|
*/
|
|
254
254
|
async beforeUpdate() {
|
|
255
255
|
await super.beforeUpdate();
|
|
256
|
+
if (this.employmentStatus !== this._beforeData.employmentStatus) {
|
|
257
|
+
throw new Error(
|
|
258
|
+
"[Employee.js] employmentStatus cannot be changed via update. Use toTerminated() method to change status to terminated."
|
|
259
|
+
);
|
|
260
|
+
}
|
|
256
261
|
this._validateForeignerRequiredFields();
|
|
257
262
|
this._validateTerminatedRequiredFields();
|
|
258
263
|
}
|
|
264
|
+
|
|
265
|
+
async toTerminated(dateOfTermination) {
|
|
266
|
+
if (!this.docId) {
|
|
267
|
+
throw new Error(
|
|
268
|
+
"[Employee.js] docId is required to terminate an employee."
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
if (!dateOfTermination || !(dateOfTermination instanceof Date)) {
|
|
272
|
+
throw new Error(
|
|
273
|
+
"[Employee.js] A valid dateOfTermination is required to terminate an employee."
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
this.employmentStatus = Employee.STATUS_TERMINATED;
|
|
278
|
+
this.dateOfTermination = dateOfTermination;
|
|
279
|
+
|
|
280
|
+
await FireModel.prototype.update.call(this);
|
|
281
|
+
}
|
|
259
282
|
}
|