From 96108d0b35e5165f76e2e6db68ca6b61b39ec250 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Wed, 28 Jan 2026 12:41:30 +0330 Subject: [PATCH] up rest --- .../providers/restaurants.service.ts | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/modules/restaurants/providers/restaurants.service.ts b/src/modules/restaurants/providers/restaurants.service.ts index 3881f70..eb21602 100644 --- a/src/modules/restaurants/providers/restaurants.service.ts +++ b/src/modules/restaurants/providers/restaurants.service.ts @@ -28,6 +28,7 @@ import { WalletTransaction } from '../../users/entities/wallet-transaction.entit import { SmsLog } from '../../notifications/entities/smsLogs.entity'; import { Notification } from '../../notifications/entities/notification.entity'; + @Injectable() export class RestaurantsService { constructor( @@ -58,7 +59,7 @@ export class RestaurantsService { phone: dto.phone, isActive: true, plan: dto.plan, - domain: `https://dmenu-plus-front.dev.danakcorp.com/${slug}`, + domain: `https://dmenu.danakcorp.com/${slug}`, subscriptionId: dto.subscriptionId, subscriptionEndDate: dto.subscriptionEndDate, subscriptionStartDate: dto.subscriptionStartDate, @@ -138,7 +139,9 @@ export class RestaurantsService { } async findOneBySubscriptionId(subscriptionId: string): Promise { + console.log('subscriptionId', subscriptionId) const restaurant = await this.restRepository.findOne({ subscriptionId }); + console.log('restaurant', restaurant) if (!restaurant) { throw new NotFoundException(RestMessage.NOT_FOUND); } @@ -149,7 +152,7 @@ export class RestaurantsService { const restaurant = await this.findBySlug(slug); return restaurant; } - + // TODO : it must be done inside transaction async update(id: string, dto: UpdateRestaurantDto): Promise { const restaurant = await this.restRepository.findOne({ id: id }); @@ -158,6 +161,31 @@ export class RestaurantsService { throw new NotFoundException(RestMessage.NOT_FOUND); } + if (dto.plan && dto.plan !== restaurant.plan) { + const isPremium = dto.plan === PlanEnum.Premium + // find admins and make them premium or base + const adminRoles = await this.em.find(AdminRole, { + restaurant: { + id + }, + role: { + name: isPremium ? 'مدیر (پلن پایه)' : 'مدیر ( پلن ویژه)' + } + }) + const newRole = await this.em.findOne(Role, { + name: isPremium ? 'مدیر ( پلن ویژه)' : 'مدیر (پلن پایه)' + }) + if (!newRole) { + throw new BadRequestException("Role Not Found") + } + adminRoles.forEach(a => { + a.role = newRole + }) + + this.em.persistAndFlush(adminRoles) + + } + this.restRepository.assign(restaurant, dto); await this.em.persistAndFlush(restaurant); @@ -186,10 +214,10 @@ export class RestaurantsService { throw new NotFoundException(RestMessage.NOT_FOUND); } - restaurant.plan = dto.newPlan; - restaurant.subscriptionEndDate = dto.subscriptionEndDate; - - await this.em.persistAndFlush(restaurant); + await this.update(restaurant.id, { + plan: dto.newPlan, + subscriptionEndDate:dto.subscriptionEndDate + }) return restaurant; }