mirror of
https://github.com/tomru/pdfer.git
synced 2026-03-03 06:27:19 +01:00
fix some type errors
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user