in progress: associate ingredients to recipe on save

This commit is contained in:
Mikayla Dobson
2023-02-19 12:04:46 -06:00
parent 47360518ce
commit 63d0049450
8 changed files with 116 additions and 15 deletions

View File

@@ -57,10 +57,16 @@ export const recipeRoute = (app: Express) => {
router.post('/', restrictAccess, async (req, res, next) => {
const user = req.user as IUser;
const data = req.body;
const { addIngredients, recipeID } = req.query;
try {
const result = await recipectl.post(user.id as number, data);
res.status(result.code).send(result.data);
if (addIngredients) {
const result = await recipectl.addIngredientToRecipe(data, recipeID as string);
res.status(result.code).send(result.data);
} else {
const result = await recipectl.post(user.id as number, data);
res.status(result.code).send(result.data);
}
} catch(e) {
next(e);
}