From d126ece7cea837bc27db8828c9ebd0da2a3e4408 Mon Sep 17 00:00:00 2001 From: dhinesh-m24 Date: Wed, 25 Feb 2026 15:21:45 +0530 Subject: [PATCH] fix: Issue 523, 536 to delete duplicate queries and create cost center schema and queries --- .../connector/benefitsData/queries.gql | 44 +---------------- .../connector/costCenter/mutations.gql | 37 +++++++++++++++ .../connector/costCenter/queries.gql | 47 +++++++++++++++++++ .../dataconnect/connector/hub/mutations.gql | 21 +++++++++ backend/dataconnect/connector/hub/queries.gql | 20 ++++++++ backend/dataconnect/schema/costCenter.gql | 7 +++ backend/dataconnect/schema/hub.gql | 2 + 7 files changed, 135 insertions(+), 43 deletions(-) create mode 100644 backend/dataconnect/connector/costCenter/mutations.gql create mode 100644 backend/dataconnect/connector/costCenter/queries.gql create mode 100644 backend/dataconnect/schema/costCenter.gql diff --git a/backend/dataconnect/connector/benefitsData/queries.gql b/backend/dataconnect/connector/benefitsData/queries.gql index c856fcbf..da7e32de 100644 --- a/backend/dataconnect/connector/benefitsData/queries.gql +++ b/backend/dataconnect/connector/benefitsData/queries.gql @@ -1,38 +1,3 @@ - -# ---------------------------------------------------------- -# GET WORKER BENEFIT BALANCES (M4) -# Returns all active benefit plans with balance data for a given worker. -# Supports: Sick Leave (40h), Holidays (24h), Vacation (40h) -# Extensible: any future VendorBenefitPlan will appear automatically. -# -# Fields: -# vendorBenefitPlan.title → benefit type name -# vendorBenefitPlan.total → total entitlement (hours) -# current → used hours -# remaining = total - current → computed client-side -# ---------------------------------------------------------- -query getWorkerBenefitBalances( - $staffId: UUID! -) @auth(level: USER) { - benefitsDatas( - where: { - staffId: { eq: $staffId } - } - ) { - vendorBenefitPlanId - current - - vendorBenefitPlan { - id - title - description - requestLabel - total - isActive - } - } -} - # ---------------------------------------------------------- # LIST ALL (admin/debug) # ---------------------------------------------------------- @@ -109,16 +74,9 @@ query listBenefitsDataByStaffId( id vendorBenefitPlanId current - staffId - - staff { - id - fullName - } vendorBenefitPlan { id - vendorId title description requestLabel @@ -196,4 +154,4 @@ query listBenefitsDataByVendorBenefitPlanIds( isActive } } -} +} \ No newline at end of file diff --git a/backend/dataconnect/connector/costCenter/mutations.gql b/backend/dataconnect/connector/costCenter/mutations.gql new file mode 100644 index 00000000..d671a6d1 --- /dev/null +++ b/backend/dataconnect/connector/costCenter/mutations.gql @@ -0,0 +1,37 @@ + +# ---------------------------------------------------------- +# CREATE COST CENTER +# ---------------------------------------------------------- +mutation createCostCenter( + $name: String! + $createdBy: String +) @auth(level: USER) { + costCenter_insert( + data: { + name: $name + createdBy: $createdBy + } + ) +} + +# ---------------------------------------------------------- +# UPDATE COST CENTER +# ---------------------------------------------------------- +mutation updateCostCenter( + $id: UUID! + $name: String +) @auth(level: USER) { + costCenter_update( + id: $id + data: { + name: $name + } + ) +} + +# ---------------------------------------------------------- +# DELETE COST CENTER +# ---------------------------------------------------------- +mutation deleteCostCenter($id: UUID!) @auth(level: USER) { + costCenter_delete(id: $id) +} diff --git a/backend/dataconnect/connector/costCenter/queries.gql b/backend/dataconnect/connector/costCenter/queries.gql new file mode 100644 index 00000000..678afbe0 --- /dev/null +++ b/backend/dataconnect/connector/costCenter/queries.gql @@ -0,0 +1,47 @@ + +# ---------------------------------------------------------- +# LIST ALL COST CENTERS +# ---------------------------------------------------------- +query listCostCenters( + $offset: Int + $limit: Int +) @auth(level: USER) { + costCenters(offset: $offset, limit: $limit) { + id + name + createdAt + updatedAt + createdBy + } +} + +# ---------------------------------------------------------- +# GET BY ID +# ---------------------------------------------------------- +query getCostCenterById($id: UUID!) @auth(level: USER) { + costCenter(id: $id) { + id + name + createdAt + updatedAt + createdBy + } +} + +# ---------------------------------------------------------- +# GET COST CENTER LINKED TO A SPECIFIC HUB +# ---------------------------------------------------------- +query getCostCenterByHubId($hubId: UUID!) @auth(level: USER) { + hubs(where: { id: { eq: $hubId } }) { + id + name + costCenterId + costCenter { + id + name + createdAt + updatedAt + createdBy + } + } +} diff --git a/backend/dataconnect/connector/hub/mutations.gql b/backend/dataconnect/connector/hub/mutations.gql index bf7b0c18..52bd8024 100644 --- a/backend/dataconnect/connector/hub/mutations.gql +++ b/backend/dataconnect/connector/hub/mutations.gql @@ -39,3 +39,24 @@ mutation updateHub( mutation deleteHub($id: UUID!) @auth(level: USER) { hub_delete(id: $id) } + +mutation assignCostCenterToHub( + $hubId: UUID! + $costCenterId: UUID! +) @auth(level: USER) { + hub_update( + id: $hubId + data: { + costCenterId: $costCenterId + } + ) +} + +mutation removeCostCenterFromHub($hubId: UUID!) @auth(level: USER) { + hub_update( + id: $hubId + data: { + costCenterId: null + } + ) +} diff --git a/backend/dataconnect/connector/hub/queries.gql b/backend/dataconnect/connector/hub/queries.gql index dc2a69c9..c29cd99a 100644 --- a/backend/dataconnect/connector/hub/queries.gql +++ b/backend/dataconnect/connector/hub/queries.gql @@ -6,6 +6,11 @@ query listHubs @auth(level: USER) { address nfcTagId ownerId + costCenterId + costCenter { + id + name + } createdAt updatedAt createdBy @@ -20,6 +25,11 @@ query getHubById($id: UUID!) @auth(level: USER) { address nfcTagId ownerId + costCenterId + costCenter { + id + name + } createdAt updatedAt createdBy @@ -34,6 +44,11 @@ query getHubsByOwnerId($ownerId: UUID!) @auth(level: USER) { address nfcTagId ownerId + costCenterId + costCenter { + id + name + } createdAt updatedAt createdBy @@ -58,5 +73,10 @@ query filterHubs( address nfcTagId ownerId + costCenterId + costCenter { + id + name + } } } diff --git a/backend/dataconnect/schema/costCenter.gql b/backend/dataconnect/schema/costCenter.gql new file mode 100644 index 00000000..2001dd28 --- /dev/null +++ b/backend/dataconnect/schema/costCenter.gql @@ -0,0 +1,7 @@ +type CostCenter @table(name: "cost_centers") { + id: UUID! @default(expr: "uuidV4()") + name: String! + createdAt: Timestamp @default(expr: "request.time") + updatedAt: Timestamp @default(expr: "request.time") + createdBy: String +} diff --git a/backend/dataconnect/schema/hub.gql b/backend/dataconnect/schema/hub.gql index 98a6f5b3..7f4c234d 100644 --- a/backend/dataconnect/schema/hub.gql +++ b/backend/dataconnect/schema/hub.gql @@ -5,6 +5,8 @@ type Hub @table(name: "hubs") { address: String nfcTagId: String ownerId: UUID! + costCenterId: UUID + costCenter: CostCenter @ref(fields: "costCenterId", references: "id") createdAt: Timestamp @default(expr: "request.time") updatedAt: Timestamp @default(expr: "request.time") createdBy: String