feat(status): add estimate customer actions
This commit is contained in:
parent
efdc4d5be1
commit
6f6891134e
9 changed files with 699 additions and 3 deletions
36
app/api/status/[token]/estimate/action-response.ts
Normal file
36
app/api/status/[token]/estimate/action-response.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
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 "";
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue