Skip to content

Commit

Permalink
Merge pull request #173 from avinyafoundation/main
Browse files Browse the repository at this point in the history
lint
  • Loading branch information
YujithIsura authored Oct 7, 2024
2 parents c178482 + 65b963b commit a03ad62
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions api/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -5519,11 +5519,7 @@ AND p.organization_id IN (
`SELECT *
from person p
where
p.avinya_type_id = ${avinya_type_id} and
p.organization_id IN(
Select child_org_id
from parent_child_organization pco
);`);
p.avinya_type_id = ${avinya_type_id};`);
}
} else {
return error("Provide non-null values for both 'organization_id' and 'avinya_type_id'.");
Expand Down Expand Up @@ -5564,6 +5560,8 @@ AND p.organization_id IN (
int|string? permanent_address_insert_id = null;
int|string? mailing_address_insert_id = null;

string message = "";

transaction {

int permanent_address_id = permanent_address?.id ?: 0;
Expand All @@ -5577,7 +5575,7 @@ AND p.organization_id IN (
if (permanent_address_raw is Address) {
io:println("Permanent Address is already exists!");

if (permanent_address != null && permanent_address_city != null ) {
if (permanent_address != null && permanent_address_city != null) {

permanent_address_res = check db_client->execute(
`UPDATE address SET
Expand All @@ -5591,13 +5589,13 @@ AND p.organization_id IN (
if (permanent_address_res.affectedRowCount == sql:EXECUTION_FAILED) {
first_db_transaction_fail = true;
io:println("Unable to update permanent address record");
message = "Unable to update permanent address record";
}
}


} else {

if (permanent_address != null && permanent_address_city != null ) {
if (permanent_address != null && permanent_address_city != null) {

permanent_address_res = check db_client->execute(
`INSERT INTO address(
Expand All @@ -5616,6 +5614,7 @@ AND p.organization_id IN (
if !(permanent_address_insert_id is int) {
first_db_transaction_fail = true;
io:println("Unable to insert permanent address");
message = "Unable to insert permanent address";
}
}
}
Expand Down Expand Up @@ -5646,6 +5645,7 @@ AND p.organization_id IN (
if (mailing_address_res.affectedRowCount == sql:EXECUTION_FAILED) {
second_db_transaction_fail = true;
io:println("Unable to update mailing address record");
message = "Unable to update mailing address record";
}
}

Expand All @@ -5670,6 +5670,7 @@ AND p.organization_id IN (
if !(mailing_address_insert_id is int) {
second_db_transaction_fail = true;
io:println("Unable to insert mailing address");
message = "Unable to insert mailing address";
}
}

Expand Down Expand Up @@ -5711,14 +5712,15 @@ AND p.organization_id IN (
if (update_person_res.affectedRowCount == sql:EXECUTION_FAILED) {
third_db_transaction_fail = true;
io:println("Unable to update person record");
message = "Unable to update person record";
}

if (first_db_transaction_fail ||
second_db_transaction_fail ||
third_db_transaction_fail) {

rollback;
return error("Transaction rollback");
return error(message);
} else {

// Commit the transaction if three updates are successful
Expand All @@ -5738,7 +5740,8 @@ AND p.organization_id IN (
boolean third_db_transaction_fail = false;

int|string? mailing_address_insert_id = null;


string message = "";

transaction {

Expand All @@ -5750,13 +5753,12 @@ AND p.organization_id IN (
);

if (personRaw is Person) {
first_db_transaction_fail = true;
io:println("Person already exists.");
first_db_transaction_fail = true;
io:println("Person already exists.");
message = "Person already exists.";
}


if (mailing_address != null && mailing_address?.street_address != null &&
mailing_address_city != null && mailing_address_city?.id != null) {
if (mailing_address != null && mailing_address_city != null) {

sql:ExecutionResult mailing_address_res = check db_client->execute(
`INSERT INTO address(
Expand All @@ -5775,6 +5777,7 @@ AND p.organization_id IN (
if !(mailing_address_insert_id is int) {
second_db_transaction_fail = true;
io:println("Unable to insert mailing address");
message = "Unable to insert mailing address";
}
}

Expand Down Expand Up @@ -5825,25 +5828,26 @@ AND p.organization_id IN (
${person.created_by}
);`);

int|string? insert_person_id = insert_person_res.lastInsertId;
int|string? insert_person_id = insert_person_res.lastInsertId;

if !(insert_person_id is int) {
third_db_transaction_fail = true;
io:println("Unable to insert person");
message = "Unable to insert person";
}

if (first_db_transaction_fail ||
second_db_transaction_fail ||
third_db_transaction_fail) {

rollback;
return error("Transaction rollback");
return error(message);
} else {

// Commit the transaction if three updates are successful
check commit;
io:println("Transaction committed successfully!");
return new (null,<int?>insert_person_id);
return new (null, <int?>insert_person_id);
}
}

Expand Down

0 comments on commit a03ad62

Please sign in to comment.