Skip to content

Commit

Permalink
Allow prospect/consent duplicates if not active
Browse files Browse the repository at this point in the history
  • Loading branch information
samisa-abeysinghe committed Oct 22, 2022
1 parent 6987312 commit 21df92a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions api/applicant_consent_data.bal
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public isolated service class ApplicantConsentData {
return new AvinyaTypeData(id);
}

isolated resource function get active() returns boolean? {
lock {
return self.applicant_consent.active;
}
}

isolated resource function get phone() returns int? {
lock {
return self.applicant_consent.phone;
Expand Down
17 changes: 15 additions & 2 deletions api/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ service graphql:Service /graphql on new graphql:Listener(4000) {
ApplicantConsent|error? applicantConsentRaw = db_client -> queryRow(
`SELECT *
FROM avinya_db.applicant_consent
WHERE email = ${applicantConsent.email} OR
phone = ${applicantConsent.phone};`
WHERE (email = ${applicantConsent.email} OR
phone = ${applicantConsent.phone}) AND
active = TRUE;`
);

if(applicantConsentRaw is ApplicantConsent) {
Expand Down Expand Up @@ -128,6 +129,18 @@ service graphql:Service /graphql on new graphql:Listener(4000) {
}

remote function add_prospect(Prospect prospect) returns ProspectData|error? {
Prospect|error? prospectRaw = db_client -> queryRow(
`SELECT *
FROM avinya_db.applicant_consent
WHERE (email = ${prospect.email} OR
phone = ${prospect.phone}) AND
active = TRUE;`
);

if(prospectRaw is Prospect) {
return error("Prospect already exists. The phone or the email you provided is already used by another prospect");
}

sql:ExecutionResult res = check db_client->execute(
`INSERT INTO avinya_db.prospect (
name,
Expand Down
6 changes: 6 additions & 0 deletions api/prospect_data.bal
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public isolated service class ProspectData {
self.prospect = consent_raw.cloneReadOnly();
}

isolated resource function get active() returns boolean? {
lock {
return self.prospect.active;
}
}

isolated resource function get phone() returns int? {
lock {
return self.prospect.phone;
Expand Down
2 changes: 2 additions & 0 deletions api/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ public type WorkExperienceEvaluation record {|
public type ApplicantConsent record {|
readonly string? record_type = "applicant_consent";
int id?;
boolean? active;
int? organization_id;
int? avinya_type_id;
int? person_id;
Expand All @@ -247,6 +248,7 @@ public type ApplicantConsent record {|
public type Prospect record {|
readonly string? record_type = "prospect";
int id?;
boolean? active;
string? name;
int? phone;
string? email;
Expand Down

0 comments on commit 21df92a

Please sign in to comment.