Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. app.post('/recipes-by-ingredients', async (req, res) => {
  2.     const { name, description, ingredients } = req.body
  3.  
  4.     const recipeQuery = `
  5.         INSERT INTO recipes (name, description)
  6.         VALUES ('${name}', '${description}')
  7.     `;
  8.    
  9.     try {
  10.         const recipe = await executeQuery(recipeQuery);
  11.        
  12.         const ingredientsQuery = `
  13.             INSERT INTO recipes_to_ingredients (recipe_id, ingredient_id)
  14.             VALUES
  15.                 (${recipe.insertId}, 20),
  16.                 (${recipe.insertId}, 21),
  17.                 (${recipe.insertId}, 22),
  18.                 (${recipe.insertId}, 23),
  19.                 (${recipe.insertId}, 24)
  20.         `;
  21.  
  22.     try {
  23.             res.json(await executeQuery(ingredientsQuery));
  24.     } catch(e) {
  25.       res.status(500).send(e.message);
  26.     }
  27.   } catch(e) {
  28.     res.status(500).send(e.message);
  29.   }
  30. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement