From debd7183879321a18aed480dff44b6ed6a228fcc Mon Sep 17 00:00:00 2001 From: Jeebon Date: Mon, 14 Feb 2022 14:50:43 +0600 Subject: [PATCH] CNA-003: Bug Fix --- .../app/components/product-item/product-item.component.ts | 2 ++ client/src/app/pages/login/login.component.ts | 2 +- docker-compose.yml | 2 +- server/components/wishlist/WishlistRouter.js | 3 +-- server/components/wishlist/WishlistService.js | 6 +++++- server/config/default.js | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/client/src/app/components/product-item/product-item.component.ts b/client/src/app/components/product-item/product-item.component.ts index 93bdad7..64e9f3d 100644 --- a/client/src/app/components/product-item/product-item.component.ts +++ b/client/src/app/components/product-item/product-item.component.ts @@ -29,6 +29,7 @@ export class ProductItemComponent implements OnInit { addToWishlist(id: string) { if (this.currentUser) { this.productService.addWishlist(id).subscribe((res) => { + this.item.wishlist = true; alert(res?.message || 'Added'); }, (err) => { alert(err?.message || 'Unable to process'); @@ -41,6 +42,7 @@ export class ProductItemComponent implements OnInit { removeFromWishlist(id: string) { if (this.currentUser) { this.productService.removeFromWishlist(id).subscribe((res) => { + this.item.wishlist = false; alert(res?.message || 'Removed'); }, (err) => { alert(err?.message || 'Unable to process'); diff --git a/client/src/app/pages/login/login.component.ts b/client/src/app/pages/login/login.component.ts index 10c2769..58b9c69 100644 --- a/client/src/app/pages/login/login.component.ts +++ b/client/src/app/pages/login/login.component.ts @@ -50,7 +50,7 @@ export class LoginComponent implements OnInit { } }, (err) => { console.log('err', err); - this.msg = err.body?.message || 'Unable to process request!'; + this.msg = err || 'Unable to process request!'; }); } diff --git a/docker-compose.yml b/docker-compose.yml index fa59a05..6024e94 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,7 +25,7 @@ services: MONGODB_SERVER_STATIC: localhost MONGODB_URI: mongodb//mongo_db:27017, JWT_SECRET: skfjslkjksdfjw3434j32l4 - JWT_EXPIRES_IN: 3600000 + JWT_EXPIRES_IN: 365d ports: - "5000:5000" volumes: diff --git a/server/components/wishlist/WishlistRouter.js b/server/components/wishlist/WishlistRouter.js index ad9c8a4..9c83a1e 100644 --- a/server/components/wishlist/WishlistRouter.js +++ b/server/components/wishlist/WishlistRouter.js @@ -62,9 +62,8 @@ router.delete('/:id', async (req, res, next) => { if (!req.authenticatedUser) { return next(new AuthenticationException('Unauthorized')); } - try { - await WishlistService.deleteHoax(req.params.hoaxId, req.authenticatedUser.id); + await WishlistService.deleteItem(req.params.id, req.authenticatedUser); res.send(); } catch (err) { return next(err); diff --git a/server/components/wishlist/WishlistService.js b/server/components/wishlist/WishlistService.js index d07a4c5..b58a387 100644 --- a/server/components/wishlist/WishlistService.js +++ b/server/components/wishlist/WishlistService.js @@ -75,11 +75,15 @@ const getItemsWithProducts = async (page, size, authenticatedUser) => { }; }; +const deleteItem = async (productId, authenticatedUser) => { + return await Wishlist.findOne({ user: ObjectId(authenticatedUser._id), product: ObjectId(productId) }).remove().exec(); +}; module.exports = { save, findByUserIdAndProductId, getItem, getItems, - getItemsWithProducts + getItemsWithProducts, + deleteItem }; diff --git a/server/config/default.js b/server/config/default.js index c81c27a..f5578cc 100644 --- a/server/config/default.js +++ b/server/config/default.js @@ -7,6 +7,7 @@ module.exports = { }, JWT: { JWT_SECRET: process.env.JWT_SECRET || 'thetokenwillbereplaced', - JWT_EXPIRES_IN: process.env.JWT_EXPIRES_IN || 3600000 + //JWT_EXPIRES_IN: process.env.JWT_EXPIRES_IN || '365d' + JWT_EXPIRES_IN: '365d' } };