Skip to content

Commit

Permalink
Buyankhuu'sChecl
Browse files Browse the repository at this point in the history
  • Loading branch information
BuyankhuuTsCAl committed Mar 19, 2024
1 parent 3d9bdc5 commit a53ca6e
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/api/supabase/queries/order_queries.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/* eslint-disable no-console */
//

import {
Order,
OrderProduct,
Product,
} from '../../../schema/schema';
import { Order, OrderProduct, Product } from '../../../schema/schema';
import { fetchUser } from './user_queries';
import { fetchProductByID } from './product_queries';
import supabase from '../createClient';

/**
Expand Down Expand Up @@ -78,7 +75,6 @@ export async function fetchOrdersByUser(): Promise<Order[]> {
return data;
}


/**
* gets all orders by user id and sorted it by creation data
* @param Order[] - An array of Order objects.
Expand Down Expand Up @@ -119,7 +115,6 @@ export async function fetchOrderProductById(
return orderProduct;
}


export async function fetchProductWithQuantityById(
productId: number,
): Promise<Product> {
Expand Down Expand Up @@ -193,12 +188,34 @@ export async function fetchCurrentOrdersByUser(): Promise<Order[]> {
return data;
}


export async function updateCartPickupId(pickupId: number) {
const user = await fetchUser();
const cartId = user.cart_id;
await supabase
.from('order')
.update({ pickup_time_id: pickupId })
.eq('id', cartId);
}
}

export async function fetchProductsFromOrder(
orderId: number,
): Promise<Product[]> {
const order = await getOrderById(orderId);
const products = order.order_product_id_array;

const productPromises = products.map(async (productID: number) => {
const product = await fetchProductFromOrderProduct(productID);
return product;
});
const fetchedProducts = await Promise.all(productPromises);

return fetchedProducts;
}

export async function fetchProductFromOrderProduct(
orderProductId: number,
): Promise<Product> {
const orderProduct = await fetchOrderProductById(orderProductId);
const product = await fetchProductByID(orderProduct.product_id);
return product;
}

0 comments on commit a53ca6e

Please sign in to comment.