fix:bug --> get admin permission

This commit is contained in:
2025-12-27 12:00:31 +03:30
parent c8e00f9e1a
commit a7c18a9bff
3 changed files with 26 additions and 38 deletions
@@ -11,6 +11,7 @@ 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 { normalizePhone } from 'src/modules/utils/phone.util';
@Injectable()
export class RestaurantsService {
@@ -52,22 +53,21 @@ export class RestaurantsService {
throw new BadRequestException(`Role not found for plan: ${dto.plan}`);
}
// Create admin (using a default phone number for now - this could be made configurable)
const adminPhone = `admin_${dto.slug}@system.local`; // Temporary phone format for system-generated admins
let admin = await em.findOne(Admin, { phone: adminPhone });
const normalizedPhone = normalizePhone(dto.phone);
let admin = await em.findOne(Admin, { phone: normalizedPhone });
if (!admin) {
admin = em.create(Admin, {
phone: adminPhone,
firstName: 'مدیر',
lastName: dto.name,
phone: normalizedPhone,
firstName: 'نام مدیر',
lastName: 'نام خانوادگی مدیر',
});
}
// Create admin role relationship
const adminRole = em.create(AdminRole, {
admin: admin,
role: role,
restaurant: restaurant,
admin,
role,
restaurant,
});
// Persist all entities