From 26220dbb8b4bd251cc4b3e92190eb69670b4d4a1 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Wed, 17 Dec 2025 11:59:10 +0330 Subject: [PATCH] cache --- src/modules/cart/providers/cart.service.ts | 13 ++++++++----- src/modules/utils/cache.service.ts | 7 ++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/modules/cart/providers/cart.service.ts b/src/modules/cart/providers/cart.service.ts index 52001cc..8d6abb0 100644 --- a/src/modules/cart/providers/cart.service.ts +++ b/src/modules/cart/providers/cart.service.ts @@ -21,6 +21,7 @@ import { CouponService } from 'src/modules/coupons/providers/coupon.service'; import { OrderCouponDetail } from 'src/modules/orders/interface/order-status'; import { CouponType } from 'src/modules/coupons/interface/coupon'; import { UserWallet } from 'src/modules/users/entities/user-wallet.entity'; +import { PaymentMethodEnum } from 'src/modules/payments/interface/payment'; @Injectable() export class CartService { @@ -221,8 +222,10 @@ export class CartService { ): Promise { const cart = await this.findOneOrFail(userId, restaurantId); - await this.getEnabledPaymentMethodOrFail(restaurantId, setPaymentMethodDto.paymentMethodId); - await this.assertWalletHasEnoughBalance(userId, restaurantId,cart.total); + const paymentMethod = await this.getEnabledPaymentMethodOrFail(restaurantId, setPaymentMethodDto.paymentMethodId); + if (paymentMethod.method === PaymentMethodEnum.Wallet) { + await this.assertWalletHasEnoughBalance(userId, restaurantId, cart.total); + } cart.paymentMethodId = setPaymentMethodDto.paymentMethodId; return this.recalculateAndSaveCart(cart); } @@ -236,16 +239,16 @@ export class CartService { user: { id: userId }, restaurant: { id: restaurantId }, }); - + console.log('wallet', wallet); if (!wallet) { throw new BadRequestException('User wallet not found'); } - + if (wallet.wallet < amount) { throw new BadRequestException('User wallet is not enough'); } } - + /** * Set delivery method for cart */ diff --git a/src/modules/utils/cache.service.ts b/src/modules/utils/cache.service.ts index fc9be4f..ee79e2c 100755 --- a/src/modules/utils/cache.service.ts +++ b/src/modules/utils/cache.service.ts @@ -8,8 +8,9 @@ export class CacheService implements OnModuleInit { this.logger.log('Pinging Redis to check connection...'); try { // 3. Try to set and get a test key - await this.cacheManager.set('ping', 'pong', 10); // 10-second TTL - const result = await this.cacheManager.get('ping'); + // Use the wrapper to keep TTL units consistent (seconds -> ms) + await this.set('ping', 'pong', 10); // 10-second TTL + const result = await this.get('ping'); if (result === 'pong') { this.logger.log('✅ Redis connection successful (set/get test passed).'); @@ -24,7 +25,7 @@ export class CacheService implements OnModuleInit { } } - constructor(@Inject(CACHE_MANAGER) private cacheManager: Cache) {} + constructor(@Inject(CACHE_MANAGER) private cacheManager: Cache) { } async get(key: string) { return await this.cacheManager.get(key);