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 }) {
if (size && color) {
pushOptions()
}
recommend()
}, [size, color])
async function recommend(){
try {
const response = await axios.post('/api/order/recommend')
} catch (error) {
catchErrors(error, setError)
}
}
function handleClick(e) {
const box = e.target.parentNode.parentNode
box.style.display = "none"
......
......@@ -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) => {
try {
const user = await User.findById(id)
......@@ -71,4 +49,26 @@ const orderById = async (req, res, next, id) => {
}
}
export default { addorder, showorder, orderById, Ordered }
\ No newline at end of file
const recommendPro = async (req,res)=>{
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')
router.route('/showorder/:userId')
.get(orderCtrl.showorder)
router.route('/recommend')
.post(orderCtrl.recommendPro)
router.param('userId', orderCtrl.orderById)
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