Skip to content

Commit

Permalink
Merge branch 'main' into david/refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
davidqing6432 committed Apr 9, 2024
2 parents 81144b2 + d0dce7e commit 675593e
Show file tree
Hide file tree
Showing 23 changed files with 979 additions and 173 deletions.
274 changes: 272 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/api/supabase/queries/order_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export async function fetchOrderProductsbyOrderId(
fetchOrderProductById(orderProductId),
),
);
console.log(newOrderProducts);

const orderProducts = await Promise.all(
newOrderProducts.map(async orderProduct =>
fetchProductWithQuantityById(orderProduct.product_id),
Expand Down
2 changes: 1 addition & 1 deletion src/api/supabase/queries/pickup_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function fetchNRecentPickupTimes(n: number): Promise<Pickup[]> {
const { data: getTimes, error } = await supabase
.from('pickup_times')
.select('*')
.order('start_time', { ascending: false })
.order('start_time', { ascending: true })
.limit(n);

if (error) {
Expand Down
21 changes: 19 additions & 2 deletions src/api/supabase/queries/product_queries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Product } from '../../../schema/schema';
import { Product, StorefrontButtons } from '../../../schema/schema';
import supabase from '../createClient';
import { fetchUser } from './user_queries';

Expand Down Expand Up @@ -85,14 +85,31 @@ export async function filterProduct(productType: string): Promise<Product[]> {
return products;
}

export async function convertCategoryToNumber(
productType: string,
): Promise<StorefrontButtons> {
const { data: buttonVal, error } = await supabase
.from('storefront_buttons')
.select('*')
.eq('name', productType)
.single();

if (error) {
throw new Error(`Error fetching products: ${error.message}`);
}
return buttonVal.id;
}

export async function fetchUnprescribedCategory(
productType: string,
): Promise<Product[]> {
const productTypeConverted = await convertCategoryToNumber(productType);

const { data: products, error } = await supabase
.from('product')
.select('*')
.eq('prescribed', false)
.eq('category', productType);
.eq('category', productTypeConverted);
if (error) {
throw new Error(`Error fetching products: ${error.message}`);
}
Expand Down
8 changes: 2 additions & 6 deletions src/api/supabase/queries/user_queries.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-console */
//

import supabase from '../createClient';
import { User, Product } from '../../../schema/schema';
import { fetchProductByID } from './product_queries';
Expand Down Expand Up @@ -119,8 +115,6 @@ export async function fetchUserAddress(uuid: string) {
.eq('user_id', uuid)
.single();

console.log('test', error);

if (error) {
console.error('Error fetching user data:', error);
}
Expand All @@ -143,7 +137,9 @@ export async function fetchCurrentUserAddress() {
.from('address')
.select('*')
.eq('user_id', user.id)
.limit(1)
.single();
console.log(address);

if (error) {
console.error('Error fetching user data:', error);
Expand Down
Loading

0 comments on commit 675593e

Please sign in to comment.