24 lines
1.0 KiB
TypeScript
24 lines
1.0 KiB
TypeScript
import { readBody } from "h3";
|
|
import { prisma } from "../../utils/prisma";
|
|
import { getAuthContext } from "../../utils/auth";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const auth = await getAuthContext(event);
|
|
const id = String(getRouterParam(event, "id") ?? "");
|
|
if (!id) throw createError({ statusCode: 400, statusMessage: "id is required" });
|
|
|
|
const body = await readBody<{ decision?: "accepted" | "rejected" | "pending"; decisionNote?: string }>(event);
|
|
const decision = body?.decision;
|
|
if (!decision) throw createError({ statusCode: 400, statusMessage: "decision is required" });
|
|
|
|
const nextDecision = decision === "accepted" ? "ACCEPTED" : decision === "rejected" ? "REJECTED" : "PENDING";
|
|
|
|
const res = await prisma.feedCard.updateMany({
|
|
where: { id, teamId: auth.teamId },
|
|
data: { decision: nextDecision, decisionNote: body?.decisionNote ?? null },
|
|
});
|
|
if (res.count === 0) throw createError({ statusCode: 404, statusMessage: "feed card not found" });
|
|
|
|
return { ok: true, id };
|
|
});
|