mirror of
https://github.com/tomru/pdfer.git
synced 2026-03-02 22:17:18 +01:00
33 lines
773 B
TypeScript
33 lines
773 B
TypeScript
function checkStatus(res) {
|
|
if (res.status < 200 || res.status >= 400) {
|
|
throw new Error(`Something went wrong (Status ${res.status}) - I do feel very sorry!`);
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
export function generatePdf(state){
|
|
const options = {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(state)
|
|
};
|
|
|
|
return fetch('/api/pdf/generate/brief', options)
|
|
.then(checkStatus)
|
|
.then(res => res.json());
|
|
}
|
|
|
|
export function getLatest() {
|
|
return fetch('/api/pdf/latest')
|
|
.then(checkStatus)
|
|
.then(res => res.json());
|
|
}
|
|
|
|
export function removeLatest(item) {
|
|
return fetch(`/api/pdf/latest/${item.id}`, {method: 'DELETE'})
|
|
.then(checkStatus);
|
|
}
|