cart refactor

This commit is contained in:
2026-02-10 12:40:44 +03:30
parent 5fb1c63c4c
commit 30be5402f3
5 changed files with 49 additions and 43 deletions
@@ -15,6 +15,7 @@ import { ProductService } from 'src/modules/products/providers/product.service';
import { ShopService } from 'src/modules/shops/providers/shops.service';
import { DeliveryService } from 'src/modules/delivery/providers/delivery.service';
import { PaymentMethodService } from 'src/modules/payments/services/payment-method.service';
import { Variant } from 'src/modules/products/entities/variant.entity';
@Injectable()
export class CartValidationService {
@@ -30,14 +31,14 @@ export class CartValidationService {
/**
* Validate product exists and belongs to shop
*/
async validateAndGetFood(productId: string, shopId: string, quantity: number): Promise<Product> {
const product = await this.productService.findOrFail(productId)
async validateAndGetVariant(variantId: string, shopId: string, quantity: number): Promise<Variant> {
const variant = await this.productService.findOrFailVariant(variantId)
if (product.shop.id !== shopId) {
if (variant.product.shop.id !== shopId) {
throw new BadRequestException(CartMessage.PRODUCT_NOT_BELONGS_TO_SHOP);
}
return product;
return variant;
}