From 771359dd736cef67c694bf2cea5c755d1a49e6d6 Mon Sep 17 00:00:00 2001 From: lahirulakruwan Date: Mon, 30 Sep 2024 14:43:19 +0530 Subject: [PATCH 1/2] update person api changes added --- api/main.bal | 34 ++++++++++++++++++++++++---------- api/types.bal | 1 + 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/api/main.bal b/api/main.bal index a4cba60..92a2b9c 100644 --- a/api/main.bal +++ b/api/main.bal @@ -5498,9 +5498,8 @@ AND p.organization_id IN ( isolated resource function get persons(int? organization_id, int? avinya_type_id) returns PersonData[]|error? { stream persons_data; - if (organization_id != null && avinya_type_id != null) { - - lock { + if(organization_id != null && organization_id != -1 && avinya_type_id !=null){ + lock { persons_data = db_client->query( `SELECT * from person p @@ -5513,6 +5512,22 @@ AND p.organization_id IN ( );`); } + } else if (organization_id != null && organization_id ==-1 && avinya_type_id != null) { + + lock { + persons_data = db_client->query( + `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 + );`); + } + } else { + return error("Provide non-null values for both 'organization_id' and 'avinya_type_id'."); + } PersonData[] personDatas = []; check from Person person_data_record in persons_data @@ -5525,9 +5540,6 @@ AND p.organization_id IN ( check persons_data.close(); return personDatas; - } else { - return error("Provide non-null values for both 'organization_id' and 'avinya_type_id'."); - } } @@ -5555,6 +5567,7 @@ AND p.organization_id IN ( transaction { int permanent_address_id = permanent_address?.id ?: 0; + City permanent_address_city = permanent_address?.city; Address|error? permanent_address_raw = db_client->queryRow( `SELECT * @@ -5569,7 +5582,7 @@ AND p.organization_id IN ( `UPDATE address SET street_address = ${permanent_address?.street_address}, phone = ${permanent_address?.phone}, - city_id = ${permanent_address?.city_id} + city_id = ${permanent_address_city.id} WHERE id = ${permanent_address_id};`); permanent_address_insert_id = permanent_address_id; @@ -5589,7 +5602,7 @@ AND p.organization_id IN ( ) VALUES( ${permanent_address?.street_address}, ${permanent_address?.phone}, - ${permanent_address?.city_id} + ${permanent_address_city.id} );` ); @@ -5602,6 +5615,7 @@ AND p.organization_id IN ( } int mailing_address_id = mailing_address?.id ?: 0; + City mailing_address_city = mailing_address?.city; Address|error? mailing_address_raw = db_client->queryRow( `SELECT * @@ -5617,7 +5631,7 @@ AND p.organization_id IN ( `UPDATE address SET street_address = ${mailing_address?.street_address}, phone = ${mailing_address?.phone}, - city_id = ${mailing_address?.city_id} + city_id = ${mailing_address_city.id} WHERE id = ${mailing_address_id};`); mailing_address_insert_id = mailing_address_id; @@ -5637,7 +5651,7 @@ AND p.organization_id IN ( ) VALUES( ${mailing_address?.street_address}, ${mailing_address?.phone}, - ${mailing_address?.city_id} + ${mailing_address_city.id} );` ); diff --git a/api/types.bal b/api/types.bal index eeec072..a9a60e2 100644 --- a/api/types.bal +++ b/api/types.bal @@ -50,6 +50,7 @@ public type Address record { string street_address; int? phone; int city_id; + City? city; }; public type AvinyaType record {| From af74bfa0cc7493c08d772d2b3847e9ea41034751 Mon Sep 17 00:00:00 2001 From: lahirulakruwan Date: Tue, 1 Oct 2024 15:38:19 +0530 Subject: [PATCH 2/2] update person api new changes added --- api/geo_data.bal | 2 +- api/main.bal | 37 +++++++++++++++++++++++++++---------- api/types.bal | 10 +++++----- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/api/geo_data.bal b/api/geo_data.bal index 75dc06a..49a4e4b 100644 --- a/api/geo_data.bal +++ b/api/geo_data.bal @@ -215,7 +215,7 @@ public isolated service class AddressData { } } - isolated resource function get street_address() returns string { + isolated resource function get street_address() returns string? { lock { return self.address.street_address; } diff --git a/api/main.bal b/api/main.bal index 92a2b9c..d7f8070 100644 --- a/api/main.bal +++ b/api/main.bal @@ -5551,7 +5551,8 @@ AND p.organization_id IN ( } } - remote function update_person(Person person,Address? permanent_address,Address? mailing_address) returns PersonData|error? { + remote function update_person(Person person,Address? permanent_address,City? permanent_address_city,Address? mailing_address,City? mailing_address_city) returns PersonData|error? { + //starting the transaction boolean first_db_transaction_fail = false; @@ -5566,8 +5567,8 @@ AND p.organization_id IN ( transaction { + int permanent_address_id = permanent_address?.id ?: 0; - City permanent_address_city = permanent_address?.city; Address|error? permanent_address_raw = db_client->queryRow( `SELECT * @@ -5578,11 +5579,14 @@ AND p.organization_id IN ( if (permanent_address_raw is Address) { io:println("Permanent Address is already exists!"); + if(permanent_address != null && permanent_address?.street_address != null && + permanent_address_city !=null && permanent_address_city?.id !=null) { + permanent_address_res = check db_client->execute( `UPDATE address SET street_address = ${permanent_address?.street_address}, phone = ${permanent_address?.phone}, - city_id = ${permanent_address_city.id} + city_id = ${permanent_address_city?.id} WHERE id = ${permanent_address_id};`); permanent_address_insert_id = permanent_address_id; @@ -5591,9 +5595,13 @@ AND p.organization_id IN ( first_db_transaction_fail = true; io:println("Unable to update permanent address record"); } + } }else{ + if(permanent_address != null && permanent_address?.street_address != null && + permanent_address_city !=null && permanent_address_city?.id !=null){ + permanent_address_res = check db_client->execute( `INSERT INTO address( street_address, @@ -5602,9 +5610,10 @@ AND p.organization_id IN ( ) VALUES( ${permanent_address?.street_address}, ${permanent_address?.phone}, - ${permanent_address_city.id} + ${permanent_address_city?.id} );` ); + permanent_address_insert_id = permanent_address_res.lastInsertId; @@ -5612,10 +5621,10 @@ AND p.organization_id IN ( first_db_transaction_fail = true; io:println("Unable to insert permanent address"); } + } } int mailing_address_id = mailing_address?.id ?: 0; - City mailing_address_city = mailing_address?.city; Address|error? mailing_address_raw = db_client->queryRow( `SELECT * @@ -5626,12 +5635,15 @@ AND p.organization_id IN ( if (mailing_address_raw is Address) { io:println("Mailing Address is already exists!"); + + if(mailing_address != null && mailing_address?.street_address != null && + mailing_address_city !=null && mailing_address_city?.id !=null) { mailing_address_res = check db_client->execute( `UPDATE address SET street_address = ${mailing_address?.street_address}, phone = ${mailing_address?.phone}, - city_id = ${mailing_address_city.id} + city_id = ${mailing_address_city?.id} WHERE id = ${mailing_address_id};`); mailing_address_insert_id = mailing_address_id; @@ -5640,9 +5652,13 @@ AND p.organization_id IN ( second_db_transaction_fail = true; io:println("Unable to update mailing address record"); } + } }else{ + if(mailing_address != null && mailing_address?.street_address != null && + mailing_address_city !=null && mailing_address_city?.id !=null) { + mailing_address_res = check db_client->execute( `INSERT INTO address( street_address, @@ -5651,7 +5667,7 @@ AND p.organization_id IN ( ) VALUES( ${mailing_address?.street_address}, ${mailing_address?.phone}, - ${mailing_address_city.id} + ${mailing_address_city?.id} );` ); @@ -5661,6 +5677,7 @@ AND p.organization_id IN ( second_db_transaction_fail = true; io:println("Unable to insert mailing address"); } + } } @@ -5706,7 +5723,7 @@ AND p.organization_id IN ( third_db_transaction_fail) { rollback; - return error("Transaction rollback successfully!"); + return error("Transaction rollback"); }else{ // Commit the transaction if three updates are successful @@ -5897,7 +5914,7 @@ isolated function updateDutyParticipantsWorkRotation(DutyParticipant[] dutyParti foreach DutyParticipant activityObject in dutyParticipantsArray { - if (activityObject.role == "member") { + //if (activityObject.role == "member") { int? currentIndex = dynamicDutyActivitiesArray.indexOf(activityObject.activity_id); int? nextIndex = (currentIndex + 1) % dynamicDutyActivitiesArray.length(); @@ -5922,7 +5939,7 @@ isolated function updateDutyParticipantsWorkRotation(DutyParticipant[] dutyParti } } - } + //} } } diff --git a/api/types.bal b/api/types.bal index a9a60e2..ac85cb1 100644 --- a/api/types.bal +++ b/api/types.bal @@ -8,14 +8,14 @@ # + name_ta - Name in Tamil, தமிழ் # + name_si - Name in Sinhala, සිංහල public type LocalizedName record { - string name_en; + string? name_en; string? name_ta; string? name_si; }; type GeospatialInformation record {| - decimal latitude; - decimal longitude; + decimal? latitude; + decimal? longitude; |}; public type Province record {| @@ -47,9 +47,9 @@ public type Address record { readonly string? record_type = "address"; int id?; //*LocalizedName; - string street_address; + string? street_address; int? phone; - int city_id; + int? city_id; City? city; };