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.
3.9 kB ยท 129 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130import { Events } from "@openstatus/analytics";import { NotFoundError } from "@openstatus/services";import { createMaintenance, deleteMaintenance, listMaintenances, updateMaintenance,} from "@openstatus/services/maintenance";import { z } from "zod";
import { toServiceCtx, toTRPCError } from "../service-adapter";import { createTRPCRouter, protectedProcedure } from "../trpc";import { periods } from "./utils";
export const maintenanceRouter = createTRPCRouter({ delete: protectedProcedure .meta({ track: Events.DeleteMaintenance }) .input(z.object({ id: z.number() })) .mutation(async ({ ctx, input }) => { try { await deleteMaintenance({ ctx: toServiceCtx(ctx), input: { id: input.id }, }); // Preserve the old contract โ return an empty array that looks like // drizzle's `.returning()` result. Callers today ignore the payload, // only `.mutate` success/failure is observed. return [] as Array<never>; } catch (err) { // Preserve the pre-migration idempotent behaviour โ the old tRPC // delete silently succeeded when the row was already gone. Connect // still returns 404 on missing; external API semantics preserved. if (err instanceof NotFoundError) return [] as Array<never>; toTRPCError(err); } }),
list: protectedProcedure .input( z .object({ period: z.enum(periods).optional(), pageId: z.number().optional(), order: z.enum(["asc", "desc"]).optional(), }) .optional(), ) .query(async ({ ctx, input }) => { try { const { items } = await listMaintenances({ ctx: toServiceCtx(ctx), input: { pageId: input?.pageId, period: input?.period, order: input?.order ?? "desc", // tRPC callers (dashboard) want the full set โ see // statusReport.list for the same reasoning. limit: 10_000, offset: 0, }, }); return items; } catch (err) { toTRPCError(err); } }),
new: protectedProcedure .meta({ track: Events.CreateMaintenance }) .input( z.object({ pageId: z.number(), title: z.string(), message: z.string(), startDate: z.coerce.date(), endDate: z.coerce.date(), pageComponents: z.array(z.number()).optional(), notifySubscribers: z.boolean().nullish(), }), ) .mutation(async ({ ctx, input }) => { try { const record = await createMaintenance({ ctx: toServiceCtx(ctx), input: { title: input.title, message: input.message, from: input.startDate, to: input.endDate, pageId: input.pageId, pageComponentIds: input.pageComponents ?? [], }, }); return { ...record, notifySubscribers: input.notifySubscribers }; } catch (err) { toTRPCError(err); } }),
update: protectedProcedure .meta({ track: Events.UpdateMaintenance }) .input( z.object({ id: z.number(), title: z.string(), message: z.string(), startDate: z.coerce.date(), endDate: z.coerce.date(), pageComponents: z.array(z.number()).optional(), }), ) .mutation(async ({ ctx, input }) => { try { await updateMaintenance({ ctx: toServiceCtx(ctx), input: { id: input.id, title: input.title, message: input.message, from: input.startDate, to: input.endDate, pageComponentIds: input.pageComponents, }, }); } catch (err) { toTRPCError(err); } }),});