fix import errors
This commit is contained in:
@@ -1,39 +1,37 @@
|
||||
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateRestaurantDto } from '../dto/create-shop.dto';
|
||||
import { UpdateRestaurantDto } from '../dto/update-shop.dto';
|
||||
import { UpgradeSubscriptionDto } from '../dto/upgrade-subscription.dto';
|
||||
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 { ShopRepository } from '../repositories/rest.repository';
|
||||
import { RestMessage } from 'src/common/enums/message.enum';
|
||||
import { FindRestaurantsDto } from '../dto/find-shops.dto';
|
||||
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
||||
import { PlanEnum } from '../interface/plan.interface';
|
||||
import { Admin } from '../../../admin/entities/admin.entity';
|
||||
import { AdminRole } from '../../../admin/entities/adminRole.entity';
|
||||
import { Role } from '../../../roles/entities/role.entity';
|
||||
import { Admin } from '../../admin/entities/admin.entity';
|
||||
import { AdminRole } from '../../admin/entities/adminRole.entity';
|
||||
import { Role } from '../../roles/entities/role.entity';
|
||||
import { normalizePhone } from 'src/modules/utils/phone.util';
|
||||
import slugify from 'slugify';
|
||||
import { NotificationPreference } from '../../../notifications/entities/notification-preference.entity';
|
||||
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 { Delivery } from '../../../delivery/entities/delivery.entity';
|
||||
import { PaymentMethod } from '../../../payments/entities/payment-method.entity';
|
||||
import { Pager } from '../../../pager/entities/pager.entity';
|
||||
import { NotificationPreference } from '../../notifications/entities/notification-preference.entity';
|
||||
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 { Delivery } from '../../delivery/entities/delivery.entity';
|
||||
import { PaymentMethod } from '../../payments/entities/payment-method.entity';
|
||||
import { Schedule } from '../entities/schedule.entity';
|
||||
import { WalletTransaction } from '../../../users/entities/wallet-transaction.entity';
|
||||
import { SmsLog } from '../../../notifications/entities/smsLogs.entity';
|
||||
import { Notification } from '../../../notifications/entities/notification.entity';
|
||||
import { WalletTransaction } from '../../users/entities/wallet-transaction.entity';
|
||||
import { SmsLog } from '../../notifications/entities/smsLogs.entity';
|
||||
import { Notification } from '../../notifications/entities/notification.entity';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class ShopService {
|
||||
constructor(
|
||||
private readonly em: EntityManager,
|
||||
private readonly shopRepository: shopRepository,
|
||||
private readonly shopRepository: ShopRepository,
|
||||
) { }
|
||||
|
||||
async setupRestuarant(dto: CreateRestaurantDto): Promise<Shop> {
|
||||
@@ -58,18 +56,15 @@ export class ShopService {
|
||||
establishedYear: dto.establishedYear,
|
||||
phone: dto.phone,
|
||||
isActive: true,
|
||||
plan: dto.plan,
|
||||
domain: `https://dmenu.danakcorp.com/${slug}`,
|
||||
subscriptionId: dto.subscriptionId,
|
||||
subscriptionEndDate: dto.subscriptionEndDate,
|
||||
subscriptionStartDate: dto.subscriptionStartDate,
|
||||
});
|
||||
|
||||
// Find the appropriate role based on plan
|
||||
const roleName = dto.plan === PlanEnum.Base ? 'مدیر (پلن پایه)' : 'مدیر ( پلن ویژه)';
|
||||
const role = await em.findOne(Role, { name: roleName });
|
||||
const role = await em.findOne(Role, { isSystem:true });
|
||||
if (!role) {
|
||||
throw new BadRequestException(`Role not found for plan: ${dto.plan}`);
|
||||
throw new BadRequestException(`System role not found`);
|
||||
}
|
||||
|
||||
const normalizedPhone = normalizePhone(dto.phone);
|
||||
@@ -112,7 +107,6 @@ export class ShopService {
|
||||
limit: dto.limit,
|
||||
search: dto.search,
|
||||
isActive: dto.isActive,
|
||||
plan: dto.plan,
|
||||
orderBy: dto.orderBy,
|
||||
order: dto.order,
|
||||
});
|
||||
@@ -161,30 +155,6 @@ export class ShopService {
|
||||
throw new NotFoundException(RestMessage.NOT_FOUND);
|
||||
}
|
||||
|
||||
if (dto.plan && dto.plan !== shop.plan) {
|
||||
const isPremium = dto.plan === PlanEnum.Premium
|
||||
// find admins and make them premium or base
|
||||
const adminRoles = await this.em.find(AdminRole, {
|
||||
shop: {
|
||||
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.shopRepository.assign(shop, dto);
|
||||
|
||||
@@ -207,7 +177,7 @@ export class ShopService {
|
||||
return shop;
|
||||
}
|
||||
|
||||
async upgradeSubscription(subscriptionId: string, dto: UpgradeSubscriptionDto): Promise<Shop> {
|
||||
async updateSubscription(subscriptionId: string, dto: UpdateSubscriptionDto): Promise<Shop> {
|
||||
const shop = await this.shopRepository.findOne({ subscriptionId });
|
||||
|
||||
if (!shop) {
|
||||
@@ -217,7 +187,6 @@ export class ShopService {
|
||||
const isActive = new Date(dto.subscriptionEndDate) > new Date()
|
||||
|
||||
await this.update(shop.id, {
|
||||
plan: dto.newPlan,
|
||||
subscriptionEndDate: dto.subscriptionEndDate,
|
||||
isActive
|
||||
})
|
||||
@@ -267,8 +236,6 @@ export class ShopService {
|
||||
// Delete payment methods
|
||||
await em.nativeDelete(PaymentMethod, { shop: id });
|
||||
|
||||
// Delete pagers
|
||||
await em.nativeDelete(Pager, { shop: id });
|
||||
|
||||
// Delete wallet transactions
|
||||
await em.nativeDelete(WalletTransaction, { shop: id });
|
||||
|
||||
Reference in New Issue
Block a user