diff --git a/server/controllers/CollectionCtl.ts b/server/controllers/CollectionCtl.ts new file mode 100644 index 0000000..82836f5 --- /dev/null +++ b/server/controllers/CollectionCtl.ts @@ -0,0 +1,3 @@ +export default class CollectionCtl { + +} \ No newline at end of file diff --git a/server/db/examplevals.ts b/server/db/examplevals.ts new file mode 100644 index 0000000..e69de29 diff --git a/server/db/seed.ts b/server/db/seed.ts index 54de6dd..adca384 100644 --- a/server/db/seed.ts +++ b/server/db/seed.ts @@ -5,6 +5,7 @@ dotenv.config(); (async function() { const setRole = ` SET ROLE postgres; + DROP SCHEMA IF EXISTS recipin CASCADE; CREATE SCHEMA IF NOT EXISTS recipin; ` @@ -31,10 +32,22 @@ dotenv.config(); CREATE TABLE IF NOT EXISTS recipin.collection ( id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, name varchar NOT NULL, + active boolean NOT NULL, + ismaincollection boolean NOT NULL, ownerid int REFERENCES recipin.appusers (id) ); ` + const groceryList = ` + CREATE TABLE IF NOT EXISTS recipin.grocerylist ( + id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + name varchar NOT NULL, + active boolean NOT NULL, + ownerid int REFERENCES recipin.appusers (id) + ); + ` + + const recipe = ` CREATE TABLE IF NOT EXISTS recipin.recipe ( id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, @@ -48,8 +61,8 @@ dotenv.config(); ` const recipeingredient = ` - CREATE TABLE IF NOT EXISTS recipin.cmp_recipe_ingredient ( - recipe_ingredient_id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + CREATE TABLE IF NOT EXISTS recipin.cmp_recipeingredient ( + recipeingredientid INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, quantity decimal, unit varchar, ingredientid int REFERENCES recipin.ingredient (id), @@ -59,7 +72,7 @@ dotenv.config(); ` const userscollections = ` - CREATE TABLE IF NOT EXISTS recipin.cmp_users_collections ( + CREATE TABLE IF NOT EXISTS recipin.cmp_userscollections ( userscollectionsid INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, collectionid int REFERENCES recipin.collection (id), usermemberid int REFERENCES recipin.appusers (id) @@ -67,7 +80,7 @@ dotenv.config(); `; const allStatements = [ - setRole, appusers, ingredient, collection, recipe, recipeingredient, userscollections + setRole, appusers, ingredient, collection, recipe, groceryList, recipeingredient, userscollections ] const client = new Client({ connectionString: process.env.CONSTRING }); diff --git a/server/models/collection.ts b/server/models/collection.ts new file mode 100644 index 0000000..de932d0 --- /dev/null +++ b/server/models/collection.ts @@ -0,0 +1,37 @@ +import { ICollection } from "../schemas"; +import pool from "../db"; + +export class Collection { + async getOne(id: string) { + try { + const statement = `SELECT * FROM recipin.collection WHERE id = $1`; + const values = [id]; + const result = await pool.query(statement, values); + return result; + } catch (e: any) { + throw new Error(e); + } + } + + async getAll() { + // requires clearance + try { + const statement = `SELECT * FROM recipin.collection`; + const result = await pool.query(statement); + return result; + } catch (e: any) { + throw new Error(e); + } + } + + async post(data: ICollection) { + try { + const statement = ` + INSERT INTO recipin.collection + () + ` + } catch (e: any) { + throw new Error(e); + } + } +} \ No newline at end of file diff --git a/server/routes/collection.ts b/server/routes/collection.ts index e69de29..70aca1b 100644 --- a/server/routes/collection.ts +++ b/server/routes/collection.ts @@ -0,0 +1,16 @@ +import { Express, Router } from "express"; + +const router = Router(); + +const collectionRoute = (app: Express) => { + app.use('/collection', router); + + router.get('/:id', async (req, res, next) => { + const { id } = req.params; + try { + + } catch(e) { + next(e); + } + }) +} \ No newline at end of file diff --git a/server/schemas/index.ts b/server/schemas/index.ts index 346dfac..903c8a7 100644 --- a/server/schemas/index.ts +++ b/server/schemas/index.ts @@ -1,35 +1,40 @@ export interface IUser { + id: string | number firstname: string lastname: string handle: string email: string password: string + active: boolean } export interface IRecipe { + id: string | number name: string description?: string preptime: string - ingredients: IIngredient[] removed: boolean + authoruserid: IUser["id"] } export interface IIngredient { + id: string | number name: string description?: string - active: boolean } export interface ICollection { + id: string | number name: string - owner: IUser - active: boolean - default: boolean + active: string + ismaincollection: boolean + owner: IUser["id"] } export interface IGroceryList { + id: string | number owner: IUser listname: string - recipes?: IRecipe[] + recipes?: IRecipe["id"][] active: boolean } \ No newline at end of file