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 ยท 67 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768import { eq } from "@openstatus/db";import { maintenance, maintenanceUpdate } from "@openstatus/db/src/schema";
import { emitAudit } from "../audit";import { requireScope } from "../auth";import { type ServiceContext, tryGetActorUserId, withTransaction,} from "../context";import type { MaintenanceUpdate } from "../types";import { getMaintenanceInWorkspace } from "./internal";import { AddMaintenanceUpdateInput } from "./schemas";
export async function addMaintenanceUpdate(args: { ctx: ServiceContext; input: AddMaintenanceUpdateInput;}): Promise<MaintenanceUpdate> { const { ctx } = args; requireScope(ctx, "write"); const input = AddMaintenanceUpdateInput.parse(args.input); const actorUserId = tryGetActorUserId(ctx.actor);
return withTransaction(ctx, async (tx) => { const record = await getMaintenanceInWorkspace({ tx, id: input.maintenanceId, workspaceId: ctx.workspace.id, });
const created = await tx .insert(maintenanceUpdate) .values({ maintenanceId: record.id, message: input.message, date: input.date ?? new Date(), createdBy: actorUserId, updatedBy: actorUserId, }) .returning() .get();
await touchMaintenance(tx, record.id, actorUserId);
await emitAudit(tx, ctx, { action: "maintenance_update.create", entityType: "maintenance_update", entityId: created.id, after: created, metadata: { maintenanceId: record.id }, });
return created; });}
/** Timeline writes bump the parent so feeds and caches see a change. */export async function touchMaintenance( tx: Parameters<Parameters<typeof withTransaction>[1]>[0], maintenanceId: number, actorUserId: number | null,): Promise<void> { await tx .update(maintenance) .set({ updatedAt: new Date(), updatedBy: actorUserId }) .where(eq(maintenance.id, maintenanceId));}