Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
shopping-mall
Commits
8d8a98af
Commit
8d8a98af
authored
Jan 29, 2021
by
Jiwon Yoon
Browse files
asd
parent
dcc19277
Changes
1
Show whitespace changes
Inline
Side-by-side
server/controllers/order.controller.js
View file @
8d8a98af
...
@@ -71,28 +71,32 @@ const recommendPro = async (req, res) => {
...
@@ -71,28 +71,32 @@ const recommendPro = async (req, res) => {
_id
:
"
$products.productId
"
,
_id
:
"
$products.productId
"
,
count
:
{
$sum
:
1
}
count
:
{
$sum
:
1
}
}
}
},
{
$sort
:
{
count
:
-
1
}
},
{
$limit
:
5
},
{
$lookup
:
{
from
:
"
products
"
,
localField
:
"
_id
"
,
foreignField
:
"
_id
"
,
as
:
"
product
"
}
}
}
])
])
console
.
log
(
'
recommend=
'
,
recommend
)
console
.
log
(
'
recommend=
'
,
recommend
)
const
filteredRecommend
=
recommend
.
filter
((
el
)
=>
String
(
el
.
_id
)
!==
String
(
productId
))
const
filteredRecommend
=
recommend
.
filter
((
el
)
=>
String
(
el
.
_id
)
!==
String
(
productId
))
console
.
log
(
'
filtering=
'
,
filteredRecommend
)
console
.
log
(
'
filtering=
'
,
filteredRecommend
)
filteredRecommend
.
sort
(
function
(
a
,
b
)
{
// const array = filteredRecommend.map(async (el) => {
if
(
a
.
count
>
b
.
count
)
{
// const aa = await Product.findById(el._id)
return
-
1
;
// return aa
}
// })
if
(
a
.
count
<
b
.
count
)
{
// const bb = await Promise.all(array)
return
1
;
res
.
json
(
filteredRecommend
)
}
// a must be equal to b
return
0
;
});
const
finalrecommend
=
filteredRecommend
.
slice
(
0
,
4
)
const
array
=
finalrecommend
.
map
(
async
(
el
)
=>
{
const
aa
=
await
Product
.
findById
(
el
.
_id
)
return
aa
})
const
bb
=
await
Promise
.
all
(
array
)
res
.
json
(
bb
)
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
'
error in order
'
,
error
)
console
.
log
(
'
error in order
'
,
error
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment