forked from Yara724/api
Enforce claim beneficiary access and retire unused legacy APIs
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
import { AiService } from "src/ai/ai.service";
|
||||
import { currentAiCaptures } from "src/ai/ai-captures";
|
||||
import { ClaimCaseDbService } from "src/claim-request-management/entites/db-service/claim-case.db.service";
|
||||
import {
|
||||
BadRequestException,
|
||||
Body,
|
||||
@@ -23,40 +20,38 @@ import {
|
||||
ApiTags,
|
||||
} from "@nestjs/swagger";
|
||||
import { Types } from "mongoose";
|
||||
import { SuperAdminGuard } from "./guards/super-admin.guard";
|
||||
import { SuperAdminService } from "./super-admin.service";
|
||||
import {
|
||||
CreateSuperAdminDto,
|
||||
CreateFieldExpertAdminDto,
|
||||
CreateRegistrarAdminDto,
|
||||
CreateCallCenterAgentDto,
|
||||
} from "./dto/super-admin.dto";
|
||||
import { currentAiCaptures } from "src/ai/ai-captures";
|
||||
import { AiService } from "src/ai/ai.service";
|
||||
import { InsurerRegisterDto } from "src/auth/dto/actor/register.actor.dto";
|
||||
import { ClaimCaseDbService } from "src/claim-request-management/entites/db-service/claim-case.db.service";
|
||||
import { CreateBranchDto } from "src/client/dto/create-branch.dto";
|
||||
import { ClientDto } from "src/client/dto/create-client.dto";
|
||||
import {
|
||||
InsurerRegisterDto,
|
||||
GenuineRegisterDto,
|
||||
LegalRegisterDto,
|
||||
} from "src/auth/dto/actor/register.actor.dto";
|
||||
import { SystemSettingsService } from "src/system-settings/system-settings.service";
|
||||
import {
|
||||
SystemSettingsResponseDto,
|
||||
UpdateSystemSettingsDto,
|
||||
} from "src/system-settings/dto/system-settings.dto";
|
||||
import { SetExternalInquiriesLiveDto } from "src/client/dto/external-inquiries-live.dto";
|
||||
import { ExpertInsurerService } from "src/expert-insurer/expert-insurer.service";
|
||||
import { ListQueryV2Dto } from "src/common/dto/list-query-v2.dto";
|
||||
import {
|
||||
UnifiedFileStatusReportDto,
|
||||
UnifiedFileStatusReportQueryDto,
|
||||
} from "src/common/dto/unified-file-status-report.dto";
|
||||
import { CreateBranchDto } from "src/client/dto/create-branch.dto";
|
||||
import { FileRating } from "src/request-management/entities/schema/request-management.schema";
|
||||
import {
|
||||
CreateBlameExpertByInsurerDto,
|
||||
CreateClaimExpertByInsurerDto,
|
||||
CreateFileMakerByInsurerDto,
|
||||
CreateFileReviewerByInsurerDto,
|
||||
} from "src/expert-insurer/dto/create-insurer-expert.dto";
|
||||
import { ExpertInsurerService } from "src/expert-insurer/expert-insurer.service";
|
||||
import {
|
||||
SystemSettingsResponseDto,
|
||||
UpdateSystemSettingsDto,
|
||||
} from "src/system-settings/dto/system-settings.dto";
|
||||
import { SystemSettingsService } from "src/system-settings/system-settings.service";
|
||||
import {
|
||||
CreateCallCenterAgentDto,
|
||||
CreateFieldExpertAdminDto,
|
||||
CreateRegistrarAdminDto,
|
||||
CreateSuperAdminDto,
|
||||
} from "./dto/super-admin.dto";
|
||||
import { SuperAdminGuard } from "./guards/super-admin.guard";
|
||||
import { SuperAdminService } from "./super-admin.service";
|
||||
|
||||
@ApiTags("super-admin")
|
||||
@ApiBearerAuth()
|
||||
@@ -119,30 +114,6 @@ export class SuperAdminController {
|
||||
return this.superAdminService.registerInsurer(body);
|
||||
}
|
||||
|
||||
@Post("register/genuine")
|
||||
@ApiOperation({
|
||||
deprecated: true,
|
||||
summary: "[DEPRECATED] Register a genuine actor",
|
||||
description:
|
||||
"Kept for legacy clients. Use the unified onboarding flow instead.",
|
||||
})
|
||||
@ApiBody({ type: GenuineRegisterDto })
|
||||
registerGenuine(@Body() body: GenuineRegisterDto) {
|
||||
return this.superAdminService.registerGenuine(body);
|
||||
}
|
||||
|
||||
@Post("register/legal")
|
||||
@ApiOperation({
|
||||
deprecated: true,
|
||||
summary: "[DEPRECATED] Register a legal actor",
|
||||
description:
|
||||
"Kept for legacy clients. Use the unified onboarding flow instead.",
|
||||
})
|
||||
@ApiBody({ type: LegalRegisterDto })
|
||||
registerLegal(@Body() body: LegalRegisterDto) {
|
||||
return this.superAdminService.registerLegal(body);
|
||||
}
|
||||
|
||||
@Post("create-field-expert")
|
||||
@ApiOperation({ summary: "Create a field expert" })
|
||||
@ApiBody({ type: CreateFieldExpertAdminDto })
|
||||
@@ -201,9 +172,21 @@ export class SuperAdminController {
|
||||
@ApiOperation({ summary: "List branches for a given client" })
|
||||
@ApiQuery({ name: "clientId", required: true, type: String })
|
||||
@ApiQuery({ name: "search", required: false, type: String })
|
||||
@ApiQuery({ name: "from", required: false, description: "Optional start datetime (ISO string)" })
|
||||
@ApiQuery({ name: "to", required: false, description: "Optional end datetime (ISO string)" })
|
||||
@ApiQuery({ name: "isActive", required: false, description: "Filter active state (true/false)" })
|
||||
@ApiQuery({
|
||||
name: "from",
|
||||
required: false,
|
||||
description: "Optional start datetime (ISO string)",
|
||||
})
|
||||
@ApiQuery({
|
||||
name: "to",
|
||||
required: false,
|
||||
description: "Optional end datetime (ISO string)",
|
||||
})
|
||||
@ApiQuery({
|
||||
name: "isActive",
|
||||
required: false,
|
||||
description: "Filter active state (true/false)",
|
||||
})
|
||||
getInsuranceBranches(
|
||||
@Query("clientId") clientId: string,
|
||||
@Query("search") search?: string,
|
||||
@@ -211,10 +194,12 @@ export class SuperAdminController {
|
||||
@Query("to") to?: string,
|
||||
@Query("isActive") isActive?: string,
|
||||
) {
|
||||
return this.expertInsurerService.retrieveInsuranceBranches(
|
||||
clientId,
|
||||
{ search, from, to, isActive },
|
||||
);
|
||||
return this.expertInsurerService.retrieveInsuranceBranches(clientId, {
|
||||
search,
|
||||
from,
|
||||
to,
|
||||
isActive,
|
||||
});
|
||||
}
|
||||
|
||||
@Post("insurer/branches")
|
||||
@@ -226,7 +211,9 @@ export class SuperAdminController {
|
||||
{
|
||||
type: "object",
|
||||
required: ["clientId"],
|
||||
properties: { clientId: { type: "string", description: "Client ObjectId" } },
|
||||
properties: {
|
||||
clientId: { type: "string", description: "Client ObjectId" },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -260,13 +247,19 @@ export class SuperAdminController {
|
||||
if (typeof isActive === "boolean") {
|
||||
active = isActive;
|
||||
} else {
|
||||
const normalized = String(isActive ?? "").trim().toLowerCase();
|
||||
const normalized = String(isActive ?? "")
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
if (!["true", "false", "1", "0", "yes", "no"].includes(normalized)) {
|
||||
throw new BadRequestException("isActive must be a boolean");
|
||||
}
|
||||
active = ["true", "1", "yes"].includes(normalized);
|
||||
}
|
||||
return this.expertInsurerService.setBranchActive(clientId, branchId, active);
|
||||
return this.expertInsurerService.setBranchActive(
|
||||
clientId,
|
||||
branchId,
|
||||
active,
|
||||
);
|
||||
}
|
||||
|
||||
@Post("insurer/experts/blame")
|
||||
@@ -278,7 +271,9 @@ export class SuperAdminController {
|
||||
{
|
||||
type: "object",
|
||||
required: ["clientId"],
|
||||
properties: { clientId: { type: "string", description: "Client ObjectId" } },
|
||||
properties: {
|
||||
clientId: { type: "string", description: "Client ObjectId" },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -299,7 +294,9 @@ export class SuperAdminController {
|
||||
{
|
||||
type: "object",
|
||||
required: ["clientId"],
|
||||
properties: { clientId: { type: "string", description: "Client ObjectId" } },
|
||||
properties: {
|
||||
clientId: { type: "string", description: "Client ObjectId" },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -320,7 +317,9 @@ export class SuperAdminController {
|
||||
{
|
||||
type: "object",
|
||||
required: ["clientId"],
|
||||
properties: { clientId: { type: "string", description: "Client ObjectId" } },
|
||||
properties: {
|
||||
clientId: { type: "string", description: "Client ObjectId" },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -333,7 +332,9 @@ export class SuperAdminController {
|
||||
}
|
||||
|
||||
@Post("insurer/experts/file-reviewer")
|
||||
@ApiOperation({ summary: "Create a FileReviewer account under a given client" })
|
||||
@ApiOperation({
|
||||
summary: "Create a FileReviewer account under a given client",
|
||||
})
|
||||
@ApiBody({
|
||||
schema: {
|
||||
allOf: [
|
||||
@@ -341,7 +342,9 @@ export class SuperAdminController {
|
||||
{
|
||||
type: "object",
|
||||
required: ["clientId"],
|
||||
properties: { clientId: { type: "string", description: "Client ObjectId" } },
|
||||
properties: {
|
||||
clientId: { type: "string", description: "Client ObjectId" },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -374,11 +377,15 @@ export class SuperAdminController {
|
||||
@ApiOperation({ summary: "Top blame vs claim experts for a given client" })
|
||||
@ApiQuery({ name: "clientId", required: true, type: String })
|
||||
getTopExperts(@Query("clientId") clientId: string) {
|
||||
return this.expertInsurerService.getTopExpertsForClient({ clientKey: clientId });
|
||||
return this.expertInsurerService.getTopExpertsForClient({
|
||||
clientKey: clientId,
|
||||
});
|
||||
}
|
||||
|
||||
@Get("insurer/files")
|
||||
@ApiOperation({ summary: "List files (blame + claim merged) for a given client" })
|
||||
@ApiOperation({
|
||||
summary: "List files (blame + claim merged) for a given client",
|
||||
})
|
||||
@ApiQuery({ name: "clientId", required: true, type: String })
|
||||
getAllFiles(
|
||||
@Query("clientId") clientId: string,
|
||||
@@ -388,7 +395,9 @@ export class SuperAdminController {
|
||||
}
|
||||
|
||||
@Get("insurer/report/unified-file-statuses")
|
||||
@ApiOperation({ summary: "Unified file status catalog + counts for a given client" })
|
||||
@ApiOperation({
|
||||
summary: "Unified file status catalog + counts for a given client",
|
||||
})
|
||||
@ApiQuery({ name: "clientId", required: true, type: String })
|
||||
@ApiResponse({ status: 200, type: UnifiedFileStatusReportDto })
|
||||
getUnifiedFileStatusReport(
|
||||
@@ -408,8 +417,16 @@ export class SuperAdminController {
|
||||
description: "Prefer GET insurer/report/unified-file-statuses.",
|
||||
})
|
||||
@ApiQuery({ name: "clientId", required: true, type: String })
|
||||
@ApiQuery({ name: "from", required: false, description: "Optional start datetime (ISO string)" })
|
||||
@ApiQuery({ name: "to", required: false, description: "Optional end datetime (ISO string)" })
|
||||
@ApiQuery({
|
||||
name: "from",
|
||||
required: false,
|
||||
description: "Optional start datetime (ISO string)",
|
||||
})
|
||||
@ApiQuery({
|
||||
name: "to",
|
||||
required: false,
|
||||
description: "Optional end datetime (ISO string)",
|
||||
})
|
||||
getInsurerStatusReport(
|
||||
@Query("clientId") clientId: string,
|
||||
@Query("from") from?: string,
|
||||
@@ -436,20 +453,42 @@ export class SuperAdminController {
|
||||
@Get("insurer/files/:publicId/ai-analysis")
|
||||
@ApiOperation({ summary: "AI analysis for a file of the selected client" })
|
||||
@ApiQuery({ name: "clientId", required: true, type: String })
|
||||
async getAiAnalysis(@Query("clientId") clientId: string, @Param("publicId") publicId: string) {
|
||||
const detail = await this.expertInsurerService.retrieveFileDetailsByPublicId(clientId, publicId);
|
||||
const id = typeof detail.claim?.claimRequestId === "string" ? detail.claim.claimRequestId : undefined;
|
||||
async getAiAnalysis(
|
||||
@Query("clientId") clientId: string,
|
||||
@Param("publicId") publicId: string,
|
||||
) {
|
||||
const detail =
|
||||
await this.expertInsurerService.retrieveFileDetailsByPublicId(
|
||||
clientId,
|
||||
publicId,
|
||||
);
|
||||
const id =
|
||||
typeof detail.claim?.claimRequestId === "string"
|
||||
? detail.claim.claimRequestId
|
||||
: undefined;
|
||||
if (!id) return { enabled: this.aiService.enabled, images: [] };
|
||||
const claim = await this.claimCaseDbService.findById(id);
|
||||
return this.aiService.list(id, currentAiCaptures(claim));
|
||||
}
|
||||
|
||||
@Post("insurer/files/:publicId/ai-analysis/retry")
|
||||
@ApiOperation({ summary: "Retry failed AI analyses for the selected client's file" })
|
||||
@ApiOperation({
|
||||
summary: "Retry failed AI analyses for the selected client's file",
|
||||
})
|
||||
@ApiQuery({ name: "clientId", required: true, type: String })
|
||||
async retryAiAnalysis(@Query("clientId") clientId: string, @Param("publicId") publicId: string) {
|
||||
const detail = await this.expertInsurerService.retrieveFileDetailsByPublicId(clientId, publicId);
|
||||
const id = typeof detail.claim?.claimRequestId === "string" ? detail.claim.claimRequestId : undefined;
|
||||
async retryAiAnalysis(
|
||||
@Query("clientId") clientId: string,
|
||||
@Param("publicId") publicId: string,
|
||||
) {
|
||||
const detail =
|
||||
await this.expertInsurerService.retrieveFileDetailsByPublicId(
|
||||
clientId,
|
||||
publicId,
|
||||
);
|
||||
const id =
|
||||
typeof detail.claim?.claimRequestId === "string"
|
||||
? detail.claim.claimRequestId
|
||||
: undefined;
|
||||
if (!id) return { enabled: this.aiService.enabled, images: [] };
|
||||
const claim = await this.claimCaseDbService.findById(id);
|
||||
return this.aiService.retry(id, currentAiCaptures(claim));
|
||||
@@ -463,7 +502,10 @@ export class SuperAdminController {
|
||||
@Query("clientId") clientId: string,
|
||||
@Param("publicId") publicId: string,
|
||||
) {
|
||||
return this.expertInsurerService.retrieveFileDetailsByPublicId(clientId, publicId);
|
||||
return this.expertInsurerService.retrieveFileDetailsByPublicId(
|
||||
clientId,
|
||||
publicId,
|
||||
);
|
||||
}
|
||||
|
||||
// @Put("insurer/files/:publicId/rating")
|
||||
@@ -509,11 +551,15 @@ export class SuperAdminController {
|
||||
@ApiOperation({ summary: "Expert statistics report for a given client" })
|
||||
@ApiQuery({ name: "clientId", required: true, type: String })
|
||||
getExpertStatistics(@Query("clientId") clientId: string) {
|
||||
return this.expertInsurerService.getExpertStatisticsReport({ clientKey: clientId });
|
||||
return this.expertInsurerService.getExpertStatisticsReport({
|
||||
clientKey: clientId,
|
||||
});
|
||||
}
|
||||
|
||||
@Get("insurer/:expertId")
|
||||
@ApiOperation({ summary: "Files handled by one roster expert for a given client" })
|
||||
@ApiOperation({
|
||||
summary: "Files handled by one roster expert for a given client",
|
||||
})
|
||||
@ApiParam({ name: "expertId" })
|
||||
@ApiQuery({ name: "clientId", required: true, type: String })
|
||||
getExpertFiles(
|
||||
@@ -523,6 +569,9 @@ export class SuperAdminController {
|
||||
if (!Types.ObjectId.isValid(expertId)) {
|
||||
throw new BadRequestException("Invalid expert ID");
|
||||
}
|
||||
return this.expertInsurerService.getAllFilesForInsurerExpert(expertId, clientId);
|
||||
return this.expertInsurerService.getAllFilesForInsurerExpert(
|
||||
expertId,
|
||||
clientId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,20 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
ConflictException,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from "@nestjs/common";
|
||||
import { ConflictException, Injectable } from "@nestjs/common";
|
||||
import { Types } from "mongoose";
|
||||
import { HashService } from "src/utils/hash/hash.service";
|
||||
import { ActorAuthService } from "src/auth/auth-services/actor.auth.service";
|
||||
import { InsurerRegisterDto } from "src/auth/dto/actor/register.actor.dto";
|
||||
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 { RoleEnum } from "src/Types&Enums/role.enum";
|
||||
import { CallCenterAgentDbService } from "src/users/entities/db-service/call-center-agent.db.service";
|
||||
|
||||
import { HashService } from "src/utils/hash/hash.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,
|
||||
CreateCallCenterAgentDto,
|
||||
CreateFieldExpertAdminDto,
|
||||
CreateRegistrarAdminDto,
|
||||
CreateCallCenterAgentDto,
|
||||
CreateSuperAdminDto,
|
||||
} 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 { CallCenterAgentDbService } from "src/users/entities/db-service/call-center-agent.db.service";
|
||||
import { SuperAdminDbService } from "./entities/db-service/super-admin.db.service";
|
||||
|
||||
@Injectable()
|
||||
export class SuperAdminService {
|
||||
@@ -33,8 +23,7 @@ export class SuperAdminService {
|
||||
private readonly hashService: HashService,
|
||||
private readonly clientService: ClientService,
|
||||
private readonly actorAuthService: ActorAuthService,
|
||||
private readonly fieldExpertDbService: FieldExpertDbService,
|
||||
private readonly registrarDbService: RegistrarDbService,
|
||||
|
||||
private readonly callCenterAgentDbService: CallCenterAgentDbService,
|
||||
) {}
|
||||
|
||||
@@ -87,14 +76,6 @@ export class SuperAdminService {
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user