36 lines
1 KiB
TypeScript
36 lines
1 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import type { EstimateActionResult } from "@/lib/olympus/status";
|
|
|
|
export function estimateActionResponse(result: EstimateActionResult, successMessage: string) {
|
|
if (result.ok) {
|
|
return NextResponse.json({ message: successMessage });
|
|
}
|
|
|
|
if (result.reason === "invalid") {
|
|
return NextResponse.json(
|
|
{ message: "Dieser Statuslink ist ungültig oder nicht mehr aktiv." },
|
|
{ status: 404 },
|
|
);
|
|
}
|
|
|
|
if (result.reason === "unavailable") {
|
|
return NextResponse.json(
|
|
{ message: "Der Reparaturstatus ist momentan nicht abrufbar." },
|
|
{ status: 502 },
|
|
);
|
|
}
|
|
|
|
return NextResponse.json(
|
|
{ message: "Die Aktion konnte nicht abgeschlossen werden. Bitte versuchen Sie es erneut." },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
export async function readOptionalMessage(request: Request) {
|
|
try {
|
|
const body = await request.json() as { message?: unknown };
|
|
return typeof body.message === "string" ? body.message : "";
|
|
} catch {
|
|
return "";
|
|
}
|
|
}
|