diff --git a/scripts/hydrate.ts b/scripts/hydrate.ts index 31a9a81a..ddd3103e 100644 --- a/scripts/hydrate.ts +++ b/scripts/hydrate.ts @@ -30,26 +30,20 @@ async function insertDummyData() { .get(); // Insert dummy users - await db.insert(users).values([ - { - orgId: org1.orgId, - name: "John Doe", - email: "john@fossorial.com", - groups: "admin,developer", - }, - { - orgId: org1.orgId, - name: "Jane Smith", - email: "jane@fossorial.com", - groups: "developer", - }, - { - orgId: org2.orgId, - name: "Bob Johnson", - email: "bob@fosrl.io", - groups: "admin", - }, - ]); + // await db.insert(users).values([ + // { + // email: "john@fossorial.com", + // groups: "admin,developer", + // }, + // { + // email: "jane@fossorial.com", + // groups: "developer", + // }, + // { + // email: "bob@fosrl.io", + // groups: "admin", + // }, + // ]); // Insert dummy exit nodes const exitNode1 = db @@ -107,6 +101,7 @@ async function insertDummyData() { .values({ resourceId: `web.${site1.subdomain}.${org1.domain}`, siteId: site1.siteId, + orgId: site1.orgId, name: "Web Server", subdomain: "web", }) @@ -118,6 +113,7 @@ async function insertDummyData() { .values({ resourceId: `web2.${site1.subdomain}.${org1.domain}`, siteId: site1.siteId, + orgId: site1.orgId, name: "Web Server 2", subdomain: "web2", }) @@ -129,6 +125,7 @@ async function insertDummyData() { .values({ resourceId: `db.${site2.subdomain}.${org2.domain}`, siteId: site2.siteId, + orgId: site2.orgId, name: "Database", subdomain: "db", }) diff --git a/server/routers/external.ts b/server/routers/external.ts index 78130c4c..a338ae32 100644 --- a/server/routers/external.ts +++ b/server/routers/external.ts @@ -43,7 +43,7 @@ authenticated.post("/target/:targetId", target.updateTarget); authenticated.delete("/target/:targetId", target.deleteTarget); authenticated.get("/users", user.listUsers); -authenticated.get("/org/:orgId/users", user.listUsers); +// authenticated.get("/org/:orgId/users", user.???); // TODO: Implement this authenticated.get("/user/:userId", user.getUser); authenticated.delete("/user/:userId", user.deleteUser); diff --git a/server/routers/resource/listResources.ts b/server/routers/resource/listResources.ts index f188d298..0f20650b 100644 --- a/server/routers/resource/listResources.ts +++ b/server/routers/resource/listResources.ts @@ -8,13 +8,15 @@ import createHttpError from 'http-errors'; import { sql, eq } from 'drizzle-orm'; const listResourcesParamsSchema = z.object({ - siteId: z.string().optional().transform(Number).pipe(z.number().int().positive()), - orgId: z.string().optional().transform(Number).pipe(z.number().int().positive()), + siteId: z.coerce.number().int().positive().optional(), + orgId: z.coerce.number().int().positive().optional(), +}).refine(data => !!data.siteId !== !!data.orgId, { + message: "Either siteId or orgId must be provided, but not both", }); const listResourcesSchema = z.object({ - limit: z.string().optional().transform(Number).pipe(z.number().int().positive().default(10)), - offset: z.string().optional().transform(Number).pipe(z.number().int().nonnegative().default(0)), + limit: z.coerce.number().int().positive().default(10), + offset: z.coerce.number().int().nonnegative().default(0), }); export async function listResources(req: Request, res: Response, next: NextFunction): Promise { @@ -59,13 +61,6 @@ export async function listResources(req: Request, res: Response, next: NextFunct } else if (orgId) { baseQuery = baseQuery.where(eq(resources.orgId, orgId)); countQuery = countQuery.where(eq(resources.orgId, orgId)); - } else { - return next( - createHttpError( - HttpCode.BAD_REQUEST, - 'Either siteId or orgId must be provided' - ) - ); } const resourcesList = await baseQuery.limit(limit).offset(offset); diff --git a/server/routers/target/listTargets.ts b/server/routers/target/listTargets.ts index 88ad56a4..caa75683 100644 --- a/server/routers/target/listTargets.ts +++ b/server/routers/target/listTargets.ts @@ -8,7 +8,7 @@ import createHttpError from 'http-errors'; import { sql, eq } from 'drizzle-orm'; const listTargetsParamsSchema = z.object({ - resourceId: z.string().optional(), + resourceId: z.string().optional() }); const listTargetsSchema = z.object({