product module

This commit is contained in:
2026-02-08 15:06:52 +03:30
parent 8aac87add1
commit 92cd7432f5
32 changed files with 359 additions and 259 deletions
+28 -13
View File
@@ -4,9 +4,9 @@ import { UpdateRestaurantDto } from '../dto/update-shop.dto';
import { UpgradeSubscriptionDto } from '../dto/upgrade-subscription.dto';
import { Shop } from '../entities/shop.entity';
import { EntityManager } from '@mikro-orm/postgresql';
import { RestRepository } from '../repositories/rest.repository';
import { shopRepository } from '../repositories/rest.repository';
import { RestMessage } from 'src/common/enums/message.enum';
import { FindRestaurantsDto } from ../../..shops.dto';
import { FindRestaurantsDto } from '../providers/shops.dto';
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
import { PlanEnum } from '../interface/plan.interface';
import { Admin } from '../../../admin/entities/admin.entity';
@@ -18,8 +18,8 @@ import { NotificationPreference } from '../../../notifications/entities/notifica
import { notificationPreferencesData } from '../../../../seeders/data/notification-preferences.data';
import { Order } from '../../../orders/entities/order.entity';
import { Coupon } from '../../../coupons/entities/coupon.entity';
import { Category } from ../../..products/entities/category.entity';
import { Product } from ../../..products/entities/product.entity';
import { Category } from ../../..products / entities / category.entity';
import { Product } from ../../..products / entities / product.entity';
import { Delivery } from '../../../delivery/entities/delivery.entity';
import { PaymentMethod } from '../../../payments/entities/payment-method.entity';
import { Pager } from '../../../pager/entities/pager.entity';
@@ -30,10 +30,10 @@ import { Notification } from '../../../notifications/entities/notification.entit
@Injectable()
export class RestaurantsService {
export class ShopService {
constructor(
private readonly em: EntityManager,
private readonly restRepository: RestRepository,
private readonly shopRepository: shopRepository,
) { }
async setupRestuarant(dto: CreateRestaurantDto): Promise<Shop> {
@@ -107,7 +107,7 @@ export class RestaurantsService {
}
async findAll(dto: FindRestaurantsDto): Promise<PaginatedResult<Shop>> {
return this.restRepository.findAllPaginated({
return this.shopRepository.findAllPaginated({
page: dto.page,
limit: dto.limit,
search: dto.search,
@@ -129,7 +129,7 @@ export class RestaurantsService {
}
async findOne(id: string): Promise<Shop> {
const shop = await this.restRepository.findOne({ id });
const shop = await this.shopRepository.findOne({ id });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
@@ -140,7 +140,7 @@ export class RestaurantsService {
async findOneBySubscriptionId(subscriptionId: string): Promise<Shop> {
console.log('subscriptionId', subscriptionId)
const shop = await this.restRepository.findOne({ subscriptionId });
const shop = await this.shopRepository.findOne({ subscriptionId });
console.log('shop', shop)
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
@@ -155,7 +155,7 @@ export class RestaurantsService {
// TODO : it must be done inside transaction
async update(id: string, dto: UpdateRestaurantDto): Promise<Shop> {
const shop = await this.restRepository.findOne({ id: id });
const shop = await this.shopRepository.findOne({ id: id });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
@@ -186,7 +186,7 @@ export class RestaurantsService {
}
this.restRepository.assign(shop, dto);
this.shopRepository.assign(shop, dto);
await this.em.persistAndFlush(shop);
@@ -195,7 +195,7 @@ export class RestaurantsService {
async remove(id: string) {
// Soft delete the shop by setting isActive to false
const shop = await this.restRepository.findOne({ id });
const shop = await this.shopRepository.findOne({ id });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
@@ -208,7 +208,7 @@ export class RestaurantsService {
}
async upgradeSubscription(subscriptionId: string, dto: UpgradeSubscriptionDto): Promise<Shop> {
const shop = await this.restRepository.findOne({ subscriptionId });
const shop = await this.shopRepository.findOne({ subscriptionId });
if (!shop) {
throw new NotFoundException(RestMessage.NOT_FOUND);
@@ -278,4 +278,19 @@ export class RestaurantsService {
});
}
async findOrFail(shopId: string) {
const shop = await this.shopRepository.findOne({ id: shopId }, { populate: ['deliveries'] })
if (!shop) {
throw new BadRequestException("Shop not found")
}
return shop
}
async findOrFailBySlug(shopSlug: string) {
const shop = await this.shopRepository.findOne({ slug: shopSlug }, { populate: ['deliveries'] })
if (!shop) {
throw new BadRequestException("Shop not found")
}
return shop
}
}