Ð
Size: a a a
Ð
Ð
AZ
ДП
Ð
AZ
ДП
AZ
Ð
Ð
oT
UnhandledPromiseRejectionWarning: TypeError: Cannot set property 'count' of undefined
Ð
oT
class Card {
static async add(product) {
const card = await Card.fetch();
const ind = card.products.findIndex(c => c.id === product.id);
const candidate = card.products[ind]
if (candidate) {
candidate.count++;
card.products[ind] = candidate;
} else {
product.count = 1
card.products.push(product);
}
card.price += +product.price;
return new Promise((resolve, reject) => {
fs.writeFile(p, JSON.stringify(card), err => {
if(err) {
reject(err);
} else {
console.log(resolve())
resolve();
}
})
})
}
Ð
ДП
Ð
Ð
Ð
АК