Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
2.1 kB
2
Indexable
Never
const getMenuCategories = async () => {
    try {
        getBeeToken().then((token) => {
            console.log("userToken=>", token);

            const response = API.get(
                BEE_BASE_URL,
                {
                    "x-customer-token": token,
                },
                "/cart/v1/carts-by-token"
            );

            response.then((res) => {
                const slug = res.data.cart_store_groups[0].store_uuid;
                const lat = res.data.information.delivery?.lat;
                const long = res.data.information.delivery?.long;

                if (res.code === 200) {
                    const responseStore = API.get(
                        BEE_BASE_URL,
                        {
                            "x-customer-token": token,
                        },
                        `/store/v1/store/${slug}`,
                        {
                            lat: lat,
                            long: long,
                        }
                    );

                    responseStore.then((resStore) => {
                        const restaurantUuid = resStore.data.uuid;
                        const categoryResponse = API.get(
                            BEE_BASE_URL,
                            {
                                "x-customer-token": token,
                            },
                            `/menu/v1/store-categories?store_uuid=${restaurantUuid}&sort_type=1`
                        );

                        categoryResponse.then((catResponse) => {
                            if (catResponse.code === 200) {
                                console.log(
                                    "categoryResponse.data=>>",
                                    catResponse.data
                                );
                                return Promise.resolve(catResponse.data);
                            }
                        });
                    });
                }
            });
        });
    } catch (e) {
        console.log(e);
    }
};