chore: simplify policy rule update/delete lookups

This commit is contained in:
copilot-swe-agent[bot]
2026-06-16 23:52:22 +00:00
committed by GitHub
parent a7c99f336f
commit 0bde633c5f
2 changed files with 13 additions and 7 deletions
@@ -74,13 +74,15 @@ export async function deleteResourceRule(
} }
if (resource.resourcePolicyId !== null) { if (resource.resourcePolicyId !== null) {
const policyId = resource.resourcePolicyId;
const [deletedRule] = await db const [deletedRule] = await db
.delete(resourcePolicyRules) .delete(resourcePolicyRules)
.where( .where(
and( and(
eq(resourcePolicyRules.ruleId, ruleId), eq(resourcePolicyRules.ruleId, ruleId),
eq(resourcePolicyRules.resourcePolicyId, policyId) eq(
resourcePolicyRules.resourcePolicyId,
resource.resourcePolicyId
)
) )
) )
.returning(); .returning();
@@ -151,16 +151,17 @@ export async function updateResourceRule(
); );
} }
const policyId = resource.resourcePolicyId; if (resource.resourcePolicyId !== null) {
if (policyId !== null) {
const [existingRule] = await db const [existingRule] = await db
.select() .select()
.from(resourcePolicyRules) .from(resourcePolicyRules)
.where( .where(
and( and(
eq(resourcePolicyRules.ruleId, ruleId), eq(resourcePolicyRules.ruleId, ruleId),
eq(resourcePolicyRules.resourcePolicyId, policyId) eq(
resourcePolicyRules.resourcePolicyId,
resource.resourcePolicyId
)
) )
) )
.limit(1); .limit(1);
@@ -195,7 +196,10 @@ export async function updateResourceRule(
.where( .where(
and( and(
eq(resourcePolicyRules.ruleId, ruleId), eq(resourcePolicyRules.ruleId, ruleId),
eq(resourcePolicyRules.resourcePolicyId, policyId) eq(
resourcePolicyRules.resourcePolicyId,
resource.resourcePolicyId
)
) )
) )
.returning(); .returning();