move store in local storage

This commit is contained in:
Thomas Ruoff
2021-03-10 23:53:35 +01:00
parent eaba68a779
commit 1633fad10b
13 changed files with 5414 additions and 193 deletions

View File

@@ -1,5 +1,5 @@
import { IDocProps } from '../interfaces/IDocProps'
import { ILatest } from '../interfaces/ILatest'
import { IStoreItem } from '../interfaces/IStoreItem'
function checkStatus(res: Response) {
if (res.status < 200 || res.status >= 400) {
@@ -7,7 +7,7 @@ function checkStatus(res: Response) {
}
}
export async function generatePdf(state: IDocProps): Promise<string> {
export async function generatePdf(state: IDocProps): Promise<{ url: string; data: IStoreItem }> {
const options = {
method: 'POST',
headers: {
@@ -18,18 +18,9 @@ export async function generatePdf(state: IDocProps): Promise<string> {
const response = await fetch('/api/document?template=brief', options)
checkStatus(response)
const { id } = await response.json()
return `/api/document/${id}`
}
export async function getLatest(): Promise<ILatest[]> {
const response = await fetch('/api/document/latest')
checkStatus(response)
return response.json()
}
export async function removeLatest(item: { id: string }) {
const response = await fetch(`/api/document/${item.id}`, { method: 'DELETE' })
checkStatus(response)
return response
const { id, data } = await response.json()
return {
url: `/api/document/${id}`,
data,
}
}