Untitled

mail@pastecode.io avatar
unknown
typescript
a year ago
4.9 kB
2
Indexable
Never
import { Category } from "@/types/Category";
import { Order } from "@/types/Order";
import { OrderStatus } from "@/types/OrderStatus";
import { Product } from "@/types/Product";

const tmpProduct: Product = {
    id: 847,
    image: 'https://saopaulosecreto.com/wp-content/uploads/2022/10/Get-Burger-1024x683.jpg',
    category: {
        id: 99,
        name: 'Burgers'
    },
    name: 'Burgão Boladão',
    price: 35.3,
    description: 'Um burger boladão muito legal'
}

export const api = {
    getOrders: async (): Promise<Order[]> => {
        return new Promise((resolve) => {
            setTimeout(() => {
                const orders: Order[] = [];
                const statuses: OrderStatus[] = ['preparing', 'sent', 'delivered'];

                for (let i = 0; i < 6; i++) {
                    orders.push({
                        id: parseInt('12' + i),
                        status: statuses[Math.floor(Math.random() * 3)],
                        orderDate: '2023-01-03 18:30',
                        userid: '1',
                        userName: ['Pedro', 'João', 'Julia'][Math.floor(Math.random() * 3)],
                        shippingAddress: {
                            id: 99,
                            cep: '9999999',
                            address: 'Rua bla bla',
                            number: '1200',
                            neighborhood: 'Algo',
                            city: 'São Paulo',
                            state: 'SP',
                            complement: 'AAA2'
                        },
                        shippingPrice: 12,
                        paymentType: 'card',
                        changeValue: 9,
                        cupom: 'BLA',
                        cupomDiscount: 2,
                        products: [
                            {
                                qt: 2,
                                product: tmpProduct
                            },
                            {
                                qt: 3,
                                product: {
                                    ...tmpProduct,
                                    id: 848,
                                    name: 'Burgão Boladão 2'
                                }
                            }
                        ],
                        subtotal: 99,
                        total: 120
                    });
                }


                resolve(orders);
            }, 1000);
        });
    },
    changeOrderStatus: async (id: number, newStatus: OrderStatus) => {
        return true;
    },
    getCategories: async (): Promise<Category[]> => {
        const list: Category[] = [
            { id: 99, name: 'Burgers', canDelete: false },
            { id: 98, name: 'Refrigerantes', canDelete: true },
            { id: 97, name: 'Doces', canDelete: true }
        ];
        return new Promise(resolve => {
            setTimeout(() => {
                resolve(list);
            }, 200);
        });
    },
    deleteCategory: async (id: number): Promise<boolean> => {
        return new Promise(resolve => {
            setTimeout(() => {
                resolve(true);
            }, 1000);
        });
    },
    createCategory: async (form: FormData) => {
        return new Promise(resolve => {
            setTimeout(() => {
                resolve(true);
            }, 1000);
        });
    },
    updateCategory: async (form: FormData) => {
        return new Promise(resolve => {
            setTimeout(() => {
                resolve(true);
            }, 1000);
        });
    },
    getProducts: async (): Promise<Product[]> => {
        const list: Product[] = [
            { ...tmpProduct, id: 123 },
            { ...tmpProduct, id: 124 },
            { ...tmpProduct, id: 125 },
            { ...tmpProduct, id: 126 },
            { ...tmpProduct, id: 127 },
            { ...tmpProduct, id: 128 },
            { ...tmpProduct, id: 129 },
            { ...tmpProduct, id: 130 }
        ];
        return new Promise(resolve => {
            setTimeout(() => {
                resolve(list);
            }, 500);
        });
    },
    deleteProduct: async (id: number): Promise<boolean> => {
        return new Promise(resolve => {
            setTimeout(() => {
                resolve(true);
            }, 1000);
        });
    },
    createProduct: async (form: FormData) => {
        return new Promise(resolve => {
            setTimeout(() => {
                resolve(true);
            }, 1000);
        });
    },
    updateProduct: async (form: FormData) => {
        return new Promise(resolve => {
            setTimeout(() => {
                resolve(true);
            }, 1000);
        });
    }
}