remove inventory

This commit is contained in:
2026-02-08 10:49:16 +03:30
parent 9a7010dcea
commit 8aac87add1
76 changed files with 125 additions and 639 deletions
@@ -1,7 +1,7 @@
import { Injectable, NotFoundException, BadRequestException } from '@nestjs/common';
import { EntityManager } from '@mikro-orm/postgresql';
import { Product } from ../../..products/entities/product.entity';
import { Shop } from ../../..shops/entities/shop.entity';
import { Product } from ../../../products/entities/product.entity';
import { Shop } from ../../../shops/entities/shop.entity';
import { UserAddress } from '../../../users/entities/user-address.entity';
import { User } from '../../../users/entities/user.entity';
import { PaymentMethod } from '../../../payments/entities/payment-method.entity';
@@ -23,10 +23,10 @@ export class CartValidationService {
) { }
/**
* Validate product exists, belongs to shop, has inventory, and check stock
* Validate product exists and belongs to shop
*/
async validateAndGetFood(foodId: string, restaurantId: string, quantity: number): Promise<Product> {
const product = await this.em.findOne(Product, { id: foodId }, { populate: ['shop', 'inventory'] });
const product = await this.em.findOne(Product, { id: foodId }, { populate: ['shop'] });
if (!product) {
throw new NotFoundException(CartMessage.FOOD_NOT_FOUND);
}
@@ -35,23 +35,9 @@ export class CartValidationService {
throw new BadRequestException(CartMessage.FOOD_NOT_BELONGS_TO_RESTAURANT);
}
if (!product.inventory) {
throw new BadRequestException(CartMessage.FOOD_NO_INVENTORY);
}
this.validateStock(product, quantity);
return product;
}
/**
* Validate stock availability for product
*/
validateStock(product: Product, quantity: number): void {
const availableStock = product.inventory!.availableStock;
if (availableStock < quantity) {
throw new BadRequestException(CartMessage.INSUFFICIENT_STOCK + product.title);
}
}
/**
* Get user or throw if not found