Fix pr blueprints not picking up site

This commit is contained in:
Owen
2026-04-30 11:39:37 -07:00
parent 81972dbb73
commit d3e4d8cda8

View File

@@ -131,41 +131,22 @@ export async function updateClientResources(
: []; : [];
const allSites: { siteId: number }[] = []; const allSites: { siteId: number }[] = [];
if (resourceData.site) { if (resourceData.site) {
let siteSingle; // Look up site by niceId
const resourceSiteId = resourceData.site; const [siteSingle] = await trx
.select({ siteId: sites.siteId })
if (resourceSiteId) { .from(sites)
// Look up site by niceId .where(
[siteSingle] = await trx and(
.select({ siteId: sites.siteId }) eq(sites.niceId, resourceData.site),
.from(sites) eq(sites.orgId, orgId)
.where(
and(
eq(sites.niceId, resourceSiteId),
eq(sites.orgId, orgId)
)
) )
.limit(1); )
} else if (siteId) { .limit(1);
// Use the provided siteId directly, but verify it belongs to the org if (siteSingle) {
[siteSingle] = await trx allSites.push(siteSingle);
.select({ siteId: sites.siteId })
.from(sites)
.where(
and(eq(sites.siteId, siteId), eq(sites.orgId, orgId))
)
.limit(1);
} else {
throw new Error(`Target site is required`);
} }
if (!siteSingle) {
throw new Error(
`Site not found: ${resourceSiteId} in org ${orgId}`
);
}
allSites.push(siteSingle);
} }
if (resourceData.sites) { if (resourceData.sites) {
@@ -180,15 +161,31 @@ export async function updateClientResources(
) )
) )
.limit(1); .limit(1);
if (!site) { if (site) {
throw new Error( allSites.push(site);
`Site not found: ${siteId} in org ${orgId}`
);
} }
allSites.push(site);
} }
} }
if (siteId && allSites.length === 0) {
// only add if there are not provided sites
// Use the provided siteId directly, but verify it belongs to the org
const [siteSingle] = await trx
.select({ siteId: sites.siteId })
.from(sites)
.where(and(eq(sites.siteId, siteId), eq(sites.orgId, orgId)))
.limit(1);
if (siteSingle) {
allSites.push(siteSingle);
}
}
if (allSites.length === 0) {
throw new Error(
`No valid sites found for private private resource ${resourceNiceId} in org ${orgId}`
);
}
if (existingResource) { if (existingResource) {
let domainInfo: let domainInfo:
| { subdomain: string | null; domainId: string } | { subdomain: string | null; domainId: string }