32 lines
888 B
TypeScript
32 lines
888 B
TypeScript
import { order } from "@/types";
|
|
import { useHookahStore } from "@/store";
|
|
|
|
export function useOrdersApi() {
|
|
const hookahStore = useHookahStore();
|
|
|
|
async function createOrder(order: { table: number; heavinessId: number; tasteIds: number[] }) {
|
|
const heaviness = hookahStore.heavinessList.find((x) => x.id === order.heavinessId);
|
|
const tastes = hookahStore.tastesList.filter((x) => order.tasteIds.includes(x.id));
|
|
|
|
const resp: order = {
|
|
id: 0,
|
|
status: "new",
|
|
table: order.table,
|
|
heaviness: heaviness ?? hookahStore.heavinessList[0],
|
|
tastes: tastes,
|
|
price: 123,
|
|
favourite: false,
|
|
};
|
|
|
|
return resp;
|
|
}
|
|
|
|
async function toggleFavourite(order: order) {
|
|
const resp = true;
|
|
|
|
return resp;
|
|
}
|
|
|
|
return { createOrder, toggleFavourite };
|
|
}
|