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
+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
}