From 1b5856fa8f9135165f4ab716dc30465134b3870f Mon Sep 17 00:00:00 2001 From: Mikayla Dobson <93477693+innocuous-symmetry@users.noreply.github.com> Date: Thu, 8 Dec 2022 13:51:53 -0600 Subject: [PATCH] updates to db; course, cuisine added --- server/controllers/CourseCtl.ts | 0 server/controllers/CuisineCtl.ts | 0 server/db/populate.ts | 36 ++++++++++++++++++++------ server/db/seed.ts | 28 ++++++++++---------- server/db/sql/create/createcourse.sql | 7 +++++ server/db/sql/create/createcuisine.sql | 7 +++++ server/db/sql/create/createrecipe.sql | 4 ++- server/models/course.ts | 0 server/models/cuisine.ts | 0 server/routes/course.ts | 0 server/routes/cuisine.ts | 0 server/schemas/index.ts | 16 ++++++++++++ 12 files changed, 76 insertions(+), 22 deletions(-) create mode 100644 server/controllers/CourseCtl.ts create mode 100644 server/controllers/CuisineCtl.ts create mode 100644 server/db/sql/create/createcourse.sql create mode 100644 server/db/sql/create/createcuisine.sql create mode 100644 server/models/course.ts create mode 100644 server/models/cuisine.ts create mode 100644 server/routes/course.ts create mode 100644 server/routes/cuisine.ts diff --git a/server/controllers/CourseCtl.ts b/server/controllers/CourseCtl.ts new file mode 100644 index 0000000..e69de29 diff --git a/server/controllers/CuisineCtl.ts b/server/controllers/CuisineCtl.ts new file mode 100644 index 0000000..e69de29 diff --git a/server/db/populate.ts b/server/db/populate.ts index db2b22f..4219f6c 100644 --- a/server/db/populate.ts +++ b/server/db/populate.ts @@ -16,14 +16,34 @@ export default async function populate() { ; ` + const populateCuisines = ` + INSERT INTO recipin.cuisine (name, datecreated, datemodified, active) VALUES + ('Thai', $1, $1, true), + ('American', $1, $1, true), + ('Tex Mex', $1, $1, true), + ('Italian', $1, $1, true), + ('Korean', $1, $1, true) + ; + ` + + const populateCourses = ` + INSERT INTO recipin.course (name, datecreated, datemodified, active) VALUES + ('Breakfast', $1, $1, true), + ('Lunch', $1, $1, true), + ('Dinner', $1, $1, true), + ('Appetizers', $1, $1, true), + ('Dessert', $1, $1, true) + ; + ` + const populateRecipes = ` INSERT INTO recipin.recipe - (name, description, preptime, authoruserid, datecreated, datemodified) + (name, description, preptime, authoruserid, cuisineid, courseid, datecreated, datemodified) VALUES - ('Pad Thai', 'noodles', '1 hour', 1, $1, $1), - ('Tacos', null, '30 minutes', 1, $1, $1), - ('Garlic knots', null, '1 hour', 4, $1, $1), - ('Cacio e pepe', 'stinky pasta', '1 hour', 3, $1, $1) + ('Pad Thai', 'noodles', '1 hour', 1, 1, 3, $1, $1), + ('Tacos', null, '30 minutes', 1, 3, 3, $1, $1), + ('Garlic knots', null, '1 hour', 4, 4, 3, $1, $1), + ('Cacio e pepe', 'stinky pasta', '1 hour', 3, 4, 3, $1, $1) ; ` @@ -79,9 +99,9 @@ export default async function populate() { ` const allStatements: Array = [ - populateUsers, populateRecipes, populateCollection, - populateIngredients, populateGroceryList, populateFriendships, - populateComments + populateUsers, populateCuisines, populateCourses, populateRecipes, + populateCollection, populateIngredients, populateGroceryList, + populateFriendships, populateComments ]; await pool.query(setup); diff --git a/server/db/seed.ts b/server/db/seed.ts index 638a9a1..e91b82f 100644 --- a/server/db/seed.ts +++ b/server/db/seed.ts @@ -16,21 +16,23 @@ dotenv.config(); CREATE SCHEMA IF NOT EXISTS recipin; ` - const appusers = fs.readFileSync(appRoot + '/db/sql/create/createappusers.sql').toString(); - const ingredient = fs.readFileSync(appRoot + '/db/sql/create/createingredient.sql').toString(); - const collection = fs.readFileSync(appRoot + '/db/sql/create/createcollection.sql').toString(); - const groceryList = fs.readFileSync(appRoot + '/db/sql/create/creategrocerylist.sql').toString(); - const recipe = fs.readFileSync(appRoot + '/db/sql/create/createrecipe.sql').toString(); - const recipecomments = fs.readFileSync(appRoot + '/db/sql/create/createrecipecomments.sql').toString(); - const recipeingredient = fs.readFileSync(appRoot + '/db/sql/create/createcmp_recipeingredient.sql').toString(); - const recipecollection = fs.readFileSync(appRoot + '/db/sql/create/createcmp_recipecollection.sql').toString(); - const usersubscriptions = fs.readFileSync(appRoot + '/db/sql/create/createcmp_usersubscriptions.sql').toString(); - const userfriendships = fs.readFileSync(appRoot + '/db/sql/create/createcmp_userfriendships.sql').toString(); + const appusers = fs.readFileSync(appRoot + '/db/sql/create/createappusers.sql').toString(); + const ingredient = fs.readFileSync(appRoot + '/db/sql/create/createingredient.sql').toString(); + const collection = fs.readFileSync(appRoot + '/db/sql/create/createcollection.sql').toString(); + const groceryList = fs.readFileSync(appRoot + '/db/sql/create/creategrocerylist.sql').toString(); + const cuisine = fs.readFileSync(appRoot + '/db/sql/create/createcuisine.sql').toString(); + const course = fs.readFileSync(appRoot + '/db/sql/create/createcourse.sql').toString(); + const recipe = fs.readFileSync(appRoot + '/db/sql/create/createrecipe.sql').toString(); + const recipecomments = fs.readFileSync(appRoot + '/db/sql/create/createrecipecomments.sql').toString(); + const recipeingredient = fs.readFileSync(appRoot + '/db/sql/create/createcmp_recipeingredient.sql').toString(); + const recipecollection = fs.readFileSync(appRoot + '/db/sql/create/createcmp_recipecollection.sql').toString(); + const usersubscriptions = fs.readFileSync(appRoot + '/db/sql/create/createcmp_usersubscriptions.sql').toString(); + const userfriendships = fs.readFileSync(appRoot + '/db/sql/create/createcmp_userfriendships.sql').toString(); const allStatements = [ - setRole, appusers, ingredient, collection, recipe, recipecomments, - groceryList, recipeingredient, recipecollection, usersubscriptions, - userfriendships + setRole, appusers, ingredient, collection, cuisine, course, + recipe, recipecomments, groceryList, recipeingredient, + recipecollection, usersubscriptions, userfriendships ] try { diff --git a/server/db/sql/create/createcourse.sql b/server/db/sql/create/createcourse.sql new file mode 100644 index 0000000..362a132 --- /dev/null +++ b/server/db/sql/create/createcourse.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS recipin.course ( + id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + name varchar NOT NULL, + datecreated varchar NOT NULL, + datemodified varchar NOT NULL, + active boolean NOT NULL +); \ No newline at end of file diff --git a/server/db/sql/create/createcuisine.sql b/server/db/sql/create/createcuisine.sql new file mode 100644 index 0000000..aa2ef8e --- /dev/null +++ b/server/db/sql/create/createcuisine.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS recipin.cuisine ( + id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + name varchar NOT NULL, + datecreated varchar NOT NULL, + datemodified varchar NOT NULL, + active boolean NOT NULL +); \ No newline at end of file diff --git a/server/db/sql/create/createrecipe.sql b/server/db/sql/create/createrecipe.sql index 96a1e07..d3642f7 100644 --- a/server/db/sql/create/createrecipe.sql +++ b/server/db/sql/create/createrecipe.sql @@ -5,5 +5,7 @@ CREATE TABLE IF NOT EXISTS recipin.recipe ( datecreated varchar NOT NULL, datemodified varchar NOT NULL, description varchar, - authoruserid int REFERENCES recipin.appusers (id) + authoruserid int REFERENCES recipin.appusers (id), + cuisineid int REFERENCES recipin.cuisine (id), + courseid int REFERENCES recipin.course (id) ); \ No newline at end of file diff --git a/server/models/course.ts b/server/models/course.ts new file mode 100644 index 0000000..e69de29 diff --git a/server/models/cuisine.ts b/server/models/cuisine.ts new file mode 100644 index 0000000..e69de29 diff --git a/server/routes/course.ts b/server/routes/course.ts new file mode 100644 index 0000000..e69de29 diff --git a/server/routes/cuisine.ts b/server/routes/cuisine.ts new file mode 100644 index 0000000..e69de29 diff --git a/server/schemas/index.ts b/server/schemas/index.ts index f1c77de..03fc6f2 100644 --- a/server/schemas/index.ts +++ b/server/schemas/index.ts @@ -31,6 +31,8 @@ export interface IRecipe extends HasHistory, CanDeactivate { name: string preptime: string authoruserid: string | number + cuisineid?: string | number + courseid?: string | number description?: string ingredients?: string[] } @@ -38,6 +40,7 @@ export interface IRecipe extends HasHistory, CanDeactivate { export interface IIngredient extends HasHistory { name: string description?: string + flavorprofile?: string | FlavorProfile['name'] createdbyid: string | number } @@ -56,4 +59,17 @@ export interface IFriendship extends HasHistory, CanDeactivate { senderid: string | number targetid: string | number pending: boolean +} + +export interface ICuisine extends HasHistory, CanDeactivate { + name: string +} + +export interface ICourse extends HasHistory, CanDeactivate { + name: string +} + +export interface FlavorProfile extends HasHistory, CanDeactivate { + name: string + description?: string } \ No newline at end of file