This repository has been archived on 2026-11-18. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
everythingbutwork/apps/api/src/routers/risk.ts
T
Raffael SheikhandClaude Opus 4.8 a1cf6f3883
ci / quality (push) Failing after 45s
ci / build (push) Has been skipped
deploy / deploy (push) Successful in 53s
chore(format): Prettier über das gesamte Repo
Behebt die rote CI (format:check schlug an 36 Alt-Bestand-Dateien fehl:
migrations/meta-Snapshots, seed.ts, schemas/lead.ts, README u. a.) und erzwingt
nebenbei einen frischen web-Build beim Auto-Deploy (apps/web-Dateien geaendert
-> COPY-Layer invalidiert -> Vite baut neu).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-07 17:50:07 +02:00

60 lines
2.1 KiB
TypeScript

import { TRPCError } from '@trpc/server';
import { desc, eq } from 'drizzle-orm';
import { risk } from '@cockpit/db';
import { RiskSchemas } from '@cockpit/shared';
import { router, protectedProcedure } from '../trpc.js';
export const riskRouter = router({
forProject: protectedProcedure
.input(RiskSchemas.riskForProjectInput)
.query(async ({ ctx, input }) => {
return ctx.db
.select()
.from(risk)
.where(eq(risk.projectId, input.projectId))
.orderBy(desc(risk.showstopper), desc(risk.createdAt));
}),
create: protectedProcedure.input(RiskSchemas.createRiskInput).mutation(async ({ ctx, input }) => {
const [created] = await ctx.db
.insert(risk)
.values({
projectId: input.projectId,
kind: input.kind,
title: input.title,
wahrscheinlichkeit: input.wahrscheinlichkeit,
auswirkung: input.auswirkung,
herkunft: input.herkunft ?? null,
showstopper: input.showstopper,
massnahme: input.massnahme ?? null,
strategie: input.strategie ?? null,
ownerUserId: input.ownerUserId ?? null,
status: input.status,
createdBy: ctx.user.id,
})
.returning();
return created;
}),
update: protectedProcedure.input(RiskSchemas.updateRiskInput).mutation(async ({ ctx, input }) => {
const { id, ...patch } = input;
if (Object.keys(patch).length === 0) {
const existing = (await ctx.db.select().from(risk).where(eq(risk.id, id)).limit(1))[0];
if (!existing) throw new TRPCError({ code: 'NOT_FOUND', message: 'Eintrag nicht gefunden.' });
return existing;
}
const [updated] = await ctx.db
.update(risk)
.set({ ...patch, updatedAt: new Date() })
.where(eq(risk.id, id))
.returning();
if (!updated) throw new TRPCError({ code: 'NOT_FOUND', message: 'Eintrag nicht gefunden.' });
return updated;
}),
remove: protectedProcedure.input(RiskSchemas.removeRiskInput).mutation(async ({ ctx, input }) => {
await ctx.db.delete(risk).where(eq(risk.id, input.id));
return { ok: true as const };
}),
});