forked from Yara724/api
daghi problem fixed , 2 apis for reporting counts added
This commit is contained in:
@@ -12,6 +12,10 @@ import {
|
||||
blameCaseAccessibleToExpert,
|
||||
requireActorClientKey,
|
||||
} from "src/helpers/tenant-scope";
|
||||
import {
|
||||
blameCaseStatusToReportBucket,
|
||||
initialBlameExpertReportBuckets,
|
||||
} from "src/helpers/expert-panel-status-report";
|
||||
import { RequestManagementDbService } from "src/request-management/entities/db-service/request-management.db.service";
|
||||
import { BlameRequestDbService } from "src/request-management/entities/db-service/blame-request.db.service";
|
||||
import {
|
||||
@@ -205,6 +209,38 @@ export class ExpertBlameService {
|
||||
* 2. Requests where current expert made the decision
|
||||
* Does NOT show requests decided by other experts.
|
||||
*/
|
||||
/**
|
||||
* V2: Count blame cases for this expert’s tenant, grouped for dashboard:
|
||||
* `IN_PROGRESS` = OPEN + WAITING_FOR_SECOND_PARTY; other {@link CaseStatus} keys unchanged.
|
||||
*/
|
||||
async getStatusReportBucketsV2(actor: any): Promise<Record<string, number>> {
|
||||
requireActorClientKey(actor);
|
||||
const rows = await this.blameRequestDbService.find({}, { lean: true });
|
||||
const buckets = initialBlameExpertReportBuckets();
|
||||
for (const doc of rows as Record<string, unknown>[]) {
|
||||
if (!this.blameDocIncludedInExpertTenantReport(doc, actor)) continue;
|
||||
const st = String(doc.status ?? "");
|
||||
const key = blameCaseStatusToReportBucket(st);
|
||||
buckets.all++;
|
||||
buckets[key] = (buckets[key] ?? 0) + 1;
|
||||
}
|
||||
return buckets;
|
||||
}
|
||||
|
||||
/** Tenant + expert-initiated visibility (same as list, without queue filters). */
|
||||
private blameDocIncludedInExpertTenantReport(
|
||||
doc: Record<string, unknown>,
|
||||
actor: { sub: string; clientKey?: string },
|
||||
): boolean {
|
||||
if (!blameCaseAccessibleToExpert(doc, actor)) {
|
||||
return false;
|
||||
}
|
||||
if (doc.expertInitiated && doc.initiatedByFieldExpertId) {
|
||||
return String(doc.initiatedByFieldExpertId) === String(actor.sub);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
async findAllV2(actor: any): Promise<AllRequestDtoRsV2> {
|
||||
try {
|
||||
requireActorClientKey(actor);
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
Put,
|
||||
UseGuards,
|
||||
} from "@nestjs/common";
|
||||
import { ApiBearerAuth, ApiBody, ApiParam, ApiTags } from "@nestjs/swagger";
|
||||
import { ApiBearerAuth, ApiBody, ApiOperation, ApiParam, ApiTags } from "@nestjs/swagger";
|
||||
import { LocalActorAuthGuard } from "src/auth/guards/actor-local.guard";
|
||||
import { RolesGuard } from "src/auth/guards/role.guard";
|
||||
import { Roles } from "src/decorators/roles.decorator";
|
||||
@@ -38,6 +38,23 @@ export class ExpertBlameV2Controller {
|
||||
}
|
||||
}
|
||||
|
||||
@Get("report/status-counts")
|
||||
@ApiOperation({
|
||||
summary: "Count blame cases by grouped status bucket (tenant)",
|
||||
description:
|
||||
"IN_PROGRESS groups OPEN and WAITING_FOR_SECOND_PARTY. WAITING_FOR_EXPERT, WAITING_FOR_DOCUMENT_RESEND, WAITING_FOR_SIGNATURES, and terminal statuses are counted separately. Expert-initiated files count only for the initiating expert.",
|
||||
})
|
||||
async getStatusReportBucketsV2(@CurrentUser() actor: any) {
|
||||
try {
|
||||
return await this.expertBlameService.getStatusReportBucketsV2(actor);
|
||||
} catch (error) {
|
||||
if (error instanceof HttpException) throw error;
|
||||
throw new InternalServerErrorException(
|
||||
error instanceof Error ? error.message : "Failed to load blame status report",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Get(":id")
|
||||
@ApiParam({ name: "id", description: "Blame case request id" })
|
||||
async findOne(@Param("id") id: string, @CurrentUser() actor: any) {
|
||||
|
||||
Reference in New Issue
Block a user