update
This commit is contained in:
@@ -20,6 +20,7 @@ import { Cart, CartItem } from '../interfaces/cart.interface';
|
|||||||
import { CouponService } from 'src/modules/coupons/providers/coupon.service';
|
import { CouponService } from 'src/modules/coupons/providers/coupon.service';
|
||||||
import { OrderCouponDetail } from 'src/modules/orders/interface/order-status';
|
import { OrderCouponDetail } from 'src/modules/orders/interface/order-status';
|
||||||
import { CouponType } from 'src/modules/coupons/interface/coupon';
|
import { CouponType } from 'src/modules/coupons/interface/coupon';
|
||||||
|
import { UserWallet } from 'src/modules/users/entities/user-wallet.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CartService {
|
export class CartService {
|
||||||
@@ -221,11 +222,30 @@ export class CartService {
|
|||||||
const cart = await this.findOneOrFail(userId, restaurantId);
|
const cart = await this.findOneOrFail(userId, restaurantId);
|
||||||
|
|
||||||
await this.getEnabledPaymentMethodOrFail(restaurantId, setPaymentMethodDto.paymentMethodId);
|
await this.getEnabledPaymentMethodOrFail(restaurantId, setPaymentMethodDto.paymentMethodId);
|
||||||
|
await this.assertWalletHasEnoughBalance(userId, restaurantId,cart.total);
|
||||||
cart.paymentMethodId = setPaymentMethodDto.paymentMethodId;
|
cart.paymentMethodId = setPaymentMethodDto.paymentMethodId;
|
||||||
return this.recalculateAndSaveCart(cart);
|
return this.recalculateAndSaveCart(cart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async assertWalletHasEnoughBalance(
|
||||||
|
userId: string,
|
||||||
|
restaurantId: string,
|
||||||
|
amount: number,
|
||||||
|
): Promise<void> {
|
||||||
|
const wallet = await this.em.findOne(UserWallet, {
|
||||||
|
user: { id: userId },
|
||||||
|
restaurant: { id: restaurantId },
|
||||||
|
});
|
||||||
|
|
||||||
|
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
|
* Set delivery method for cart
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user