mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-04 18:14:53 +02:00
Move nessicary info to url params
This commit is contained in:
parent
5dd860ef1c
commit
afe3d0659c
8 changed files with 184 additions and 38 deletions
|
@ -7,10 +7,13 @@ import HttpCode from '@server/types/HttpCode';
|
|||
import createHttpError from 'http-errors';
|
||||
import { sql, eq } from 'drizzle-orm';
|
||||
|
||||
const listTargetsParamsSchema = z.object({
|
||||
resourceId: z.string().optional(),
|
||||
});
|
||||
|
||||
const listTargetsSchema = 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)),
|
||||
resourceId: z.string().optional(),
|
||||
});
|
||||
|
||||
export async function listTargets(req: Request, res: Response, next: NextFunction): Promise<any> {
|
||||
|
@ -25,7 +28,19 @@ export async function listTargets(req: Request, res: Response, next: NextFunctio
|
|||
);
|
||||
}
|
||||
|
||||
const { limit, offset, resourceId } = parsedQuery.data;
|
||||
const { limit, offset } = parsedQuery.data;
|
||||
|
||||
const parsedParams = listTargetsParamsSchema.safeParse(req.params);
|
||||
if (!parsedParams.success) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.BAD_REQUEST,
|
||||
parsedParams.error.errors.map(e => e.message).join(', ')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const { resourceId } = parsedParams.data;
|
||||
|
||||
let baseQuery: any = db
|
||||
.select({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue