forked from Yara724/api
YARA-986
This commit is contained in:
102
src/super-admin/super-admin.service.ts
Normal file
102
src/super-admin/super-admin.service.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
ConflictException,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from "@nestjs/common";
|
||||
import { Types } from "mongoose";
|
||||
import { HashService } from "src/utils/hash/hash.service";
|
||||
import { ClientService } from "src/client/client.service";
|
||||
import { ClientDto } from "src/client/dto/create-client.dto";
|
||||
import { ActorAuthService } from "src/auth/auth-services/actor.auth.service";
|
||||
import {
|
||||
InsurerRegisterDto,
|
||||
GenuineRegisterDto,
|
||||
LegalRegisterDto,
|
||||
} from "src/auth/dto/actor/register.actor.dto";
|
||||
import { SuperAdminDbService } from "./entities/db-service/super-admin.db.service";
|
||||
import {
|
||||
CreateSuperAdminDto,
|
||||
CreateFieldExpertAdminDto,
|
||||
CreateRegistrarAdminDto,
|
||||
} 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";
|
||||
|
||||
@Injectable()
|
||||
export class SuperAdminService {
|
||||
constructor(
|
||||
private readonly superAdminDbService: SuperAdminDbService,
|
||||
private readonly hashService: HashService,
|
||||
private readonly clientService: ClientService,
|
||||
private readonly actorAuthService: ActorAuthService,
|
||||
private readonly fieldExpertDbService: FieldExpertDbService,
|
||||
private readonly registrarDbService: RegistrarDbService,
|
||||
) {}
|
||||
|
||||
/** List all super-admin accounts (sans password). */
|
||||
async listSuperAdmins() {
|
||||
const admins = await this.superAdminDbService.findAll();
|
||||
return admins.map(({ password: _pw, ...rest }) => rest);
|
||||
}
|
||||
|
||||
/** Create an additional super-admin account. */
|
||||
async createSuperAdmin(body: CreateSuperAdminDto) {
|
||||
const email = body.email.toLowerCase().trim();
|
||||
const existing = await this.superAdminDbService.findOne({ email });
|
||||
if (existing) {
|
||||
throw new ConflictException(
|
||||
"A super-admin with this email already exists.",
|
||||
);
|
||||
}
|
||||
const password = await this.hashService.hash(body.password);
|
||||
const created = await this.superAdminDbService.create({
|
||||
email,
|
||||
password,
|
||||
role: RoleEnum.SUPER_ADMIN,
|
||||
firstName: body.firstName,
|
||||
lastName: body.lastName,
|
||||
});
|
||||
const { password: _pw, ...rest } = (created as any).toObject
|
||||
? (created as any).toObject()
|
||||
: (created as any);
|
||||
return rest;
|
||||
}
|
||||
|
||||
// ── Client management ────────────────────────────────────────────────────
|
||||
|
||||
async createClient(body: ClientDto) {
|
||||
return this.clientService.addClient(body);
|
||||
}
|
||||
|
||||
async listClients() {
|
||||
return this.clientService.getClients();
|
||||
}
|
||||
|
||||
async listClientNames() {
|
||||
return this.clientService.getClientList();
|
||||
}
|
||||
|
||||
// ── Actor registration proxies ───────────────────────────────────────────
|
||||
|
||||
async registerInsurer(body: InsurerRegisterDto) {
|
||||
return this.actorAuthService.insurerRegister(body);
|
||||
}
|
||||
|
||||
async registerGenuine(body: GenuineRegisterDto) {
|
||||
return this.actorAuthService.genuineRegister(body);
|
||||
}
|
||||
|
||||
async registerLegal(body: LegalRegisterDto) {
|
||||
return this.actorAuthService.legalRegister(body);
|
||||
}
|
||||
|
||||
async createFieldExpert(body: CreateFieldExpertAdminDto) {
|
||||
return this.actorAuthService.createFieldExpertMock(body);
|
||||
}
|
||||
|
||||
async createRegistrar(body: CreateRegistrarAdminDto) {
|
||||
return this.actorAuthService.createRegistrarMock(body);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user