diff --git a/client/src/util/apiUtils.tsx b/client/src/util/apiUtils.tsx index d4b9a6e..d3fcd17 100644 --- a/client/src/util/apiUtils.tsx +++ b/client/src/util/apiUtils.tsx @@ -3,6 +3,7 @@ import axios from "axios"; const API = import.meta.env.APISTRING || "http://localhost:8080"; axios.defaults.withCredentials = true; +axios.defaults.headers['Content-Type'] = 'application/json'; export const getBaseAPI = async () => { return fetch(API); @@ -30,11 +31,9 @@ export const checkCredientials = async () => { url: API + '/auth', }); - const data = Promise.resolve(response.data); - return data; + return Promise.resolve(response.data); } catch (e: any) { - throw e; - + console.log(e); } } @@ -47,29 +46,47 @@ export const attemptLogout = async () => { } catch (e: any) { throw e; } - // const result = await fetch(API + 'auth/logout', { method: "DELETE" }).then(response => response.json()); - // return result; } -export const attemptRegister = async (data: IUser) => { - const result = await fetch(API + 'auth/register/', { +export const attemptRegister = async (body: IUser) => { + try { + const response = await axios({ method: "POST", - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify(data) - }).then(response => response.json()); - - return result; + url: API + '/auth/register', + data: JSON.stringify(body) + }) + + return Promise.resolve(response.data); + } catch (e: any) { + throw e; + } } // on recipe route export const getRecipeByID = async (id: string | number) => { - const result = await fetch(API + 'recipe/' + id).then(response => response.json()); - return result; + try { + const response = await axios({ + method: "GET", + url: API + '/recipe/' + id + }) + + return Promise.resolve(response.data); + } catch (e: any) { + throw e; + } } export const getAllRecipes = async () => { - const result = await fetch(API + 'recipe').then(response => response.json()); - return result; + try { + const response = await axios({ + method: "GET", + url: API + '/recipe' + }) + + return Promise.resolve(response.data); + } catch (e: any) { + throw e; + } + // const result = await fetch(API + 'recipe').then(response => response.json()); + // return result; } \ No newline at end of file diff --git a/server/db/examplevals.ts b/server/db/populate.ts similarity index 97% rename from server/db/examplevals.ts rename to server/db/populate.ts index 8f10da6..b2c2128 100644 --- a/server/db/examplevals.ts +++ b/server/db/populate.ts @@ -69,7 +69,7 @@ export default async function populate() { ` const populateComments = ` - INSERT INTO recipin.cmp_recipecomments + INSERT INTO recipin.recipecomments (commentbody, datecreated, recipeid, authorid) VALUES ('Very cool recipe!', $1, 2, 2), @@ -90,8 +90,9 @@ export default async function populate() { try { await pool.query(s, [now]); } catch(e: any) { + console.error(e); console.log('Last executed: ' + s); - throw new Error(e); + process.exit(0); } } diff --git a/server/db/seed.ts b/server/db/seed.ts index 4f3f81d..c586402 100644 --- a/server/db/seed.ts +++ b/server/db/seed.ts @@ -1,6 +1,6 @@ import { Client } from 'pg'; import dotenv from 'dotenv'; -import populate from "./examplevals"; +import populate from "./populate"; import pool from "."; dotenv.config(); @@ -73,7 +73,7 @@ dotenv.config(); ` const recipecomments = ` - CREATE TABLE IF NOT EXISTS recipin.cmp_recipecomments ( + CREATE TABLE IF NOT EXISTS recipin.recipecomments ( id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, commentbody varchar NOT NULL, datecreated varchar NOT NULL, @@ -122,7 +122,8 @@ dotenv.config(); await pool.query(s); } } catch(e: any) { - throw new Error(e); + console.error(e); + process.exit(0); } console.log("Database seed successful. Attempting to populate...");