Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
2.5 kB ยท 77 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778import { Events } from "@openstatus/analytics";import { NotFoundError } from "@openstatus/services";import { UpdatePageComponentOrderInput, deletePageComponent, listPageComponents, updatePageComponentOrder,} from "@openstatus/services/page-component";import { z } from "zod";
import { toServiceCtx, toTRPCError } from "../service-adapter";import { createTRPCRouter, protectedProcedure } from "../trpc";
export const pageComponentRouter = createTRPCRouter({ list: protectedProcedure .input( z .object({ pageId: z.number().optional(), order: z.enum(["asc", "desc"]).optional(), }) .optional(), ) .query(async ({ ctx, input }) => { try { return await listPageComponents({ ctx: toServiceCtx(ctx), input: { pageId: input?.pageId, order: input?.order ?? "asc", }, }); } catch (err) { toTRPCError(err); } }),
delete: protectedProcedure .meta({ track: Events.DeletePageComponent, trackProps: ["id"] }) .input(z.object({ id: z.number() })) .mutation(async ({ ctx, input }) => { try { await deletePageComponent({ ctx: toServiceCtx(ctx), input: { id: input.id }, }); // Old contract returned drizzle `.returning()` โ callers today // ignore the payload, only `.mutate` success/failure matters. return [] as Array<never>; } catch (err) { // Preserve the pre-migration idempotent behaviour โ the old tRPC // delete silently succeeded when the row was already gone. if (err instanceof NotFoundError) return [] as Array<never>; toTRPCError(err); } }),
updateOrder: protectedProcedure .meta({ track: Events.UpdatePageComponentOrder, trackProps: ["pageId"] }) // Reuse the service's canonical input schema directly โ the local // flat `z.object` that lived here previously let components slip // through with `type: "monitor"` but no `monitorId`. The service // schema carries a `.refine` enforcing that invariant, so sharing // it keeps router validation in lockstep with the service. .input(UpdatePageComponentOrderInput) .mutation(async ({ ctx, input }) => { try { await updatePageComponentOrder({ ctx: toServiceCtx(ctx), input, }); return { success: true }; } catch (err) { toTRPCError(err); } }),});