diff --git a/packages/api/src/routes/admin/posts.ts b/packages/api/src/routes/admin/posts.ts index 4dc2f0a..b28ff04 100644 --- a/packages/api/src/routes/admin/posts.ts +++ b/packages/api/src/routes/admin/posts.ts @@ -142,14 +142,18 @@ export default async function adminPostRoutes(app: FastifyInstance) { const reasonText = reason?.trim() || null; // check if the target status exists and is enabled for this board + const DEFAULT_STATUSES = [ + { status: "OPEN", label: "Open" }, { status: "UNDER_REVIEW", label: "Under Review" }, + { status: "PLANNED", label: "Planned" }, { status: "IN_PROGRESS", label: "In Progress" }, + { status: "DONE", label: "Done" }, { status: "DECLINED", label: "Declined" }, + ]; const boardConfig = await prisma.boardStatus.findMany({ where: { boardId: post.boardId, enabled: true }, }); - if (boardConfig.length === 0) { - reply.status(400).send({ error: "No statuses configured for this board" }); - return; - } - const statusEntry = boardConfig.find((c) => c.status === status); + const validStatuses = boardConfig.length > 0 + ? boardConfig.map((c) => ({ status: c.status, label: c.label })) + : DEFAULT_STATUSES; + const statusEntry = validStatuses.find((c) => c.status === status); if (!statusEntry) { reply.status(400).send({ error: `Status "${status}" is not available for this board` }); return; @@ -186,7 +190,7 @@ export default async function adminPostRoutes(app: FastifyInstance) { where: { postId: post.id }, select: { voterId: true }, }); - const statusLabel = statusEntry.label || status.replace(/_/g, " "); + const statusLabel = statusEntry?.label || status.replace(/_/g, " "); const notifBody = reasonText ? `"${post.title}" moved to ${statusLabel} - Reason: ${reasonText}` : `"${post.title}" moved to ${statusLabel}`;