I need some help. I am building an Api for recipes according to the ingredient, calorie and meal which I get from the user. so according to given ingredient I have to fetch recipes from the database which include required ingredient. I have two collection first collection of recipes which have document of recipes and these recipes document have a field ingredient from which I am searching ingredient. but here problem arise that I have a Calories and meal queries also. I can explain this with an example so let say I get queries from user like
localhost:5000/getcalorie/salmon,Fish,Turkey,Pork,ham?calorie=1400&meal=3
so here salmon fish are ingredient. but here I have to divide calorie into 3 meals like 20% 40% and 40% and fetch those recipes which have calorie less than 20% calorie, 40% and 40%
and also no recipes should repeat in any meal like if roasted salmon is in breakfast then it should not be in lunch or dinner. but they have different recipes or salmon like salmon patties in lunch and for dinner it something other.
So how can I do this
I will show you how I am doing
async function meals(array,meals){
let selectedfood = await Recipe.find({$and:[{ingredients:{$in:array}},{calorie:{$lte:meals}}]})
let selectedfood1 = await Nutrition.find({$and:[{name:{$in:array}},{calorie:{$lte:meals}}]})
let commonselectedfoodarray = selectedfood.concat(selectedfood1)
return commonselectedfoodarray
}
from above code I am fetching recipes from database but here I am just including required ingredient from URL and meals(meals change according to meal like for breakfast it is (20/100)*calorie same for lunch and dinner)
but this above code fetch me recipes which have required ingredient and calories less than a meal
but my problem is how can I handle not repetition of recipes in different meals