Skip to content

Commit

Permalink
Fix-getting-wishlist
Browse files Browse the repository at this point in the history
  • Loading branch information
Calebgisa72 committed Jul 4, 2024
1 parent 616c297 commit e3e6937
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/__test__/wishList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ describe('Wish list management tests', () => {
});

describe('Get products in wishList', () => {
it('Returns 404 when buyer has no product in wish list', async () => {
it('Returns No products in wish list when buyer has no product in wish list', async () => {
const token = jwt.sign(data2, jwtSecretKey);
const response = await request(app).get('/wish-list').set('Authorization', `Bearer ${token}`);
expect(response.status).toBe(404);
expect(response.status).toBe(200);
expect(response.body.message).toBe('No products in wish list');
});

Expand Down
12 changes: 3 additions & 9 deletions src/services/wishListServices/getProducts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,16 @@ export const getProductsService = async (req: Request, res: Response) => {
const productsForBuyer = await wishListRepository.find({ where: { buyer: { id: req.user?.id } } });

if (productsForBuyer.length === 0) {
return res.status(404).json({ message: 'No products in wish list', products: productsForBuyer });
return res.status(200).json({ message: 'No products in wish list', products: productsForBuyer });
}

const buyerWishProducts = await Promise.all(
productsForBuyer.map(async product => {
const productDetails = await productRepository.findOne({ where: { id: product.productId } });
const productDetails = await productRepository.findOne({ where: { id: product.productId }, relations: ['vendor', 'categories'] });
if (productDetails) {
return {
wishListDetails: product,
productInfo: {
productId: productDetails.id,
name: productDetails.name,
image: productDetails.images,
newPrice: productDetails.newPrice,
vendorId: productDetails.vendor,
},
productInfo: productDetails,
};
}
})
Expand Down

0 comments on commit e3e6937

Please sign in to comment.