fix:bug --> get admin permission
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user