first commit
This commit is contained in:
3
src/composables/api/index.ts
Normal file
3
src/composables/api/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export { useMenuApi } from "./menu";
|
||||
export { useUserApi } from "./user";
|
||||
export { useOrdersApi } from "./orders";
|
40
src/composables/api/menu.ts
Normal file
40
src/composables/api/menu.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { category, menuItem } from "@/types";
|
||||
|
||||
export function useMenuApi() {
|
||||
function getCategories() {
|
||||
const resp = generateCategories();
|
||||
return resp;
|
||||
}
|
||||
|
||||
function getMenuItems() {
|
||||
const resp = generateMenuItems();
|
||||
return resp;
|
||||
}
|
||||
|
||||
return { getCategories, getMenuItems };
|
||||
}
|
||||
|
||||
function generateCategories() {
|
||||
const list: category[] = [];
|
||||
for (let i = 0; i < 5; i++) {
|
||||
list.push({
|
||||
id: i,
|
||||
title: `категория ${i + 1}`,
|
||||
});
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
function generateMenuItems() {
|
||||
const list: menuItem[] = [];
|
||||
for (let i = 0; i < 20; i++) {
|
||||
list.push({
|
||||
id: i,
|
||||
title: `товар ${i + 1}`,
|
||||
description: `описание ${i + 1}`,
|
||||
categoryId: i % 5,
|
||||
price: Math.floor(Math.random() * 200 + 100),
|
||||
});
|
||||
}
|
||||
return list;
|
||||
}
|
31
src/composables/api/orders.ts
Normal file
31
src/composables/api/orders.ts
Normal file
@ -0,0 +1,31 @@
|
||||
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 };
|
||||
}
|
34
src/composables/api/user.ts
Normal file
34
src/composables/api/user.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { convertFileToBase64String } from "../utils";
|
||||
|
||||
export function useUserApi() {
|
||||
async function login(data: { email: string; password: string }) {
|
||||
const resp = { name: "Иван", surname: "Иванов", email: data.email, image: "" };
|
||||
return resp;
|
||||
}
|
||||
|
||||
async function register(data: { name: string; surname: string; email: string; password: string; imageFile?: File }) {
|
||||
const resp = {
|
||||
name: data.name,
|
||||
surname: data.surname,
|
||||
email: data.email,
|
||||
image: data.imageFile != null ? await convertFileToBase64String(data.imageFile) : "",
|
||||
};
|
||||
return resp;
|
||||
}
|
||||
|
||||
async function changeUserData(data: { name: string; surname: string; imageFile?: File }) {
|
||||
const resp = {
|
||||
name: data.name,
|
||||
surname: data.surname,
|
||||
image: data.imageFile != null ? await convertFileToBase64String(data.imageFile) : "",
|
||||
};
|
||||
return resp;
|
||||
}
|
||||
|
||||
async function changeUserPassword(data: { oldPassword: string; newPassword: string; newPassword2: string }) {
|
||||
const resp = true;
|
||||
return resp;
|
||||
}
|
||||
|
||||
return { login, register, changeUserData, changeUserPassword };
|
||||
}
|
14
src/composables/utils/index.ts
Normal file
14
src/composables/utils/index.ts
Normal file
@ -0,0 +1,14 @@
|
||||
export async function convertFileToBase64String(file: File): Promise<string> {
|
||||
return new Promise((resolve) => {
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onload = function () {
|
||||
if (typeof reader.result === "string") {
|
||||
resolve(reader.result);
|
||||
} else {
|
||||
resolve("");
|
||||
}
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user