Skip to content

Commit afea958

Browse files
Also limit to org
1 parent dca2a29 commit afea958

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

server/routers/client/createClient.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,29 +144,33 @@ export async function createClient(
144144
const subnetExistsClients = await db
145145
.select()
146146
.from(clients)
147-
.where(eq(clients.subnet, updatedSubnet))
147+
.where(
148+
and(eq(clients.subnet, updatedSubnet), eq(clients.orgId, orgId))
149+
)
148150
.limit(1);
149151

150152
if (subnetExistsClients.length > 0) {
151153
return next(
152154
createHttpError(
153155
HttpCode.CONFLICT,
154-
`Subnet ${subnet} already exists`
156+
`Subnet ${updatedSubnet} already exists in clients`
155157
)
156158
);
157159
}
158160

159161
const subnetExistsSites = await db
160162
.select()
161163
.from(sites)
162-
.where(eq(sites.address, updatedSubnet))
164+
.where(
165+
and(eq(sites.address, updatedSubnet), eq(sites.orgId, orgId))
166+
)
163167
.limit(1);
164168

165169
if (subnetExistsSites.length > 0) {
166170
return next(
167171
createHttpError(
168172
HttpCode.CONFLICT,
169-
`Subnet ${subnet} already exists`
173+
`Subnet ${updatedSubnet} already exists in sites`
170174
)
171175
);
172176
}

server/routers/site/createSite.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,17 @@ export async function createSite(
129129
);
130130
}
131131

132-
if (!org.subnet) {
133-
return next(
134-
createHttpError(
135-
HttpCode.BAD_REQUEST,
136-
`Organization with ID ${orgId} has no subnet defined`
137-
)
138-
);
139-
}
140-
141132
let updatedAddress = null;
142133
if (address) {
134+
if (!org.subnet) {
135+
return next(
136+
createHttpError(
137+
HttpCode.BAD_REQUEST,
138+
`Organization with ID ${orgId} has no subnet defined`
139+
)
140+
);
141+
}
142+
143143
if (!isValidIP(address)) {
144144
return next(
145145
createHttpError(

0 commit comments

Comments
 (0)