Commit 5151510f authored by kusang96's avatar kusang96
Browse files

Merge remote-tracking branch 'origin/jaeyeon' into kimpen

parents be29f536 edcdd9e2
...@@ -23,8 +23,17 @@ function Product({ match, location }) { ...@@ -23,8 +23,17 @@ function Product({ match, location }) {
if (size && color) { if (size && color) {
pushOptions() pushOptions()
} }
recommend()
}, [size, color]) }, [size, color])
async function recommend(){
try {
const response = await axios.post('/api/order/recommend')
} catch (error) {
catchErrors(error, setError)
}
}
function handleClick(e) { function handleClick(e) {
const box = e.target.parentNode.parentNode const box = e.target.parentNode.parentNode
box.style.display = "none" box.style.display = "none"
......
...@@ -35,28 +35,6 @@ const showorder = async (req, res) => { ...@@ -35,28 +35,6 @@ const showorder = async (req, res) => {
} }
} }
const recommendPro = async (req, res) => {
const { productId } = req.body
console.log(productId)
try {
const findedorder = await Order.find({ 'products.productId': productId })
console.log('findedouder=', findedorder)
const recommend = await
const recommend = await Order.aggregate([
// { $project: {}},
{$match: {"products":{"productId": productId}}},
{$group: {
_id: "$products.productId",
num_tutorial: { $sum: 1 }
}
}
])
console.log('recommend=', recommend)
} catch (error) {
}
}
const orderById = async (req, res, next, id) => { const orderById = async (req, res, next, id) => {
try { try {
const user = await User.findById(id) const user = await User.findById(id)
...@@ -71,4 +49,26 @@ const orderById = async (req, res, next, id) => { ...@@ -71,4 +49,26 @@ const orderById = async (req, res, next, id) => {
} }
} }
export default { addorder, showorder, orderById, Ordered } const recommendPro = async (req,res)=>{
\ No newline at end of file try {
const recommend = await Order.aggregate([
{ "$unwind": "$products" },
// {
// $match:{'products.productId':'600e2fcc8afbb038487cc8fa'}
// },
{
$group:
{
_id:'$products.productId',
num_total:{$sum:1}
}
}
])
console.log(recommend)
} catch (error) {
console.log(error)
res.status(500).send('추천 실패')
}
}
export default { addorder, showorder, orderById , Ordered , recommendPro}
\ No newline at end of file
...@@ -9,6 +9,9 @@ router.route('/addorder') ...@@ -9,6 +9,9 @@ router.route('/addorder')
router.route('/showorder/:userId') router.route('/showorder/:userId')
.get(orderCtrl.showorder) .get(orderCtrl.showorder)
router.route('/recommend')
.post(orderCtrl.recommendPro)
router.param('userId', orderCtrl.orderById) router.param('userId', orderCtrl.orderById)
export default router export default router
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment