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.
1.9 kB ยท 70 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071import { maintenance } from "@openstatus/db/src/schema";
import { emitAudit } from "../audit";import { requireScope } from "../auth";import { type ServiceContext, withTransaction } from "../context";import { ConflictError } from "../errors";import type { Maintenance } from "../types";import { assertPageInWorkspace, updatePageComponentAssociations, validatePageComponentIds,} from "./internal";import { CreateMaintenanceInput } from "./schemas";
export async function createMaintenance(args: { ctx: ServiceContext; input: CreateMaintenanceInput;}): Promise<Maintenance> { const { ctx } = args; requireScope(ctx, "write"); const input = CreateMaintenanceInput.parse(args.input);
return withTransaction(ctx, async (tx) => { await assertPageInWorkspace({ tx, pageId: input.pageId, workspaceId: ctx.workspace.id, });
const validated = await validatePageComponentIds({ tx, workspaceId: ctx.workspace.id, pageComponentIds: input.pageComponentIds, });
if (validated.pageId !== null && validated.pageId !== input.pageId) { throw new ConflictError( `pageId ${input.pageId} does not match the page (${validated.pageId}) of the selected components.`, ); }
const record = await tx .insert(maintenance) .values({ workspaceId: ctx.workspace.id, pageId: input.pageId, title: input.title, message: input.message, from: input.from, to: input.to, }) .returning() .get();
await updatePageComponentAssociations({ tx, maintenanceId: record.id, componentIds: validated.componentIds, });
await emitAudit(tx, ctx, { action: "maintenance.create", entityType: "maintenance", entityId: record.id, after: record, });
return record; });}