Skip to content

Commit

Permalink
updated get homepage producst route
Browse files Browse the repository at this point in the history
  • Loading branch information
VenketeshRushi committed Oct 29, 2023
1 parent abc8f48 commit 6e3b83c
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions module_product/controllers/ProductController.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,33 @@ exports.getAllProducts = async (req, res, next) => {
exports.getProductsByVerity = async (req, res, next) => {
try {
const products = await prisma.product.findMany({
take: 4,
take: 12,
orderBy: {
id: "desc",
},
});
return res.status(200).json(products);
// console.log("length", products.length);
let updatedProduct = {
a: [],
b: [],
c: [],
};
for (let i = 0; i < products.length; i++) {
const product = products[i];
const productInfo = {
id: product.id,
image: product.img[0],
};

if (i < 4) {
updatedProduct.a.push(productInfo);
} else if (i < 8) {
updatedProduct.b.push(productInfo);
} else {
updatedProduct.c.push(productInfo);
}
}
return res.status(200).json(updatedProduct);
} catch (error) {
next(error);
}
Expand Down

0 comments on commit 6e3b83c

Please sign in to comment.