mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-17 04:47:11 +00:00
chore: simplify policy rule update/delete lookups
This commit is contained in:
committed by
GitHub
parent
a7c99f336f
commit
0bde633c5f
@@ -74,13 +74,15 @@ export async function deleteResourceRule(
|
||||
}
|
||||
|
||||
if (resource.resourcePolicyId !== null) {
|
||||
const policyId = resource.resourcePolicyId;
|
||||
const [deletedRule] = await db
|
||||
.delete(resourcePolicyRules)
|
||||
.where(
|
||||
and(
|
||||
eq(resourcePolicyRules.ruleId, ruleId),
|
||||
eq(resourcePolicyRules.resourcePolicyId, policyId)
|
||||
eq(
|
||||
resourcePolicyRules.resourcePolicyId,
|
||||
resource.resourcePolicyId
|
||||
)
|
||||
)
|
||||
)
|
||||
.returning();
|
||||
|
||||
@@ -151,16 +151,17 @@ export async function updateResourceRule(
|
||||
);
|
||||
}
|
||||
|
||||
const policyId = resource.resourcePolicyId;
|
||||
|
||||
if (policyId !== null) {
|
||||
if (resource.resourcePolicyId !== null) {
|
||||
const [existingRule] = await db
|
||||
.select()
|
||||
.from(resourcePolicyRules)
|
||||
.where(
|
||||
and(
|
||||
eq(resourcePolicyRules.ruleId, ruleId),
|
||||
eq(resourcePolicyRules.resourcePolicyId, policyId)
|
||||
eq(
|
||||
resourcePolicyRules.resourcePolicyId,
|
||||
resource.resourcePolicyId
|
||||
)
|
||||
)
|
||||
)
|
||||
.limit(1);
|
||||
@@ -195,7 +196,10 @@ export async function updateResourceRule(
|
||||
.where(
|
||||
and(
|
||||
eq(resourcePolicyRules.ruleId, ruleId),
|
||||
eq(resourcePolicyRules.resourcePolicyId, policyId)
|
||||
eq(
|
||||
resourcePolicyRules.resourcePolicyId,
|
||||
resource.resourcePolicyId
|
||||
)
|
||||
)
|
||||
)
|
||||
.returning();
|
||||
|
||||
Reference in New Issue
Block a user