Skip to content

Commit

Permalink
Edit Product Models: split pictures
Browse files Browse the repository at this point in the history
  • Loading branch information
RobyYasirAmri committed Jun 20, 2024
1 parent c26ceb0 commit cf7b6ec
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/controllers/productController.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,21 @@ export const getAllProducts = async (req, res) => {
},
});

const formattedProducts = products.map(product => {
const pictures = product.pictures.split(",");
return {
...product,
pictures: pictures.length > 0 ? pictures[0] : null,
};
});

logger.info("Retrieved all products");

res.status(200).json({
success: "true",
data: products,
message: "Products retrieved successfully",
data: formattedProducts,
// data: products,
});
} catch (error) {
logger.error( `Error retrieving products: ${error.message}`);
Expand Down Expand Up @@ -427,11 +439,19 @@ export const getProductsByTenantId = async (req, res) => {
});
}

const formattedProducts = tenant.products.map(product => {
const pictures = product.pictures.split(",");
return {
...product,
pictures: pictures.length > 0 ? pictures[0] : null,
};
});

logger.info(`Retrieved products for tenant: ID ${tenant_id}`);
res.status(200).json({
success: "true",
message: "Products retrieved successfully",
data: tenant.products,
data: formattedProducts,
});
} catch (error) {
logger.error(`Error retrieving products for tenant: ${error.message}`);
Expand Down

0 comments on commit cf7b6ec

Please sign in to comment.