|
|
|
@ -3,26 +3,30 @@ import { Recipe } from "../types/recipes"
|
|
|
|
|
import { Connection } from "../database/connection"
|
|
|
|
|
import { Router } from "express";
|
|
|
|
|
import { StepsGateway } from "./steps.gateway";
|
|
|
|
|
import { IngredientsGateway } from "./ingredients.gateway";
|
|
|
|
|
|
|
|
|
|
export class RecipeGateway {
|
|
|
|
|
connection:Connection
|
|
|
|
|
steps_gw:StepsGateway
|
|
|
|
|
ingredient_gw:IngredientsGateway
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
this.connection = new Connection()
|
|
|
|
|
this.steps_gw = new StepsGateway()
|
|
|
|
|
this.ingredient_gw = new IngredientsGateway()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getAll() : Promise<Recipe[]> {
|
|
|
|
|
this.connection.connect()
|
|
|
|
|
const steps_gw = new StepsGateway()
|
|
|
|
|
|
|
|
|
|
const res = await this.connection.client.query('SELECT * FROM Recipes ORDER BY id');
|
|
|
|
|
|
|
|
|
|
const steps: string[] = [];
|
|
|
|
|
let recipes:Recipe[] = []
|
|
|
|
|
|
|
|
|
|
for (let key in res.rows) {
|
|
|
|
|
const steps = await steps_gw.getForRecipes(Number(key));
|
|
|
|
|
let recipe:Recipe = new Recipe(Number(res.rows[key].id), res.rows[key].name, res.rows[key].description, res.rows[key].time, steps);
|
|
|
|
|
const steps = await this.steps_gw.getForRecipes(Number(key));
|
|
|
|
|
const ingredients = await this.ingredient_gw.findIngredientsForRecipe(Number(key))
|
|
|
|
|
let recipe:Recipe = new Recipe(Number(res.rows[key].id), res.rows[key].name, res.rows[key].description, res.rows[key].time, steps, ingredients);
|
|
|
|
|
recipes.push(recipe);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -33,7 +37,6 @@ export class RecipeGateway {
|
|
|
|
|
|
|
|
|
|
async getById(id: Number) : Promise<Recipe | null>{
|
|
|
|
|
this.connection.connect()
|
|
|
|
|
const steps_gw = new StepsGateway()
|
|
|
|
|
|
|
|
|
|
const query = {
|
|
|
|
|
text: 'SELECT * FROM Recipes WHERE id =$1',
|
|
|
|
@ -46,11 +49,15 @@ export class RecipeGateway {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const steps = await steps_gw.getForRecipes(id)
|
|
|
|
|
console.log(steps);
|
|
|
|
|
const recipe = new Recipe(Number(res.rows[0].id), res.rows[0].name, res.rows[0].description, res.rows[0].time, steps);
|
|
|
|
|
console.log(recipe);
|
|
|
|
|
|
|
|
|
|
const steps = await this.steps_gw.getForRecipes(id)
|
|
|
|
|
const ingredients = await this.ingredient_gw.findIngredientsForRecipe(id)
|
|
|
|
|
const recipe = new Recipe(Number(res.rows[0].id),
|
|
|
|
|
res.rows[0].name,
|
|
|
|
|
res.rows[0].description,
|
|
|
|
|
Number(res.rows[0].time),
|
|
|
|
|
steps, ingredients);
|
|
|
|
|
console.log(ingredients);
|
|
|
|
|
|
|
|
|
|
return recipe;
|
|
|
|
|
}
|
|
|
|
|
}
|