Pass in db to pickPort

This commit is contained in:
Owen
2025-09-04 17:59:59 -07:00
parent 3e353717f5
commit 838e3efbca
3 changed files with 5 additions and 5 deletions

View File

@@ -161,7 +161,7 @@ export async function createTarget(
); );
} }
const { internalPort, targetIps } = await pickPort(site.siteId!); const { internalPort, targetIps } = await pickPort(site.siteId!, db);
if (!internalPort) { if (!internalPort) {
return next( return next(

View File

@@ -1,10 +1,10 @@
import { db } from "@server/db"; import { db, Transaction } from "@server/db";
import { resources, targets } from "@server/db"; import { resources, targets } from "@server/db";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
const currentBannedPorts: number[] = []; const currentBannedPorts: number[] = [];
export async function pickPort(siteId: number): Promise<{ export async function pickPort(siteId: number, trx: Transaction | typeof db): Promise<{
internalPort: number; internalPort: number;
targetIps: string[]; targetIps: string[];
}> { }> {
@@ -12,7 +12,7 @@ export async function pickPort(siteId: number): Promise<{
const targetIps: string[] = []; const targetIps: string[] = [];
const targetInternalPorts: number[] = []; const targetInternalPorts: number[] = [];
const targetsRes = await db const targetsRes = await trx
.select() .select()
.from(targets) .from(targets)
.where(eq(targets.siteId, siteId)); .where(eq(targets.siteId, siteId));

View File

@@ -153,7 +153,7 @@ export async function updateTarget(
); );
} }
const { internalPort, targetIps } = await pickPort(site.siteId!); const { internalPort, targetIps } = await pickPort(site.siteId!, db);
if (!internalPort) { if (!internalPort) {
return next( return next(