19 lines
591 B
TypeScript
19 lines
591 B
TypeScript
import type { QuestionnaireSaveHandler } from "../../lib";
|
|
|
|
export const saveDraft: QuestionnaireSaveHandler = async request => {
|
|
const response = await fetch("/api/claims/current/draft", {
|
|
method: "PATCH",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"If-Match": JSON.stringify(request.revision),
|
|
},
|
|
body: JSON.stringify(request),
|
|
});
|
|
|
|
// Reject failures so the renderer stays on the page and allows a retry.
|
|
if (!response.ok) throw new Error("Could not save your answers.");
|
|
|
|
// The server returns { revision: number }.
|
|
return response.json();
|
|
};
|