Skip to content

Commit

Permalink
add beforeUpdate and afterUpdate to prevent update from ATS
Browse files Browse the repository at this point in the history
  • Loading branch information
c1495616js committed Jan 17, 2025
1 parent ace0d9d commit bccabaf
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions apps/api/src/applicant/entity/ienapplicant.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ManyToMany,
JoinTable,
BeforeUpdate,
AfterUpdate,
} from 'typeorm';

import { IENApplicantAudit } from './ienapplicant-audit.entity';
Expand Down Expand Up @@ -170,12 +171,28 @@ export class IENApplicant {
/**
* Check if the deleted_date is set before updating the entity, this is for syncronization with the ATS preventing updates to scrambled data
*/
// Temporary properties to store original values
private originalName?: string;
private originalEmailAddress?: string;
private originalPhoneNumber?: string;
@BeforeUpdate()
storeOriginalDataOnUpdate() {
this.originalName = this.name;
this.originalEmailAddress = this.email_address;
this.originalPhoneNumber = this.phone_number;
}
@AfterUpdate()
checkDeletedDateBeforeUpdate() {
if (this.deleted_date) {
this.name = this.name; // Keep existing value
this.email_address = this.email_address; // Keep existing value
this.phone_number = this.phone_number; // Keep existing value
if (this.originalName) {
this.name = this.originalName; // Keep existing value
}
if (this.originalEmailAddress) {
this.email_address = this.originalEmailAddress; // Keep existing value
}
if (this.originalPhoneNumber) {
this.phone_number = this.originalPhoneNumber; // Keep existing value
}
}
}

Expand Down

0 comments on commit bccabaf

Please sign in to comment.