diff --git a/server/routers/client/createClient.ts b/server/routers/client/createClient.ts index 34aef346..4e9dcdce 100644 --- a/server/routers/client/createClient.ts +++ b/server/routers/client/createClient.ts @@ -144,14 +144,16 @@ export async function createClient( const subnetExistsClients = await db .select() .from(clients) - .where(eq(clients.subnet, updatedSubnet)) + .where( + and(eq(clients.subnet, updatedSubnet), eq(clients.orgId, orgId)) + ) .limit(1); if (subnetExistsClients.length > 0) { return next( createHttpError( HttpCode.CONFLICT, - `Subnet ${subnet} already exists` + `Subnet ${updatedSubnet} already exists in clients` ) ); } @@ -159,14 +161,16 @@ export async function createClient( const subnetExistsSites = await db .select() .from(sites) - .where(eq(sites.address, updatedSubnet)) + .where( + and(eq(sites.address, updatedSubnet), eq(sites.orgId, orgId)) + ) .limit(1); if (subnetExistsSites.length > 0) { return next( createHttpError( HttpCode.CONFLICT, - `Subnet ${subnet} already exists` + `Subnet ${updatedSubnet} already exists in sites` ) ); } diff --git a/server/routers/site/createSite.ts b/server/routers/site/createSite.ts index 60e34465..fb1170cd 100644 --- a/server/routers/site/createSite.ts +++ b/server/routers/site/createSite.ts @@ -129,17 +129,17 @@ export async function createSite( ); } - if (!org.subnet) { - return next( - createHttpError( - HttpCode.BAD_REQUEST, - `Organization with ID ${orgId} has no subnet defined` - ) - ); - } - let updatedAddress = null; if (address) { + if (!org.subnet) { + return next( + createHttpError( + HttpCode.BAD_REQUEST, + `Organization with ID ${orgId} has no subnet defined` + ) + ); + } + if (!isValidIP(address)) { return next( createHttpError(