Also limit to org

This commit is contained in:
Owen
2025-07-18 11:48:14 -07:00
parent dca2a29865
commit afea958aca
2 changed files with 17 additions and 13 deletions

View File

@@ -144,14 +144,16 @@ export async function createClient(
const subnetExistsClients = await db const subnetExistsClients = await db
.select() .select()
.from(clients) .from(clients)
.where(eq(clients.subnet, updatedSubnet)) .where(
and(eq(clients.subnet, updatedSubnet), eq(clients.orgId, orgId))
)
.limit(1); .limit(1);
if (subnetExistsClients.length > 0) { if (subnetExistsClients.length > 0) {
return next( return next(
createHttpError( createHttpError(
HttpCode.CONFLICT, HttpCode.CONFLICT,
`Subnet ${subnet} already exists` `Subnet ${updatedSubnet} already exists in clients`
) )
); );
} }
@@ -159,14 +161,16 @@ export async function createClient(
const subnetExistsSites = await db const subnetExistsSites = await db
.select() .select()
.from(sites) .from(sites)
.where(eq(sites.address, updatedSubnet)) .where(
and(eq(sites.address, updatedSubnet), eq(sites.orgId, orgId))
)
.limit(1); .limit(1);
if (subnetExistsSites.length > 0) { if (subnetExistsSites.length > 0) {
return next( return next(
createHttpError( createHttpError(
HttpCode.CONFLICT, HttpCode.CONFLICT,
`Subnet ${subnet} already exists` `Subnet ${updatedSubnet} already exists in sites`
) )
); );
} }

View File

@@ -129,6 +129,8 @@ export async function createSite(
); );
} }
let updatedAddress = null;
if (address) {
if (!org.subnet) { if (!org.subnet) {
return next( return next(
createHttpError( createHttpError(
@@ -138,8 +140,6 @@ export async function createSite(
); );
} }
let updatedAddress = null;
if (address) {
if (!isValidIP(address)) { if (!isValidIP(address)) {
return next( return next(
createHttpError( createHttpError(