updates to db seed, ts definitions
This commit is contained in:
3
server/controllers/CollectionCtl.ts
Normal file
3
server/controllers/CollectionCtl.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export default class CollectionCtl {
|
||||
|
||||
}
|
||||
0
server/db/examplevals.ts
Normal file
0
server/db/examplevals.ts
Normal file
@@ -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 });
|
||||
|
||||
37
server/models/collection.ts
Normal file
37
server/models/collection.ts
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user