Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.post('/recipes-by-ingredients', async (req, res) => {
- const { name, description, ingredients } = req.body
- const recipeQuery = `
- INSERT INTO recipes (name, description)
- VALUES ('${name}', '${description}')
- `;
- try {
- const recipe = await executeQuery(recipeQuery);
- const ingredientsQuery = `
- INSERT INTO recipes_to_ingredients (recipe_id, ingredient_id)
- VALUES
- (${recipe.insertId}, 20),
- (${recipe.insertId}, 21),
- (${recipe.insertId}, 22),
- (${recipe.insertId}, 23),
- (${recipe.insertId}, 24)
- `;
- try {
- res.json(await executeQuery(ingredientsQuery));
- } catch(e) {
- res.status(500).send(e.message);
- }
- } catch(e) {
- res.status(500).send(e.message);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement