status page pagination

This commit is contained in:
Alex Holliday committed 2025-12-11 18:41:38 +00:00
1 parent b6a3d1e34d
commit fe03451393
8 files changed
+222 -85

No files matched your search

@@ -35,7 +35,14 @@ class StatusPageController {
throw new ApiError("No team ID", 400);
}
const statusPages = await this.statusPageService.getAll(teamId);
const page = req.validatedQuery.page || 0;
const rowsPerPage = req.validatedQuery.rowsPerPage || 10;
const statusPages = await this.statusPageService.getAll(
teamId,
page,
rowsPerPage
);
res.status(200).json({
message: "OK",
data: statusPages,
+3 -2
View File
@@ -5,8 +5,8 @@ import { verifyToken } from "@/middleware/VerifyToken.js";
import { verifyTeamPermission } from "@/middleware/VerifyPermission.js";
import { addUserContext } from "@/middleware/AddUserContext.js";
import { PERMISSIONS } from "@/types/permissions.js";
import { validateBody } from "@/middleware/validation.js";
import { statusPageSchema } from "@/validation/index.js";
import { validateBody, validateQuery } from "@/middleware/validation.js";
import { statusPageSchema, statusPageQuerySchema } from "@/validation/index.js";
import { enforceMax } from "@/middleware/VerifyEntitlements.js";
class StatusPageRoutes {
@@ -37,6 +37,7 @@ class StatusPageRoutes {
verifyToken,
addUserContext,
verifyTeamPermission([PERMISSIONS.statusPages.read]),
validateQuery(statusPageQuerySchema),
this.controller.getAll
);
@@ -7,6 +7,7 @@ import {
Monitor,
} from "@/db/models/index.js";
import ApiError from "@/utils/ApiError.js";
import { count } from "node:console";
const SERVICE_NAME = "StatusPageService";
@@ -15,7 +16,11 @@ export interface IStatusPageService {
tokenizedUser: IUserContext,
statusPage: IStatusPage
) => Promise<IStatusPage>;
getAll: (teamId: string) => Promise<IStatusPage[]>;
getAll: (
teamId: string,
page: number,
rowsPerPage: number
) => Promise<{ statusPages: IStatusPage[]; count: number }>;
get: (teamId: string, id: string) => Promise<IStatusPage>;
getPublic: (url: string) => Promise<IStatusPage>;
update: (
@@ -81,8 +86,13 @@ class StatusPageService implements IStatusPageService {
return statusPage;
};
getAll = async (teamId: string) => {
return StatusPage.find({ teamId });
getAll = async (teamId: string, page: number, rowsPerPage: number) => {
const count = await StatusPage.countDocuments({ teamId });
const statusPages = await StatusPage.find({ teamId })
.skip(page * rowsPerPage)
.limit(rowsPerPage);
return { statusPages, count };
};
update = async (
+54
View File
@@ -672,3 +672,57 @@ export const updateRetentionPolicySchema = z.object({
.min(1, "Retention days must be at least 1")
.max(365, "Retention days cannot exceed 365 days"),
});
export const statusPageQuerySchema = z.object({
page: z
.string()
.optional()
.transform((val, ctx) => {
const num = Number(val);
if (!val) return;
if (Number.isNaN(num)) {
ctx.addIssue({
code: "custom",
message: "page must be a number",
});
return z.NEVER;
}
if (num < 0) {
ctx.addIssue({
code: "custom",
message: "page must greater than 0",
});
return z.NEVER;
}
return num;
}),
rowsPerPage: z
.string()
.optional()
.transform((val, ctx) => {
if (!val) return;
const num = Number(val);
if (Number.isNaN(num)) {
ctx.addIssue({
code: "custom",
message: "rowsPerPage must be a number",
});
return z.NEVER;
}
if (num < 0) {
ctx.addIssue({
code: "custom",
message: "rowsPerPage must be greater than 0",
});
return z.NEVER;
}
if (num > 100) {
ctx.addIssue({
code: "custom",
message: "rowsPerPage must be less than or equal to 100",
});
return z.NEVER;
}
return num;
}),
});