From a47ef7f7bdb6a3dd07f70c48a4d17a82a21e5b32 Mon Sep 17 00:00:00 2001 From: lahirulakruwan Date: Fri, 8 Nov 2024 12:03:03 +0530 Subject: [PATCH] Added Monthly payment amount by organization api fetch function --- api/main.bal | 81 ++++++++++++++++++++++++++++----------- api/organization_data.bal | 6 +++ api/types.bal | 1 + 3 files changed, 66 insertions(+), 22 deletions(-) diff --git a/api/main.bal b/api/main.bal index 5b3f9c7..9c1825c 100644 --- a/api/main.bal +++ b/api/main.bal @@ -102,16 +102,30 @@ service /graphql on new graphql:Listener(4000) { return new (name, id); } - isolated resource function get organizations_by_avinya_type(int? avinya_type) returns OrganizationData[]|error? { + isolated resource function get organizations_by_avinya_type(int? avinya_type, int? active = 0) returns OrganizationData[]|error? { stream org_list; - lock { - org_list = db_client->query( + + if (active == 1) { + + lock { + org_list = db_client->query( + `SELECT * + FROM organization + WHERE avinya_type = ${avinya_type} and active = ${active}`); + } + + } else { + + lock { + org_list = db_client->query( `SELECT * FROM organization WHERE avinya_type = ${avinya_type} ` ); + } + } OrganizationData[] organizationListDatas = []; @@ -6046,30 +6060,53 @@ AND p.organization_id IN ( isolated resource function get monthly_leave_dates_record_by_id(int organization_id, int year, int month) returns MonthlyLeaveDatesData|error? { if ((organization_id is int) && (year is int) && (month is int)) { - MonthlyLeaveDates|error? monthly_leave_dates_raw = db_client->queryRow( + MonthlyLeaveDates|error? monthly_leave_dates_raw = db_client->queryRow( `SELECT * FROM monthly_leave_dates WHERE organization_id = ${organization_id} and year = ${year} and month = ${month} ;`); - if (monthly_leave_dates_raw is MonthlyLeaveDates) { - return new (0,monthly_leave_dates_raw); - }else{ - // Return a new empty MonthlyLeaveDates object if no record is found - MonthlyLeaveDates emptyLeaveDates = { - id: null, - year: null, - month: null, - organization_id: null, - leave_dates_list: [], - daily_amount: null, - created: null, - updated: null, - total_days_in_month: null, - leave_dates: null - }; - return new(0,emptyLeaveDates); - } + if (monthly_leave_dates_raw is MonthlyLeaveDates) { + return new (0, monthly_leave_dates_raw); + } else { + // Return a new empty MonthlyLeaveDates object if no record is found + MonthlyLeaveDates emptyLeaveDates = { + id: null, + year: null, + month: null, + organization_id: null, + leave_dates_list: [], + daily_amount: null, + created: null, + updated: null, + total_days_in_month: null, + leave_dates: null + }; + return new (0, emptyLeaveDates); + } + } + } + + isolated resource function get calendar_metadata_by_org_id(int organization_id) returns CalendarMetaData|error? { + + if (organization_id is int) { + + CalendarMetadata|error? calendar_metadata_raw = db_client->queryRow( + `SELECT * + FROM calendar_metadata + WHERE organization_id = ${organization_id} ;`); + + if (calendar_metadata_raw is CalendarMetadata) { + return new (0, calendar_metadata_raw); + } else { + // Return a new empty Calendar Metadata object if no record is found + CalendarMetadata emptyCalendarMetadata = { + id: null, + organization_id: organization_id, + monthly_payment_amount: 0.0 + }; + return new (0, emptyCalendarMetadata); + } } } diff --git a/api/organization_data.bal b/api/organization_data.bal index bf8f50f..dabeccb 100644 --- a/api/organization_data.bal +++ b/api/organization_data.bal @@ -261,4 +261,10 @@ lock{ return org_meta_data_details; } + isolated resource function get active() returns int? { + lock { + return self.organization.active; + } + } + } diff --git a/api/types.bal b/api/types.bal index ead0c67..32734de 100644 --- a/api/types.bal +++ b/api/types.bal @@ -87,6 +87,7 @@ public type Organization record {| int? phone; string? description; string? notes; + int? active; |}; type ParentChildOrganization record {|