Answer the question
In order to leave comments, you need to log in
Counting identical elements in mongodb array. How to count all the items to display the cart?
function corfList(userId,chatId){
User.findOne({telegramId: userId})
.then(user => {
let html
let amountPr
let amount
if(user){
amountPr = {}
user.corf_list.forEach(a =>{
amountPr[a] = amountPr[a] + 1 || 1;
})
Products.find({db: user.corf_list}).then(product => {
if(product.length){
html = product.map((p, i) => {
for (res in amountPr)
amount = 'x' + amountPr[res]
return `<b>${i + 1}</b> ${p.name} ` + amount +res
}).join('\n')
}
const inCorf = 'В корзине:\n'
sendHTML(chatId, inCorf + html, 'ord_corf')
})
} else {
sendHTML(chatId, `В корзине пока пусто..`, 'home')
}
})
}
{ chk: 4, fre: 1, grk: 1, big: 3 }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question