fix: Issue 523, 536 to delete duplicate queries and create cost center schema and queries

This commit is contained in:
dhinesh-m24
2026-02-25 15:21:45 +05:30
parent 99c6013453
commit d126ece7ce
7 changed files with 135 additions and 43 deletions

View File

@@ -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

View File

@@ -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)
}

View File

@@ -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
}
}
}

View File

@@ -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
}
)
}

View File

@@ -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
}
}
}

View File

@@ -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
}

View File

@@ -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