From 4ad2af6431c81eddc5103fd0b55e98c115c67637 Mon Sep 17 00:00:00 2001 From: EthanAuyeung Date: Wed, 11 Oct 2023 17:40:37 -0700 Subject: [PATCH 1/4] Fixed deployment typing --- src/app/login/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index cf6479bb..4a7a7cde 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -8,7 +8,7 @@ import { signOut, } from '../../api/supabase/auth/auth'; -export default function Login() { +export default function App() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); From fb6485ef31c00762040ad3c5a05b0084534b7d81 Mon Sep 17 00:00:00 2001 From: EthanAuyeung Date: Wed, 11 Oct 2023 17:44:40 -0700 Subject: [PATCH 2/4] vercel errors --- src/app/login/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index 4a7a7cde..cf6479bb 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -8,7 +8,7 @@ import { signOut, } from '../../api/supabase/auth/auth'; -export default function App() { +export default function Login() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); From e560b2e481df93da14b596fd06d873272da96850 Mon Sep 17 00:00:00 2001 From: Kevin Cai Date: Wed, 11 Oct 2023 22:26:19 -0700 Subject: [PATCH 3/4] Delete --- src/schema/schema.ts | 38 ------- src/supabase/order_queries.ts | 163 ----------------------------- src/supabase/pickup_queries.ts | 59 ----------- src/supabase/product_queries.ts | 58 ---------- src/supabase/tests/order_test.ts | 75 ------------- src/supabase/tests/pickup_test.ts | 25 ----- src/supabase/tests/product_test.ts | 25 ----- src/supabase/tests/user_test.ts | 41 -------- src/supabase/user_queries.ts | 103 ------------------ 9 files changed, 587 deletions(-) delete mode 100644 src/schema/schema.ts delete mode 100644 src/supabase/order_queries.ts delete mode 100644 src/supabase/pickup_queries.ts delete mode 100644 src/supabase/product_queries.ts delete mode 100644 src/supabase/tests/order_test.ts delete mode 100644 src/supabase/tests/pickup_test.ts delete mode 100644 src/supabase/tests/product_test.ts delete mode 100644 src/supabase/tests/user_test.ts delete mode 100644 src/supabase/user_queries.ts diff --git a/src/schema/schema.ts b/src/schema/schema.ts deleted file mode 100644 index ff8d3d18..00000000 --- a/src/schema/schema.ts +++ /dev/null @@ -1,38 +0,0 @@ -export type User = { - email: string; - password: string; - first_name: string; - last_name: string; - pet_information: string; - user_id: string; // UUID - order_option: boolean; - address: number; // index of the address the street, city, and zipcode to build the address - street: string[]; - city: string[]; - zipcode: string[]; -}; - -export type Order = { - id: number; // bigint generated by default as identity - user_id: string; // UUID not null - cart: number; // bigint[] null - status: string; // bigint null - pickup_time: number; // bigint null -}; - -export type Schedule = { - id: number; // bigint generated by default as identity - date: string; // text not null - start_time: string; // text null - end_time: string; // text null -}; - -export type Product = { - product_id: number; // bigint generated by default as identity - name: string; // text not null; - description: string; // text null; - category: string; // numeric not null; - quantity: number; // numeric not null; - photo: string; // text null; - updated_at: string; // timestamp with time zone not null default now(); -}; diff --git a/src/supabase/order_queries.ts b/src/supabase/order_queries.ts deleted file mode 100644 index e7c0a4a4..00000000 --- a/src/supabase/order_queries.ts +++ /dev/null @@ -1,163 +0,0 @@ -/* eslint-disable no-console */ -// - -import { - PostgrestSingleResponse, - PostgrestError, - createClient, -} from '@supabase/supabase-js'; -import { Order } from '../schema/schema'; - -// Replace these with your Supabase project URL and API key -const supabaseUrl = process.env.SUPABASE_URL; -const supabaseApiKey = process.env.SUPABASE_KEY; - -// Initialize the Supabase client -const supabase = createClient(supabaseUrl ?? '', supabaseApiKey ?? ''); - -export async function fetchOrders(): Promise< - PostgrestSingleResponse | { data: never[]; error: PostgrestError } -> { - try { - const { data: orders, error } = await supabase - .from('Order') // Update to the "Order" table - .select('*') - .single(); - - if (error) { - console.error('Error fetching data:', error); - return { data: [], error }; - } - - return orders; - } catch (error) { - console.error('Error:', error); - throw error; - } -} - -export async function fetchOrderByUUID( - uuid: string, -): Promise> { - try { - const { data: order, error } = await supabase - .from('Order') // Update to the "Order" table - .select('*') - .eq('id', uuid) - .single(); - - if (error) { - console.error('Error fetching order data:', error); - } - - return order; - } catch (error) { - console.error('Error:', error); - throw error; - } -} - -export async function getOrdersByUserId( - userId: string, -): Promise< - PostgrestSingleResponse | { data: never[]; error: PostgrestError } -> { - try { - const { data: orders, error } = await supabase - .from('Order') - .select('*') - .eq('user_id', userId) - .single(); - - if (error) { - console.error('Error fetching orders:', error); - return { data: [], error }; - } - - return orders; - } catch (error) { - console.error('Error:', error); - throw error; - } -} - -// Function to get an order by its ID -export async function getOrderById( - orderId: string, -): Promise> { - try { - const { data: order, error } = await supabase - .from('Order') - .select('*') - .eq('id', orderId) - .single(); - - if (error) { - console.error('Error fetching order:', error); - } - - return order; - } catch (error) { - console.error('Error:', error); - throw error; - } -} - -export async function toggleOrderProgress( - orderId: string, -): Promise> { - try { - // Fetch the order by ID to get its current "approved" value - const { data: currentOrder, error: fetchError } = await supabase - .from('Order') - .select('approved') - .eq('id', orderId) - .single(); - - if (fetchError) { - console.error('Error fetching order:', fetchError); - throw fetchError; - } - - // Toggle the "approved" value - const updatedApprovedValue = !currentOrder?.approved; - - // Update the order with the new "approved" value - const { data: updatedOrder, error: updateError } = await supabase - .from('Order') - .update({ approved: updatedApprovedValue }) - .eq('id', orderId) - .single(); - - if (updateError) { - console.error('Error updating order:', updateError); - throw updateError; - } - - return updatedOrder; - } catch (error) { - console.error('Error:', error); - throw error; - } -} - -export async function updateAllOrdersProgressToTrue(): Promise< - boolean | string -> { - try { - // Update all orders to set "approved" to true - const { error: updateError } = await supabase - .from('Order') - .update({ approved: true }); - - if (updateError) { - console.error('Error updating orders:', updateError); - return 'Update failed'; // Return an error message if the update fails - } - - return true; // Return true if the update succeeds - } catch (error) { - console.error('Error:', error); - return 'Update failed'; // Return an error message if an exception occurs - } -} diff --git a/src/supabase/pickup_queries.ts b/src/supabase/pickup_queries.ts deleted file mode 100644 index f7b6f46e..00000000 --- a/src/supabase/pickup_queries.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ -/* eslint-disable no-console */ -// - -import { - PostgrestSingleResponse, - PostgrestError, - createClient, -} from '@supabase/supabase-js'; -import { Schedule } from '../schema/schema'; - -// Replace these with your Supabase project URL and API key -const supabaseUrl = process.env.SUPABASE_URL; -const supabaseApiKey = process.env.SUPABASE_KEY; - -// Initialize the Supabase client -const supabase = createClient(supabaseUrl ?? '', supabaseApiKey ?? ''); - -export async function fetchPickupData(): Promise< - PostgrestSingleResponse | { data: never[]; error: PostgrestError } -> { - try { - const { data: pickupTimes, error } = await supabase - .from('Pickup_Times') - .select('*') - .single(); - - if (error) { - console.error('Error fetching data:', error); - return { data: [], error }; - } - - return pickupTimes; - } catch (error) { - console.error('Error:', error); - throw error; - } -} - -export async function fetchPickupTimesByUUID( - uuid: string, -): Promise> { - try { - const { data: pickupTimes, error } = await supabase - .from('Pickup_Times') - .select('*') - .eq('id', uuid) - .single(); - - if (error) { - console.error('Error fetching user data:', error); - } - - return pickupTimes; - } catch (error) { - console.error('Error:', error); - throw error; - } -} diff --git a/src/supabase/product_queries.ts b/src/supabase/product_queries.ts deleted file mode 100644 index dd5a5cd7..00000000 --- a/src/supabase/product_queries.ts +++ /dev/null @@ -1,58 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ -/* eslint-disable no-console */ -// -import { - PostgrestSingleResponse, - PostgrestError, - createClient, -} from '@supabase/supabase-js'; -import { Product } from '../schema/schema'; - -// Replace these with your Supabase project URL and API key -const supabaseUrl = process.env.SUPABASE_URL; -const supabaseApiKey = process.env.SUPABASE_KEY; - -// Initialize the Supabase client -const supabase = createClient(supabaseUrl ?? '', supabaseApiKey ?? ''); - -export async function fetchProducts(): Promise< - PostgrestSingleResponse | { data: never[]; error: PostgrestError } -> { - try { - const { data: products, error } = await supabase - .from('Product') - .select('*') - .single(); - - if (error) { - console.error('Error fetching data:', error); - return { data: [], error }; - } - - return products; - } catch (error) { - console.error('Error:', error); - throw error; - } -} - -export async function fetchProductByID( - productId: string, -): Promise> { - try { - const { data: product, error } = await supabase - .from('Product') - .select('*') - .eq('product_id', productId) - .single(); - - if (error) { - console.error('Error fetching product data:', error); - } - - return product; - } catch (error) { - console.error('Error:', error); - throw error; - } -} diff --git a/src/supabase/tests/order_test.ts b/src/supabase/tests/order_test.ts deleted file mode 100644 index 47510f91..00000000 --- a/src/supabase/tests/order_test.ts +++ /dev/null @@ -1,75 +0,0 @@ -/* eslint-disable no-console */ -// - -import { - fetchOrders, - fetchOrderByUUID, - getOrdersByUserId, - getOrderById, - toggleOrderProgress, - updateAllOrdersProgressToTrue, -} from '../order_queries'; // Replace './your-module' with the actual path to your module - -// Test fetching all orders -export async function testFetchOrders() { - try { - const result = await fetchOrders(); - console.log('Fetch Orders Result:', result); - } catch (error) { - console.error('Test Fetch Orders Error:', error); - } -} - -// Test fetching an order by UUID -export async function testFetchOrderByUUID() { - const uuid = 'SAMPLE_ORDER_ID'; // Replace with a valid order ID - try { - const result = await fetchOrderByUUID(uuid); - console.log('Fetch Order by UUID Result:', result); - } catch (error) { - console.error('Test Fetch Order by UUID Error:', error); - } -} - -// Test fetching orders by user ID -export async function testGetOrdersByUserId() { - const userId = '3b4a1317-b9ea-4cbd-95d7-e959aa80d1ea'; // Replace with a valid user ID - try { - const result = await getOrdersByUserId(userId); - console.log('Get Orders by User ID Result:', result); - } catch (error) { - console.error('Test Get Orders by User ID Error:', error); - } -} - -// Test fetching an order by ID -export async function testGetOrderById() { - const orderId = '2'; // Replace with a valid order ID - try { - const result = await getOrderById(orderId); - console.log('Get Order by ID Result:', result); - } catch (error) { - console.error('Test Get Order by ID Error:', error); - } -} - -// Test toggling order progress -export async function testToggleOrderProgress() { - const orderId = '2'; // Replace with a valid order ID - try { - const result = await toggleOrderProgress(orderId); - console.log('Toggle Order Progress Result:', result); - } catch (error) { - console.error('Test Toggle Order Progress Error:', error); - } -} - -// Test updating all orders' progress to true -export async function testUpdateAllOrdersProgressToTrue() { - try { - const result = await updateAllOrdersProgressToTrue(); - console.log('Update All Orders Progress Result:', result); - } catch (error) { - console.error('Test Update All Orders Progress Error:', error); - } -} diff --git a/src/supabase/tests/pickup_test.ts b/src/supabase/tests/pickup_test.ts deleted file mode 100644 index c8fb9055..00000000 --- a/src/supabase/tests/pickup_test.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* eslint-disable no-console */ -// - -import { fetchPickupData, fetchPickupTimesByUUID } from '../pickup_queries'; // Replace './your-module' with the actual path to your module - -// Test fetching data -export async function testFetchPickupData() { - try { - const result = await fetchPickupData(); - console.log('Fetch Data Result:', result); - } catch (error) { - console.error('Test Fetch Data Error:', error); - } -} - -// Test fetching pickup times by UUID -export async function testFetchPickupTimesByUUID() { - const uuid = '1'; // Replace with a valid UUID - try { - const result = await fetchPickupTimesByUUID(uuid); - console.log('Fetch Pickup Times by UUID Result:', result); - } catch (error) { - console.error('Test Fetch Pickup Times by UUID Error:', error); - } -} diff --git a/src/supabase/tests/product_test.ts b/src/supabase/tests/product_test.ts deleted file mode 100644 index b5d502d2..00000000 --- a/src/supabase/tests/product_test.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* eslint-disable no-console */ -// - -import { fetchProducts, fetchProductByID } from '../product_queries'; // Replace './your-module' with the actual path to your module - -// Test fetching all products -export async function testFetchProducts() { - try { - const result = await fetchProducts(); - console.log('Fetch Products Result:', result); - } catch (error) { - console.error('Test Fetch Products Error:', error); - } -} - -// Test fetching a product by name -export async function testFetchProductByName() { - const productId = '1'; // Replace with a valid product name - try { - const result = await fetchProductByID(productId); - console.log('Fetch Product by Name Result:', result); - } catch (error) { - console.error('Test Fetch Product by Name Error:', error); - } -} diff --git a/src/supabase/tests/user_test.ts b/src/supabase/tests/user_test.ts deleted file mode 100644 index 37a19898..00000000 --- a/src/supabase/tests/user_test.ts +++ /dev/null @@ -1,41 +0,0 @@ -/* eslint-disable no-console */ -// - -import { - fetchUserData, - fetchUserByUUID, - addUserAddress, -} from '../user_queries'; - -export async function testFetchUserData() { - try { - const result = await fetchUserData(); - console.log('Fetch Data Result:', result); - } catch (error) { - console.error('Test Fetch Data Error:', error); - } -} - -export async function testFetchUserByUUID() { - const uuid = '3b4a1317-b9ea-4cbd-95d7-e959aa80d1ea'; // Replace with a valid user ID - try { - const result = await fetchUserByUUID(uuid); - console.log('Fetch User by UUID Result:', result); - } catch (error) { - console.error('Test Fetch User by UUID Error:', error); - } -} - -export async function testAddUserAddress() { - const uuid = '3b4a1317-b9ea-4cbd-95d7-e959aa80d1ea'; // Replace with a valid user ID - const newStreet = '123 New Street'; - const newCity = 'New City'; - const newZipcode = '12345'; - - try { - const result = await addUserAddress(uuid, newStreet, newCity, newZipcode); - console.log('Add User Address Result:', result); - } catch (error) { - console.error('Test Add User Address Error:', error); - } -} diff --git a/src/supabase/user_queries.ts b/src/supabase/user_queries.ts deleted file mode 100644 index 3a934f90..00000000 --- a/src/supabase/user_queries.ts +++ /dev/null @@ -1,103 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ -/* eslint-disable no-console */ -// - -import { - PostgrestSingleResponse, - PostgrestError, - createClient, -} from '@supabase/supabase-js'; -import { User } from '../schema/schema'; - -// Replace these with your Supabase project URL and API key -const supabaseUrl = process.env.SUPABASE_URL; -const supabaseApiKey = process.env.SUPABASE_KEY; - -// Initialize the Supabase client -const supabase = createClient(supabaseUrl ?? '', supabaseApiKey ?? ''); - -export async function fetchUserData(): Promise< - PostgrestSingleResponse | { data: never[]; error: PostgrestError } -> { - try { - const { data: users, error } = await supabase - .from('Users') - .select('*') - .single(); - - if (error) { - console.error('Error fetching data:', error); - return { data: [], error }; - } - return users; - } catch (error) { - console.error('Error:', error); - throw error; - } -} - -export async function fetchUserByUUID( - uuid: string, -): Promise> { - try { - const { data: user, error } = await supabase - .from('Users') - .select('*') - .eq('user_id', uuid) - .single(); - - if (error) { - console.error('Error fetching user data:', error); - } - - return user; - } catch (error) { - console.error('Error:', error); - throw error; - } -} - -export async function addUserAddress( - uuid: string, - newStreet: string, - newCity: string, - newZipcode: string, -): Promise> { - try { - const { data: existingUser, error: selectError } = await supabase - .from('Users') - .select('street, city, zipcode') - .eq('user_id', uuid) - .single(); - - if (selectError) { - console.error('Error selecting user data:', selectError); - throw selectError; - } - - // Append new values to the arrays - const updatedStreet = [...(existingUser?.street || []), newStreet]; - const updatedCity = [...(existingUser?.city || []), newCity]; - const updatedZipcode = [...(existingUser?.zipcode || []), newZipcode]; - - const { data, error } = await supabase - .from('Users') - .update({ - street: updatedStreet, - city: updatedCity, - zipcode: updatedZipcode, - }) - .eq('user_id', uuid) - .single(); - - if (error) { - console.error('Error updating user data:', error); - throw error; - } - - return { data, error: null, status: 200, statusText: 'OK', count: 1 }; - } catch (error) { - console.error('Error:', error); - throw error; - } -} From 99eacc07b0501583756aaa05d77d5403f3e9abff Mon Sep 17 00:00:00 2001 From: Kevin Cai Date: Wed, 11 Oct 2023 22:31:36 -0700 Subject: [PATCH 4/4] Del all --- src/app/page.tsx | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index 57e78583..9907141d 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,39 +1,7 @@ import Link from 'next/link'; -import { - testFetchUserData, - testFetchUserByUUID, - testAddUserAddress, -} from '../supabase/tests/user_test'; -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { - testFetchOrderByUUID, - testFetchOrders, - testGetOrderById, - testToggleOrderProgress, - testUpdateAllOrdersProgressToTrue, -} from '../supabase/tests/order_test'; -import { - testFetchProducts, - testFetchProductByName, -} from '../supabase/tests/product_test'; -import { - testFetchPickupData, - testFetchPickupTimesByUUID, -} from '../supabase/tests/pickup_test'; export default function Checkout() { - testFetchUserData(); - testFetchUserByUUID(); - testAddUserAddress(); - testFetchOrderByUUID(); - testFetchOrders(); - testGetOrderById(); - testToggleOrderProgress(); - testFetchProducts(); - testFetchProductByName(); - testFetchPickupData(); - testFetchPickupTimesByUUID(); - // testUpdateAllOrdersProgressToTrue(); + return (