Reorder delete

This commit is contained in:
Owen
2026-03-09 20:46:27 -07:00
parent 06015d5191
commit e9a2a7e752

View File

@@ -121,6 +121,9 @@ export async function deleteOrgById(
eq(clientSitesAssociationsCache.clientId, client.clientId) eq(clientSitesAssociationsCache.clientId, client.clientId)
); );
} }
await trx.delete(resources).where(eq(resources.orgId, orgId));
const allOrgDomains = await trx const allOrgDomains = await trx
.select() .select()
.from(orgDomains) .from(orgDomains)
@@ -147,7 +150,6 @@ export async function deleteOrgById(
.delete(domains) .delete(domains)
.where(inArray(domains.domainId, domainIdsToDelete)); .where(inArray(domains.domainId, domainIdsToDelete));
} }
await trx.delete(resources).where(eq(resources.orgId, orgId));
await usageService.add(orgId, FeatureId.ORGINIZATIONS, -1, trx); // here we are decreasing the org count BEFORE deleting the org because we need to still be able to get the org to get the billing org inside of here await usageService.add(orgId, FeatureId.ORGINIZATIONS, -1, trx); // here we are decreasing the org count BEFORE deleting the org because we need to still be able to get the org to get the billing org inside of here