farsi messages

This commit is contained in:
2025-12-22 19:12:03 +03:30
parent ed251611c4
commit 1802b05e74
14 changed files with 365 additions and 230 deletions
@@ -13,6 +13,7 @@ import { OrderStatus } from '../../orders/interface/order.interface';
import { Cart } from '../interfaces/cart.interface';
import { GeographicUtils } from '../utils/geographic.utils';
import { MealType } from '../../foods/interface/food.interface';
import { CartMessage } from 'src/common/enums/message.enum';
@Injectable()
export class CartValidationService {
@@ -24,15 +25,15 @@ export class CartValidationService {
async validateAndGetFood(foodId: string, restaurantId: string, quantity: number): Promise<Food> {
const food = await this.em.findOne(Food, { id: foodId }, { populate: ['restaurant', 'inventory'] });
if (!food) {
throw new NotFoundException(`Food with ID ${foodId} not found`);
throw new NotFoundException(CartMessage.FOOD_NOT_FOUND);
}
if (food.restaurant.id !== restaurantId) {
throw new BadRequestException(`Food ${food.title || food.id} does not belong to restaurant ${restaurantId}`);
throw new BadRequestException(CartMessage.FOOD_NOT_BELONGS_TO_RESTAURANT);
}
if (!food.inventory) {
throw new BadRequestException(`The food ${food.title || food.id} does not have inventory`);
throw new BadRequestException(CartMessage.FOOD_NO_INVENTORY);
}
this.validateStock(food, quantity);
@@ -45,7 +46,7 @@ export class CartValidationService {
validateStock(food: Food, quantity: number): void {
const availableStock = food.inventory!.availableStock;
if (availableStock < quantity) {
throw new BadRequestException(`Insufficient stock for food ${food.title}. Available: ${availableStock}`);
throw new BadRequestException(CartMessage.INSUFFICIENT_STOCK);
}
}
@@ -55,7 +56,7 @@ export class CartValidationService {
async getUserOrFail(userId: string): Promise<User> {
const user = await this.em.findOne(User, { id: userId });
if (!user) {
throw new NotFoundException(`User with ID ${userId} not found`);
throw new NotFoundException(CartMessage.USER_NOT_FOUND);
}
return user;
}
@@ -66,7 +67,7 @@ export class CartValidationService {
async getUserAddressOrFail(addressId: string): Promise<UserAddress> {
const address = await this.em.findOne(UserAddress, { id: addressId }, { populate: ['user'] });
if (!address) {
throw new NotFoundException(`Address with ID ${addressId} not found`);
throw new NotFoundException(CartMessage.ADDRESS_NOT_FOUND);
}
return address;
}
@@ -77,7 +78,7 @@ export class CartValidationService {
async getFoodOrFail(foodId: string): Promise<Food> {
const food = await this.em.findOne(Food, { id: foodId });
if (!food) {
throw new NotFoundException(`Food with ID ${foodId} not found`);
throw new NotFoundException(CartMessage.FOOD_NOT_FOUND);
}
return food;
}
@@ -88,7 +89,7 @@ export class CartValidationService {
async getRestaurantOrFail(restaurantId: string): Promise<Restaurant> {
const restaurant = await this.em.findOne(Restaurant, { id: restaurantId });
if (!restaurant) {
throw new NotFoundException('Restaurant not found');
throw new NotFoundException(CartMessage.RESTAURANT_NOT_FOUND);
}
return restaurant;
}
@@ -98,7 +99,7 @@ export class CartValidationService {
*/
validateAddressOwnership(address: UserAddress, userId: string): void {
if (address.user.id !== userId) {
throw new BadRequestException('Address does not belong to the current user');
throw new BadRequestException(CartMessage.ADDRESS_NOT_BELONGS_TO_USER);
}
}
@@ -133,7 +134,7 @@ export class CartValidationService {
);
if (!GeographicUtils.isPointInPolygon(point, polygon)) {
throw new BadRequestException('Address is outside the restaurant service area');
throw new BadRequestException(CartMessage.ADDRESS_OUTSIDE_SERVICE_AREA);
}
}
@@ -168,12 +169,10 @@ export class CartValidationService {
{ populate: ['restaurant'] },
);
if (!deliveryMethod) {
throw new NotFoundException(
`Delivery method with ID ${deliveryMethodId} not found for restaurant ${restaurantId}`,
);
throw new NotFoundException(CartMessage.DELIVERY_METHOD_NOT_FOUND);
}
if (!deliveryMethod.enabled) {
throw new BadRequestException('Delivery method is not enabled for this restaurant');
throw new BadRequestException(CartMessage.DELIVERY_METHOD_NOT_ENABLED);
}
return deliveryMethod;
}
@@ -207,10 +206,10 @@ export class CartValidationService {
{ populate: ['restaurant'] },
);
if (!paymentMethod) {
throw new NotFoundException(`Payment method with ID ${paymentMethodId} not found for restaurant ${restaurantId}`);
throw new NotFoundException(CartMessage.PAYMENT_METHOD_NOT_FOUND);
}
if (!paymentMethod.enabled) {
throw new BadRequestException('Payment method is not enabled for this restaurant');
throw new BadRequestException(CartMessage.PAYMENT_METHOD_NOT_ENABLED);
}
return paymentMethod;
}
@@ -225,11 +224,11 @@ export class CartValidationService {
});
if (!wallet) {
throw new BadRequestException('User wallet not found');
throw new BadRequestException(CartMessage.WALLET_NOT_FOUND);
}
if (wallet.wallet < amount) {
throw new BadRequestException('User wallet is not enough');
throw new BadRequestException(CartMessage.WALLET_INSUFFICIENT);
}
}
@@ -247,7 +246,7 @@ export class CartValidationService {
});
if (ordersThatUsedTheCouponCount >= maxUsesPerUser) {
throw new BadRequestException(`You have reached the maximum number of uses (${maxUsesPerUser}) for this coupon`);
throw new BadRequestException(CartMessage.COUPON_MAX_USES_REACHED);
}
}