fix some type errors

This commit is contained in:
Thomas Ruoff
2021-02-08 23:18:29 +01:00
parent 78af180567
commit d7478b5e9c
11 changed files with 232 additions and 135 deletions

View File

@@ -1,12 +1,10 @@
function checkStatus(res) {
function checkStatus(res: Response) {
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) {
export async function generatePdf(state: Record<string, string>) {
const options = {
method: 'POST',
headers: {
@@ -15,17 +13,19 @@ export function generatePdf(state) {
body: JSON.stringify(state),
}
return fetch('/api/pdf/generate/brief', options)
.then(checkStatus)
.then((res) => res.json())
const response = await fetch('/api/pdf/generate/brief', options)
checkStatus(response)
return response.json()
}
export function getLatest() {
return fetch('/api/pdf/latest')
.then(checkStatus)
.then((res) => res.json())
export async function getLatest() {
const response = await fetch('/api/pdf/latest')
checkStatus(response)
return response.json()
}
export function removeLatest(item) {
return fetch(`/api/pdf/latest/${item.id}`, { method: 'DELETE' }).then(checkStatus)
export async function removeLatest(item: { id: string }) {
const response = await fetch(`/api/pdf/latest/${item.id}`, { method: 'DELETE' })
checkStatus(response)
return response
}