mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-04 10:05:53 +02:00
Tested list endpoints
This commit is contained in:
parent
afe3d0659c
commit
bbc06245fa
4 changed files with 25 additions and 33 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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<any> {
|
||||
|
@ -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);
|
||||
|
|
|
@ -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({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue