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

View File

@@ -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();

View File

@@ -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();