Files
lootakalenteri-frontend/app/api.ts

60 lines
1.7 KiB
TypeScript

import { Box, CustomerData } from "./types";
export const fetchCustomerData = async (id: string) => {
const baseUrl = "http://localhost:9090";
try {
const response = await fetch(`${baseUrl}/loota/${id}`, {
method: 'GET',
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
throw error;
}
}
export const markBoxPickedUp = async (id: string) => {
const baseUrl = "http://localhost:9090";
try {
const response = await fetch(`${baseUrl}/loota/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ id: id, pickup_date: new Date().toISOString().split('.')[0] }),
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const updatedBox = await response.json();
return updatedBox;
} catch (error) {
throw error;
}
}
export const markBoxDelivered = async (id: string) => {
const baseUrl = "http://localhost:9090";
try {
const response = await fetch(`${baseUrl}/loota/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ id: id, pickup_date: null }),
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const updatedBox = await response.json();
return updatedBox;
} catch (error) {
throw error;
}
}