forked from Yara724/api
YARA-1094, YARA-1095, YARA-1096
This commit is contained in:
@@ -19,10 +19,12 @@ import {
|
||||
CreateSuperAdminDto,
|
||||
CreateFieldExpertAdminDto,
|
||||
CreateRegistrarAdminDto,
|
||||
CreateFinancialExpertAdminDto,
|
||||
} from "./dto/super-admin.dto";
|
||||
import { RoleEnum } from "src/Types&Enums/role.enum";
|
||||
import { FieldExpertDbService } from "src/users/entities/db-service/field-expert.db.service";
|
||||
import { RegistrarDbService } from "src/users/entities/db-service/registrar.db.service";
|
||||
import { FinancialExpertDbService } from "src/users/entities/db-service/financial-expert.db.service";
|
||||
|
||||
@Injectable()
|
||||
export class SuperAdminService {
|
||||
@@ -33,6 +35,7 @@ export class SuperAdminService {
|
||||
private readonly actorAuthService: ActorAuthService,
|
||||
private readonly fieldExpertDbService: FieldExpertDbService,
|
||||
private readonly registrarDbService: RegistrarDbService,
|
||||
private readonly financialExpertDbService: FinancialExpertDbService,
|
||||
) {}
|
||||
|
||||
/** List all super-admin accounts (sans password). */
|
||||
@@ -99,4 +102,29 @@ export class SuperAdminService {
|
||||
async createRegistrar(body: CreateRegistrarAdminDto) {
|
||||
return this.actorAuthService.createRegistrarMock(body);
|
||||
}
|
||||
|
||||
async createFinancialExpert(body: CreateFinancialExpertAdminDto) {
|
||||
const email = body.email.toLowerCase().trim();
|
||||
const existing = await this.financialExpertDbService.findOne({ email });
|
||||
if (existing) {
|
||||
throw new ConflictException(
|
||||
"A FinancialExpert with this email already exists.",
|
||||
);
|
||||
}
|
||||
const hashedPassword = await this.hashService.hash(body.password);
|
||||
const created = await this.financialExpertDbService.create({
|
||||
email,
|
||||
password: hashedPassword,
|
||||
firstName: body.firstName,
|
||||
lastName: body.lastName,
|
||||
mobile: body.mobile,
|
||||
phone: body.phone,
|
||||
clientKey: new Types.ObjectId(body.clientId),
|
||||
role: RoleEnum.FINANCIAL_EXPERT,
|
||||
} as any);
|
||||
const { password: _pw, ...rest } = (created as any).toObject
|
||||
? (created as any).toObject()
|
||||
: (created as any);
|
||||
return rest;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user