import { requireApiContext } from "@/server/api/context"; import { json, parsePagination, withApi } from "@/server/api/respond"; import { getSiteHistory } from "@/server/services/sites/history"; /** * GET /api/v1/sites/:id/history?onlyApproved=true&page&pageSize * Field roles always receive released deployments only (see getSiteHistory). */ export const GET = withApi(async (req: Request, { params }: { params: Promise<{ id: string }> }) => { const ctx = await requireApiContext("sites", "site:read"); const { id } = await params; const url = new URL(req.url); const { page, pageSize } = parsePagination(url, { pageSize: 50 }); const flag = url.searchParams.get("onlyApproved"); const result = await getSiteHistory(ctx, id, { onlyApproved: flag === "true" || flag === "1", page, pageSize }); return json({ data: result.items, pagination: { page: result.page, pageSize: result.pageSize, total: result.total }, meta: { onlyApproved: result.onlyApproved }, }); });