Skip to content

Commit

Permalink
addmin can see order histoy of users and access their status
Browse files Browse the repository at this point in the history
  • Loading branch information
byohannes committed Nov 5, 2020
1 parent c59b591 commit 0e25ca7
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,47 @@ exports.update = (req, res) => {
});
});
};

exports.addOrderToUserHistory = (req, res, next) => {
let history = [];

req.body.order.products.forEach((item) => {
history.push({
_id: item._id,
name: item.name,
description: item.description,
category: item.category,
quantity: item.count,
transaction_id: req.body.order.transaction_id,
amount: req.body.order.amount,
});
});

User.findOneAndUpdate(
{ _id: req.profile._id },
{ $push: { history: history } },
{ new: true },
(error, data) => {
if (error) {
return res.status(400).json({
error: "Could not update user purchase history",
});
}
next();
}
);
};

exports.purchaseHistory = (req, res) => {
Order.find({ user: req.profile._id })
.populate("user", "_id name")
.sort("-created")
.exec((err, orders) => {
if (err) {
return res.status(400).json({
error: errorHandler(err),
});
}
res.json(orders);
});
};

0 comments on commit 0e25ca7

Please sign in to comment.