Continue to rebase

This commit is contained in:
Owen
2026-03-20 09:17:10 -07:00
parent 87524fe8ae
commit a1ce7f54a0
2 changed files with 27 additions and 21 deletions

View File

@@ -1,6 +1,6 @@
import { Request, Response, NextFunction } from "express"; import { Request, Response, NextFunction } from "express";
import { z } from "zod"; import { z } from "zod";
import { db, Site, siteResources } from "@server/db"; import { db, Site, siteNetworks, siteResources } from "@server/db";
import { newts, newtSessions, sites } from "@server/db"; import { newts, newtSessions, sites } from "@server/db";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import response from "@server/lib/response"; import response from "@server/lib/response";
@@ -71,18 +71,23 @@ export async function deleteSite(
await deletePeer(site.exitNodeId!, site.pubKey); await deletePeer(site.exitNodeId!, site.pubKey);
} }
} else if (site.type == "newt") { } else if (site.type == "newt") {
// delete all of the site resources on this site const networks = await trx
const siteResourcesOnSite = trx .select({ networkId: siteNetworks.networkId })
.delete(siteResources) .from(siteNetworks)
.where(eq(siteResources.siteId, siteId)) .where(eq(siteNetworks.siteId, siteId));
.returning();
// loop through them // loop through them
for (const removedSiteResource of await siteResourcesOnSite) { for (const network of await networks) {
await rebuildClientAssociationsFromSiteResource( const [siteResource] = await trx
removedSiteResource, .select()
trx .from(siteResources)
); .where(eq(siteResources.networkId, network.networkId));
if (siteResource) {
await rebuildClientAssociationsFromSiteResource(
siteResource,
trx
);
}
} }
// get the newt on the site by querying the newt table for siteId // get the newt on the site by querying the newt table for siteId

View File

@@ -70,17 +70,18 @@ export async function deleteSiteResource(
.where(and(eq(siteResources.siteResourceId, siteResourceId))) .where(and(eq(siteResources.siteResourceId, siteResourceId)))
.returning(); .returning();
const [newt] = await trx // not sure why this is here...
.select() // const [newt] = await trx
.from(newts) // .select()
.where(eq(newts.siteId, removedSiteResource.siteId)) // .from(newts)
.limit(1); // .where(eq(newts.siteId, removedSiteResource.siteId))
// .limit(1);
if (!newt) { // if (!newt) {
return next( // return next(
createHttpError(HttpCode.NOT_FOUND, "Newt not found") // createHttpError(HttpCode.NOT_FOUND, "Newt not found")
); // );
} // }
await rebuildClientAssociationsFromSiteResource( await rebuildClientAssociationsFromSiteResource(
removedSiteResource, removedSiteResource,