fall back to default statuses when board has no custom ones configured
This commit is contained in:
@@ -142,14 +142,18 @@ export default async function adminPostRoutes(app: FastifyInstance) {
|
|||||||
const reasonText = reason?.trim() || null;
|
const reasonText = reason?.trim() || null;
|
||||||
|
|
||||||
// check if the target status exists and is enabled for this board
|
// 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({
|
const boardConfig = await prisma.boardStatus.findMany({
|
||||||
where: { boardId: post.boardId, enabled: true },
|
where: { boardId: post.boardId, enabled: true },
|
||||||
});
|
});
|
||||||
if (boardConfig.length === 0) {
|
const validStatuses = boardConfig.length > 0
|
||||||
reply.status(400).send({ error: "No statuses configured for this board" });
|
? boardConfig.map((c) => ({ status: c.status, label: c.label }))
|
||||||
return;
|
: DEFAULT_STATUSES;
|
||||||
}
|
const statusEntry = validStatuses.find((c) => c.status === status);
|
||||||
const statusEntry = boardConfig.find((c) => c.status === status);
|
|
||||||
if (!statusEntry) {
|
if (!statusEntry) {
|
||||||
reply.status(400).send({ error: `Status "${status}" is not available for this board` });
|
reply.status(400).send({ error: `Status "${status}" is not available for this board` });
|
||||||
return;
|
return;
|
||||||
@@ -186,7 +190,7 @@ export default async function adminPostRoutes(app: FastifyInstance) {
|
|||||||
where: { postId: post.id },
|
where: { postId: post.id },
|
||||||
select: { voterId: true },
|
select: { voterId: true },
|
||||||
});
|
});
|
||||||
const statusLabel = statusEntry.label || status.replace(/_/g, " ");
|
const statusLabel = statusEntry?.label || status.replace(/_/g, " ");
|
||||||
const notifBody = reasonText
|
const notifBody = reasonText
|
||||||
? `"${post.title}" moved to ${statusLabel} - Reason: ${reasonText}`
|
? `"${post.title}" moved to ${statusLabel} - Reason: ${reasonText}`
|
||||||
: `"${post.title}" moved to ${statusLabel}`;
|
: `"${post.title}" moved to ${statusLabel}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user