fix : update shop

This commit is contained in:
2026-02-15 14:05:32 +03:30
parent 38b38cdb4c
commit f965e47bfd
11 changed files with 45 additions and 38 deletions
+2 -1
View File
@@ -424,7 +424,7 @@ export const enum AdminMessage {
ADMIN_ROLE_NOT_FOUND = 'نقش ادمین یافت نشد',
}
export const enum RestMessage {
export const enum ShopMessage {
NOT_FOUND = 'کسب و کار یافت نشد',
DUPLICATE_SUBSCRIPTION_ID = 'شناسه اشتراک تکراری است',
SYSTEM_ROLE_NOT_FOUND = 'نقش سیستمی یافت نشد',
@@ -466,6 +466,7 @@ export const enum RestMessage {
PAYMENT_GATEWAY_ERROR = 'خطا در اتصال به درگاه پرداخت',
QUOTA_UPDATED = 'حجم ایمیل با موفقیت به روز شد',
USER_DOES_NOT_HAVE_ACCESS_TO_SERVICE = 'کاربر دسترسی به این سرویس را ندارد',
SHOP_EXIST_WITH_THIS_SLUG='فروشگاه با این اسلاگ وجود دارد'
}
export const enum DomainMessage {
+4 -4
View File
@@ -6,7 +6,7 @@ import { UserService } from 'src/modules/users/providers/user.service';
import { randomInt } from 'crypto';
import { TokensService } from './tokens.service';
import { ShopRepository } from 'src/modules/shops/repositories/rest.repository';
import { AuthMessage, RestMessage } from 'src/common/enums/message.enum';
import { AuthMessage, ShopMessage } from 'src/common/enums/message.enum';
import { AdminRepository } from 'src/modules/admin/repositories/admin.repository';
import { AdminLoginTransformer } from '../transformers/admin-login.transformer';
import { UserLoginTransformer } from '../transformers/user-login.transformer';
@@ -71,7 +71,7 @@ export class AuthService {
const shop = await this.shopRepository.findOne({ slug });
if (!shop) {
throw new BadRequestException(RestMessage.NOT_FOUND);
throw new BadRequestException(ShopMessage.NOT_FOUND);
}
const tokens = await this.tokensService.generateTokens(user.id, shop.id, false, slug);
@@ -96,7 +96,7 @@ export class AuthService {
const shop = await this.shopRepository.findOne({ slug });
if (!shop) {
throw new BadRequestException(RestMessage.NOT_FOUND);
throw new BadRequestException(ShopMessage.NOT_FOUND);
}
const tokens = await this.tokensService.generateTokens(admin.id, shop.id, true, slug);
@@ -120,7 +120,7 @@ export class AuthService {
const shop = await this.shopRepository.findOne({ slug });
if (!shop) {
throw new BadRequestException(RestMessage.NOT_FOUND);
throw new BadRequestException(ShopMessage.NOT_FOUND);
}
const tokens = await this.tokensService.generateTokens(admin.id, shop.id, true, slug);
@@ -8,7 +8,7 @@ import { EntityManager } from '@mikro-orm/postgresql';
import { RequiredEntityData } from '@mikro-orm/core';
import { Coupon } from '../entities/coupon.entity';
import { CouponType } from '../interface/coupon';
import { CouponMessage, RestMessage } from 'src/common/enums/message.enum';
import { CouponMessage, ShopMessage } from 'src/common/enums/message.enum';
import { randomBytes } from 'node:crypto';
@Injectable()
@@ -22,7 +22,7 @@ export class CouponService {
async create(shopId: string, createCouponDto: CreateCouponDto): Promise<Coupon> {
const shop = await this.shopRepository.findOne({ id: shopId });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
throw new NotFoundException(ShopMessage.NOT_FOUND);
}
// Check if code already exists
@@ -260,7 +260,7 @@ export class CouponService {
async generateCouponCode(shopId: string): Promise<{ code: string }> {
const shop = await this.shopRepository.findOne({ id: shopId });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
throw new NotFoundException(ShopMessage.NOT_FOUND);
}
const code = this.generateShortCode(shop.slug);
const existing = await this.couponRepository.findOne({ code, shop: { id: shopId } });
@@ -5,7 +5,7 @@ import { Shop } from '../../shops/entities/shop.entity';
import { CreatePreferenceDto } from '../dto/create-preference.dto';
import { UpdatePreferenceDto } from '../dto/update-preference.dto';
import { NotifTitleEnum } from '../interfaces/notification.interface';
import { NotificationMessage, RestMessage } from 'src/common/enums/message.enum';
import { NotificationMessage, ShopMessage } from 'src/common/enums/message.enum';
@Injectable()
export class NotificationPreferenceService {
@@ -14,7 +14,7 @@ export class NotificationPreferenceService {
async create(shopId: string, dto: CreatePreferenceDto): Promise<NotificationPreference> {
const shop = await this.em.findOne(Shop, { id: shopId });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
throw new NotFoundException(ShopMessage.NOT_FOUND);
}
const preference = this.em.create(NotificationPreference, {
@@ -6,7 +6,7 @@ import { CreatePaymentMethodDto } from '../dto/create-payment-method.dto';
import { UpdatePaymentMethodDto } from '../dto/update-payment-method.dto';
import { RequiredEntityData } from '@mikro-orm/core';
import { Shop } from '../../shops/entities/shop.entity';
import { RestMessage, PaymentMessage } from 'src/common/enums/message.enum';
import { ShopMessage, PaymentMessage } from 'src/common/enums/message.enum';
@Injectable()
export class PaymentMethodService {
@@ -19,7 +19,7 @@ export class PaymentMethodService {
// Check if shop exists
const shop = await this.em.findOne(Shop, { id: shopId });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
throw new NotFoundException(ShopMessage.NOT_FOUND);
}
const paymentMethod = this.paymentMethodRepository.create({
@@ -5,7 +5,7 @@ import { CategoryRepository } from '../repositories/category.repository';
import { EntityManager } from '@mikro-orm/postgresql';
import { RequiredEntityData } from '@mikro-orm/core';
import { Category } from '../entities/category.entity';
import { CategoryMessage, RestMessage } from 'src/common/enums/message.enum';
import { CategoryMessage, ShopMessage } from 'src/common/enums/message.enum';
import { Shop } from '../../shops/entities/shop.entity';
@Injectable()
@@ -18,7 +18,7 @@ export class CategoryService {
async create(shopId: string, dto: CreateCategoryDto): Promise<Category> {
const shop = await this.em.findOne(Shop, { id: shopId });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
throw new NotFoundException(ShopMessage.NOT_FOUND);
}
let parent: Category | undefined;
@@ -8,7 +8,7 @@ import { UserRepository } from '../../users/repositories/user.repository';
import { EntityManager } from '@mikro-orm/postgresql';
import { RequiredEntityData } from '@mikro-orm/core';
import { Review } from '../entities/review.entity';
import { OrderMessage, ProductMessage, RestMessage, UserMessage, ReviewMessage } from 'src/common/enums/message.enum';
import { OrderMessage, ProductMessage, ShopMessage, UserMessage, ReviewMessage } from 'src/common/enums/message.enum';
import { Order } from '../../orders/entities/order.entity';
import { OrderItem } from '../../orders/entities/order-item.entity';
import { Shop } from '../../shops/entities/shop.entity';
@@ -115,7 +115,7 @@ export class ReviewService {
const { shopSlug: restuarantSlug, ...restDto } = dto;
const shop = await this.em.findOne(Shop, { slug: restuarantSlug });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
throw new NotFoundException(ShopMessage.NOT_FOUND);
}
return this.reviewRepository.findAllPaginated({ ...restDto, shopId: shop.id });
}
+2 -2
View File
@@ -8,7 +8,7 @@ import { EntityManager } from '@mikro-orm/postgresql';
import { CreateRoleDto } from '../dto/create-role.dto';
import { UpdateRoleDto } from '../dto/update-role.dto';
import { RolePermission } from '../entities/rolePermission.entity';
import { RestMessage, RoleMessage } from 'src/common/enums/message.enum';
import { ShopMessage, RoleMessage } from 'src/common/enums/message.enum';
@Injectable()
export class RolesService {
@@ -33,7 +33,7 @@ export class RolesService {
if (shopId) {
shop = await this.em.findOne(Shop, { id: shopId });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
throw new NotFoundException(ShopMessage.NOT_FOUND);
}
}
@@ -8,7 +8,7 @@ import { UpdateScheduleDto } from '../dto/update-schedule.dto';
import { FindSchedulesDto } from '../dto/find-schedules.dto';
import { ShopRepository } from '../repositories/rest.repository';
import { Shop } from '../entities/shop.entity';
import { RestMessage } from 'src/common/enums/message.enum';
import { ShopMessage } from 'src/common/enums/message.enum';
// import { RestMessage } from 'src/common/enums/message.enum';
@Injectable()
@@ -51,7 +51,7 @@ export class ScheduleService {
async findTodaySchedules(slug: string): Promise<Schedule | null> {
const shop = await this.em.findOne(Shop, { slug });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
throw new NotFoundException(ShopMessage.NOT_FOUND);
}
const today = new Date();
const weekDay = today.getDay(); // 0 = Sunday, 6 = Saturday
@@ -68,7 +68,7 @@ export class ScheduleService {
async findScheduleBySlug(slug: string): Promise<Schedule[]> {
const shop = await this.em.findOne(Shop, { slug });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
throw new NotFoundException(ShopMessage.NOT_FOUND);
}
const where: FilterQuery<Schedule> = {
+20 -14
View File
@@ -5,7 +5,7 @@ import { UpdateSubscriptionDto } from '../dto/update-subscription.dto';
import { Shop } from '../entities/shop.entity';
import { EntityManager } from '@mikro-orm/postgresql';
import { ShopRepository } from '../repositories/rest.repository';
import { RestMessage } from 'src/common/enums/message.enum';
import { ShopMessage } from 'src/common/enums/message.enum';
import { FindRestaurantsDto } from '../dto/find-shops.dto';
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
import { Admin } from '../../admin/entities/admin.entity';
@@ -46,7 +46,7 @@ export class ShopService {
const validateSubscriptionId = await em.findOne(Shop, { subscriptionId: dto.subscriptionId })
if (validateSubscriptionId) {
throw new BadRequestException(RestMessage.DUPLICATE_SUBSCRIPTION_ID);
throw new BadRequestException(ShopMessage.DUPLICATE_SUBSCRIPTION_ID);
}
// Create shop
@@ -64,7 +64,7 @@ export class ShopService {
const role = await em.findOne(Role, { isSystem: true });
if (!role) {
throw new BadRequestException(RestMessage.SYSTEM_ROLE_NOT_FOUND);
throw new BadRequestException(ShopMessage.SYSTEM_ROLE_NOT_FOUND);
}
const normalizedPhone = normalizePhone(dto.phone);
@@ -116,7 +116,7 @@ export class ShopService {
const shop = await this.em.findOne(Shop, { slug });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
throw new NotFoundException(ShopMessage.NOT_FOUND);
}
return shop;
@@ -126,7 +126,7 @@ export class ShopService {
const shop = await this.shopRepository.findOne({ id });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
throw new NotFoundException(ShopMessage.NOT_FOUND);
}
return shop;
@@ -137,7 +137,7 @@ export class ShopService {
const shop = await this.shopRepository.findOne({ subscriptionId });
console.log('shop', shop)
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
throw new NotFoundException(ShopMessage.NOT_FOUND);
}
return shop;
}
@@ -146,19 +146,25 @@ export class ShopService {
const shop = await this.findBySlug(slug);
return shop;
}
// TODO : it must be done inside transaction
async update(id: string, dto: UpdateRestaurantDto): Promise<Shop> {
async update(id: string, dto: UpdateRestaurantDto): Promise<Shop> {
const shop = await this.shopRepository.findOne({ id: id });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
throw new NotFoundException(ShopMessage.NOT_FOUND);
}
if (dto.slug) {
const shopWithThisSlug = await this.shopRepository.findOne({ slug: dto.slug, $not: { id } });
if (shopWithThisSlug) {
throw new NotFoundException(ShopMessage.SHOP_EXIST_WITH_THIS_SLUG);
}
}
this.shopRepository.assign(shop, dto);
await this.em.persistAndFlush(shop);
await this.em.flush();
return shop;
}
@@ -168,7 +174,7 @@ export class ShopService {
const shop = await this.shopRepository.findOne({ subscriptionId });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
throw new NotFoundException(ShopMessage.NOT_FOUND);
}
const isActive = new Date(dto.subscriptionEndDate) > new Date()
@@ -187,7 +193,7 @@ export class ShopService {
const shop = await em.findOne(Shop, { id });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
throw new NotFoundException(ShopMessage.NOT_FOUND);
}
// Delete orders first (will cascade to order items and payments due to cascade settings)
@@ -235,7 +241,7 @@ export class ShopService {
async findOrFail(shopId: string) {
const shop = await this.shopRepository.findOne({ id: shopId }, { populate: ['deliveries'] })
if (!shop) {
throw new BadRequestException(RestMessage.NOT_FOUND);
throw new BadRequestException(ShopMessage.NOT_FOUND);
}
return shop
}
@@ -243,7 +249,7 @@ export class ShopService {
async findOrFailBySlug(shopSlug: string) {
const shop = await this.shopRepository.findOne({ slug: shopSlug }, { populate: ['deliveries'] })
if (!shop) {
throw new BadRequestException(RestMessage.NOT_FOUND);
throw new BadRequestException(ShopMessage.NOT_FOUND);
}
return shop
}
+3 -3
View File
@@ -18,7 +18,7 @@ import { WalletTransactionRepository } from '../repositories/wallet-transaction.
import { WalletService } from './wallet.service';
import { WalletTransactionReason, WalletTransactionType } from '../interface/wallet';
import { WalletTransaction } from '../entities/wallet-transaction.entity';
import { RestMessage, UserMessage } from 'src/common/enums/message.enum';
import { ShopMessage, UserMessage } from 'src/common/enums/message.enum';
@Injectable()
export class UserService {
@@ -87,7 +87,7 @@ export class UserService {
// get registerscore from shop
const shop = await this.restaurantRepository.findOne({ id: shopId });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
throw new NotFoundException(ShopMessage.NOT_FOUND);
}
const points = Number(shop.score?.registerScore || 0);
const createData = _raw as unknown as RequiredEntityData<User>;
@@ -315,7 +315,7 @@ export class UserService {
}
const shop = await em.findOne(Shop, { id: shopId });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
throw new NotFoundException(ShopMessage.NOT_FOUND);
}
let walletTransaction = await em.findOne(WalletTransaction, { user: { id: userId }, shop: { id: shopId } },
{ orderBy: { createdAt: 'DESC' } });