Commit 48427c96 authored by kusang96's avatar kusang96
Browse files

Merge remote-tracking branch 'origin/jiwon' into ourMaster

parents 7af971e6 e28dfcd6
...@@ -49,7 +49,7 @@ function Home() { ...@@ -49,7 +49,7 @@ function Home() {
`} `}
</style> </style>
<div className="my-4"> <div className="my-4">
<h2 style={{ marginRight: "5rem", marginLeft: "3rem", marginBottom: "2rem" }}><u>Best</u></h2> <h2 style={{ marginRight: "5rem", marginLeft: "3rem", marginBottom: "2rem" }}>Best</h2>
<Row className="justify-content-center mx-0"> <Row className="justify-content-center mx-0">
{productlist.bestProduct.map(pro => ( {productlist.bestProduct.map(pro => (
<Link to={{ <Link to={{
...@@ -71,7 +71,7 @@ function Home() { ...@@ -71,7 +71,7 @@ function Home() {
</Row> </Row>
</div> </div>
<div className="my-4"> <div className="my-4">
<h2 style={{ marginRight: "5rem", marginLeft: "3rem", marginBottom: "2rem", marginTop: "2rem" }}><u>New Arrival</u></h2> <h2 style={{ marginRight: "5rem", marginLeft: "3rem", marginBottom: "2rem", marginTop: "2rem" }}>New Arrival</h2>
<Row className="justify-content-center mx-0"> <Row className="justify-content-center mx-0">
{productlist.newProduct.map(pro => ( {productlist.newProduct.map(pro => (
<Link to={{ <Link to={{
......
...@@ -35,12 +35,12 @@ function Product({ match, location }) { ...@@ -35,12 +35,12 @@ function Product({ match, location }) {
} }
}, [size, color]) }, [size, color])
async function getRecommend(){ async function getRecommend() {
try { try {
const response = await axios.get(`/api/order/recommend?products=${product.id}`) const response = await axios.get(`/api/order/recommend?products=${product.id}`)
setProductList(response.data) setProductList(response.data)
} catch (error) { } catch (error) {
catchErrors(error,setError) catchErrors(error, setError)
} }
} }
...@@ -264,7 +264,9 @@ function Product({ match, location }) { ...@@ -264,7 +264,9 @@ function Product({ match, location }) {
</Card> </Card>
<Col className='p-5'> <Col className='p-5'>
<div className='border p-2' style={{ maxWidth: "100%", height: 'auto', margin: 'auto', fontSize: '3.5vmin' }}>[ Detail Images ]</div> <div className='border p-2' style={{ maxWidth: "100%", height: 'auto', margin: 'auto', fontSize: '3.5vmin' }}>[ Detail Images ]</div>
<Image src={`/images/${product.detail_imgs}`} style={{ objectFit: "contain", maxWidth: "100%", height: 'auto', margin: 'auto' }} className='p-4 d-flex justify-content-center' /> {product.detail_imgs.map((el) => (
<Image src={`/images/${el}`} style={{ objectFit: "contain", maxWidth: "100%", height: 'auto', margin: 'auto' }} className='p-4 d-flex justify-content-center' />
))}
</Col> </Col>
</Col> </Col>
</Col> </Col>
...@@ -280,16 +282,16 @@ function Product({ match, location }) { ...@@ -280,16 +282,16 @@ function Product({ match, location }) {
pathname: `/product/${pro._id}`, pathname: `/product/${pro._id}`,
state: { state: {
id: pro._id, id: pro._id,
name: pro.pro_name, name: pro.product[0].pro_name,
price: pro.price, price: pro.product[0].price,
colors: pro.colors, colors: pro.product[0].colors,
sizes: pro.sizes, sizes: pro.product[0].sizes,
description: pro.description, description: pro.product[0].description,
main_img: pro.main_imgUrl, main_img: pro.product[0].main_imgUrl,
detail_imgs: pro.detail_imgUrls detail_imgs: pro.product[0].detail_imgUrls
} }
}}> }}>
<ListCard id={pro._id} name={pro.pro_name} price={pro.price} main_img={pro.main_imgUrl} status={'recommend'} /> <ListCard id={pro._id} name={pro.product[0].pro_name} price={pro.product[0].price} main_img={pro.product[0].main_imgUrl} status={'recommend'} />
</Link> </Link>
))} ))}
</Row> </Row>
......
...@@ -66,29 +66,23 @@ const recommendPro = async (req, res) => { ...@@ -66,29 +66,23 @@ 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) { res.json(filteredRecommend)
if (a.count > b.count) {
return -1;
}
if (a.count < b.count) {
return 1;
}
// a must be equal to b
return 0;
});
console.log('sort=',filteredRecommend)
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)
} }
......
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