mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-31 13:06:32 +00:00
Paginate the tables with queries
This commit is contained in:
@@ -21,7 +21,7 @@ import createHttpError from "http-errors";
|
||||
import logger from "@server/logger";
|
||||
import { fromError } from "zod-validation-error";
|
||||
import { OpenAPITags, registry } from "@server/openApi";
|
||||
import { and, eq, inArray, sql } from "drizzle-orm";
|
||||
import { and, eq, inArray, like, sql } from "drizzle-orm";
|
||||
|
||||
const paramsSchema = z.strictObject({
|
||||
orgId: z.string().nonempty()
|
||||
@@ -40,6 +40,7 @@ const querySchema = z.strictObject({
|
||||
.default("0")
|
||||
.transform(Number)
|
||||
.pipe(z.number().int().nonnegative()),
|
||||
query: z.string().optional(),
|
||||
siteId: z
|
||||
.string()
|
||||
.optional()
|
||||
@@ -112,7 +113,7 @@ export async function listAlertRules(
|
||||
)
|
||||
);
|
||||
}
|
||||
const { limit, offset, siteId, resourceId } = parsedQuery.data;
|
||||
const { limit, offset, query, siteId, resourceId } = parsedQuery.data;
|
||||
|
||||
// Resolve siteId filter → matching alertRuleIds
|
||||
let siteFilterRuleIds: number[] | null = null;
|
||||
@@ -160,6 +161,9 @@ export async function listAlertRules(
|
||||
|
||||
const whereClause = and(
|
||||
eq(alertRules.orgId, orgId),
|
||||
query
|
||||
? like(sql`LOWER(${alertRules.name})`, `%${query.toLowerCase()}%`)
|
||||
: undefined,
|
||||
siteFilterRuleIds !== null
|
||||
? inArray(alertRules.alertRuleId, siteFilterRuleIds)
|
||||
: undefined,
|
||||
|
||||
@@ -17,7 +17,7 @@ import HttpCode from "@server/types/HttpCode";
|
||||
import createHttpError from "http-errors";
|
||||
import logger from "@server/logger";
|
||||
import { OpenAPITags, registry } from "@server/openApi";
|
||||
import { and, eq, isNull, sql } from "drizzle-orm";
|
||||
import { and, eq, like, sql } from "drizzle-orm";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import { z } from "zod";
|
||||
import { fromError } from "zod-validation-error";
|
||||
@@ -39,7 +39,8 @@ const querySchema = z.object({
|
||||
.optional()
|
||||
.default("0")
|
||||
.transform(Number)
|
||||
.pipe(z.int().nonnegative())
|
||||
.pipe(z.int().nonnegative()),
|
||||
query: z.string().optional()
|
||||
});
|
||||
|
||||
registry.registerPath({
|
||||
@@ -80,10 +81,16 @@ export async function listHealthChecks(
|
||||
)
|
||||
);
|
||||
}
|
||||
const { limit, offset } = parsedQuery.data;
|
||||
const { limit, offset, query } = parsedQuery.data;
|
||||
|
||||
const whereClause = and(
|
||||
eq(targetHealthCheck.orgId, orgId),
|
||||
query
|
||||
? like(
|
||||
sql`LOWER(${targetHealthCheck.name})`,
|
||||
`%${query.toLowerCase()}%`
|
||||
)
|
||||
: undefined
|
||||
);
|
||||
|
||||
const list = await db
|
||||
|
||||
Reference in New Issue
Block a user