cart refactor
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user