Skip to content

Commit

Permalink
fix: unique elements (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharbansal22 authored Apr 3, 2024
1 parent c143323 commit 333b4b9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions controllers/userOrderControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ exports.getRecommendation = async (req, res, next) => {
const userID = req.params.user_id;
let orders = await Order.find({ user_id: userID })
.sort({ createdAt: -1 })
.limit(5); // Get the last 5 orders
let recommendedItems = [];
.limit(2); // Get the last 5 orders
let recommendedItemsSet = new Set();

// Fetch recommendations for default items
const defaultItems = ["Samosa", "Pav Bhaji"];
Expand All @@ -118,7 +118,7 @@ exports.getRecommendation = async (req, res, next) => {
for (let recipe of recommendedRecipes) {
const dbItem = await MenuItem.findOne({ name: recipe });
if (dbItem) {
recommendedItems.push(dbItem);
recommendedItemsSet.add(JSON.stringify(dbItem));
}
}
} catch (e) {
Expand All @@ -143,13 +143,15 @@ exports.getRecommendation = async (req, res, next) => {
for (let recipe of recommendedRecipes) {
const dbItem = await MenuItem.findOne({ name: recipe });
if (dbItem) {
recommendedItems.push(dbItem);
recommendedItemsSet.add(JSON.stringify(dbItem));
}
}
} catch (e) {
console.log(e);
}
}
const recommendedItems = Array.from(recommendedItemsSet).map(item => JSON.parse(item));


res.json({ recommendedItems });
} catch (error) {
Expand Down

0 comments on commit 333b4b9

Please sign in to comment.