From 1d920cfa7dbe0782f14e58505c57df91e6499e25 Mon Sep 17 00:00:00 2001 From: Berlem Date: Thu, 25 Apr 2024 20:26:21 +0200 Subject: [PATCH] refactor functionality #407 --- staff/belen-ivars/project/api/handlers/index.js | 6 ++++-- .../project/api/handlers/retrieveRecipesHandler.js | 1 - staff/belen-ivars/project/api/logic/checkIngredient.js | 8 ++++---- .../belen-ivars/project/api/logic/checkIngredient.test.js | 3 +-- staff/belen-ivars/project/api/logic/index.js | 4 +++- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/staff/belen-ivars/project/api/handlers/index.js b/staff/belen-ivars/project/api/handlers/index.js index 5cb945b40..4d6a43e30 100644 --- a/staff/belen-ivars/project/api/handlers/index.js +++ b/staff/belen-ivars/project/api/handlers/index.js @@ -4,11 +4,12 @@ import retrieveUserHandler from './retrieveUserHandler.js' import createRecipeHandler from './createRecipeHandler.js' import retrieveRecipesHandler from './retrieveRecipesHandler.js' import deleteRecipeHandler from './deleteRecipeHandler.js' -import editRecipeHandler from './editeRecipeHandler.js' +import editRecipeHandler from './editRecipeHandler.js' import toggleFavRecipeHandler from './toggleFavRecipeHandler.js' import retrieveFavRecipesHandler from './retrieveFavRecipesHandler.js' import searchRecipesHandler from './searchRecipesHandler.js' import getIngredientsListHandler from './getIngredientsListHandler.js' +import retrieveCompleteRecipeHandler from './retrieveCompleteRecipeHandler.js' export { @@ -22,5 +23,6 @@ export { toggleFavRecipeHandler, retrieveFavRecipesHandler, searchRecipesHandler, - getIngredientsListHandler + getIngredientsListHandler, + retrieveCompleteRecipeHandler } \ No newline at end of file diff --git a/staff/belen-ivars/project/api/handlers/retrieveRecipesHandler.js b/staff/belen-ivars/project/api/handlers/retrieveRecipesHandler.js index e1fb50d34..1182c1d31 100644 --- a/staff/belen-ivars/project/api/handlers/retrieveRecipesHandler.js +++ b/staff/belen-ivars/project/api/handlers/retrieveRecipesHandler.js @@ -9,7 +9,6 @@ const retrieveRecipesHandler = async (req, res) => { const payload = jwt.verify(token, process.env.JWT_SECRET) const { sub: userId } = payload - console.log(userId) try { validate.id(userId, 'id') diff --git a/staff/belen-ivars/project/api/logic/checkIngredient.js b/staff/belen-ivars/project/api/logic/checkIngredient.js index 92a605654..ae1f0b501 100644 --- a/staff/belen-ivars/project/api/logic/checkIngredient.js +++ b/staff/belen-ivars/project/api/logic/checkIngredient.js @@ -17,12 +17,12 @@ async function checkIngredient(userId, ingredient) { const ingredientName = ingredient.toLowerCase() - let isAnIngredient + let existingIngredient try { - isAnIngredient = await Ingredient.findOne({ name: ingredientName }) - if (isAnIngredient) { - return isAnIngredient + existingIngredient = await Ingredient.findOne({ name: ingredientName }) + if (existingIngredient) { + return existingIngredient } } catch (error) { throw new SystemError(error.message) diff --git a/staff/belen-ivars/project/api/logic/checkIngredient.test.js b/staff/belen-ivars/project/api/logic/checkIngredient.test.js index c79eca964..eb8fa9e5c 100644 --- a/staff/belen-ivars/project/api/logic/checkIngredient.test.js +++ b/staff/belen-ivars/project/api/logic/checkIngredient.test.js @@ -2,12 +2,11 @@ import dotenv from 'dotenv' dotenv.config() import mongoose, { mongo } from 'mongoose' import checkIngredient from './checkIngredient.js' -import { Ingredient } from '../data/models.js' (async () => { await mongoose.connect(process.env.MONGODB_URL) try { - await checkIngredient('65d655fac1dd88f9aee917d6', 'sal') + await checkIngredient('65d655fac1dd88f9aee917d6', 'salmó') } catch (error) { console.log(error) diff --git a/staff/belen-ivars/project/api/logic/index.js b/staff/belen-ivars/project/api/logic/index.js index eaf1d606f..bb13dadbc 100644 --- a/staff/belen-ivars/project/api/logic/index.js +++ b/staff/belen-ivars/project/api/logic/index.js @@ -10,6 +10,7 @@ import retrieveFavRecipes from './retrieveFavRecipes.js' import checkIngredient from './checkIngredient.js' import findRecipes from './findRecipes.js' import getIngredientsList from './getIngredientsList.js' +import retrieveCompleteRecipe from './retrieveCompleteRecipe.js' const logic = { registerUser, @@ -23,7 +24,8 @@ const logic = { retrieveFavRecipes, checkIngredient, findRecipes, - getIngredientsList + getIngredientsList, + retrieveCompleteRecipe } export default logic \ No newline at end of file