Skip to content

Commit

Permalink
refactor functionality b00tc4mp#407
Browse files Browse the repository at this point in the history
  • Loading branch information
berlem committed Apr 25, 2024
1 parent 8288b03 commit 1d920cf
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions staff/belen-ivars/project/api/handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -22,5 +23,6 @@ export {
toggleFavRecipeHandler,
retrieveFavRecipesHandler,
searchRecipesHandler,
getIngredientsListHandler
getIngredientsListHandler,
retrieveCompleteRecipeHandler
}
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
8 changes: 4 additions & 4 deletions staff/belen-ivars/project/api/logic/checkIngredient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions staff/belen-ivars/project/api/logic/checkIngredient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion staff/belen-ivars/project/api/logic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -23,7 +24,8 @@ const logic = {
retrieveFavRecipes,
checkIngredient,
findRecipes,
getIngredientsList
getIngredientsList,
retrieveCompleteRecipe
}

export default logic

0 comments on commit 1d920cf

Please sign in to comment.