Skip to content

Commit

Permalink
Remove __content
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Oct 7, 2024
1 parent b37fcd9 commit bf7caa4
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 0 deletions.
Binary file removed __content/backend-1.png
Binary file not shown.
Binary file removed __content/backend-2.png
Binary file not shown.
Binary file removed __content/backend-3.png
Binary file not shown.
Binary file removed __content/backend-4.png
Binary file not shown.
Binary file removed __content/backend-5.png
Binary file not shown.
Binary file removed __content/backend-6.png
Binary file not shown.
Binary file removed __content/backend-7.png
Binary file not shown.
Binary file removed __content/frontend-1.png
Binary file not shown.
Binary file removed __content/frontend-2.png
Binary file not shown.
Binary file removed __content/frontend-3.png
Binary file not shown.
Binary file removed __content/frontend-4.png
Binary file not shown.
Binary file removed __content/frontend-5.png
Binary file not shown.
Binary file removed __content/frontend-6.png
Binary file not shown.
Binary file removed __content/frontend-7-bis.png
Binary file not shown.
Binary file removed __content/frontend-8-bis.png
Binary file not shown.
Binary file removed __content/logo.png
Binary file not shown.
64 changes: 64 additions & 0 deletions api/src/controllers/productController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,67 @@ export const getFrontendProducts = async (req: Request, res: Response) => {
return res.status(400).send(i18n.t('DB_ERROR') + err)
}
}

/**
* Get frontend products.
*
* @async
* @param {Request} req
* @param {Response} res
* @returns {unknown}
*/
export const getFeaturedProducts = async (req: Request, res: Response) => {
try {
const { cart: cartId, size } = req.body

let cartProducts: mongoose.Types.ObjectId[] = []
if (cartId) {
const _cart = await Cart
.findById(cartId)
.populate<{ cartItems: env.CartItem[] }>('cartItems')
.lean()

if (_cart) {
cartProducts = _cart.cartItems.map((cartItem) => cartItem.product)
}
}

// TODO after: sort by price asc, desc
const products = await Product.aggregate([
{
$match: { featured: true },
},
{
$addFields: {
inCart: {
$cond: [{ $in: ['$_id', cartProducts] }, 1, 0],
},
},
},
{
$project: {
categories: 0,
description: 0,
},
},
{
$facet: {
resultData: [
{ $sort: { createdAt: -1 } },
{ $limit: size },
],
pageInfo: [
{
$count: 'totalRecords',
},
],
},
},
], { collation: { locale: env.DEFAULT_LANGUAGE, strength: 2 } })

return res.json(products)
} catch (err) {
logger.error(i18n.t('DB_ERROR'), err)
return res.status(400).send(i18n.t('DB_ERROR') + err)
}
}

0 comments on commit bf7caa4

Please sign in to comment.