forked from Yara724/api
YARA-854
This commit is contained in:
@@ -1,29 +1,38 @@
|
|||||||
/**
|
/**
|
||||||
* Native workflow status keys from blameCases (`CaseStatus`) or claimCases (`ClaimCaseStatus`),
|
* V2-style status buckets (`IN_PROGRESS` + native statuses) for insurer tenant scope.
|
||||||
* plus `all` = total matching documents for the tenant.
|
* `unifiedByPublicId.total` matches merging blame + claim by `publicId` (see insurer `files` API).
|
||||||
*/
|
*/
|
||||||
export class BlameCaseStatusCountReportDtoRs {
|
export class InsurerRequestsSummaryDtoRs {
|
||||||
[key: string]: number;
|
|
||||||
|
|
||||||
constructor(report: Record<string, number>) {
|
|
||||||
Object.assign(this, report);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ClaimCaseStatusCountReportDtoRs {
|
|
||||||
[key: string]: number;
|
|
||||||
|
|
||||||
constructor(report: Record<string, number>) {
|
|
||||||
Object.assign(this, report);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CompanyAllRequestsCountReportDtoRs {
|
|
||||||
blame: Record<string, number>;
|
|
||||||
claim: Record<string, number>;
|
claim: Record<string, number>;
|
||||||
|
blame: Record<string, number>;
|
||||||
|
unifiedByPublicId: { total: number };
|
||||||
|
|
||||||
constructor(blame: Record<string, number>, claim: Record<string, number>) {
|
constructor(
|
||||||
this.blame = blame;
|
claim: Record<string, number>,
|
||||||
|
blame: Record<string, number>,
|
||||||
|
unifiedTotal: number,
|
||||||
|
) {
|
||||||
this.claim = claim;
|
this.claim = claim;
|
||||||
|
this.blame = blame;
|
||||||
|
this.unifiedByPublicId = { total: unifiedTotal };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class InsurerPerMonthReportRowDtoRs {
|
||||||
|
stDate: Date;
|
||||||
|
enDate: Date;
|
||||||
|
faLabel: string;
|
||||||
|
data: InsurerRequestsSummaryDtoRs;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
stDate: Date,
|
||||||
|
enDate: Date,
|
||||||
|
faLabel: string,
|
||||||
|
data: InsurerRequestsSummaryDtoRs,
|
||||||
|
) {
|
||||||
|
this.stDate = stDate;
|
||||||
|
this.enDate = enDate;
|
||||||
|
this.faLabel = faLabel;
|
||||||
|
this.data = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import { Controller, Get, UseGuards } from "@nestjs/common";
|
import { Controller, Get, Query, UseGuards } from "@nestjs/common";
|
||||||
import { ApiBearerAuth, ApiTags } from "@nestjs/swagger";
|
import {
|
||||||
|
ApiBearerAuth,
|
||||||
|
ApiOperation,
|
||||||
|
ApiQuery,
|
||||||
|
ApiTags,
|
||||||
|
} from "@nestjs/swagger";
|
||||||
import { LocalActorAuthGuard } from "src/auth/guards/actor-local.guard";
|
import { LocalActorAuthGuard } from "src/auth/guards/actor-local.guard";
|
||||||
import { RolesGuard } from "src/auth/guards/role.guard";
|
import { RolesGuard } from "src/auth/guards/role.guard";
|
||||||
import { ClientKey } from "src/decorators/clientKey.decorator";
|
|
||||||
import { Roles } from "src/decorators/roles.decorator";
|
import { Roles } from "src/decorators/roles.decorator";
|
||||||
import { CurrentUser } from "src/decorators/user.decorator";
|
import { CurrentUser } from "src/decorators/user.decorator";
|
||||||
import { RoleEnum } from "src/Types&Enums/role.enum";
|
import { RoleEnum } from "src/Types&Enums/role.enum";
|
||||||
@@ -11,29 +15,56 @@ import { ReportsService } from "./reports.service";
|
|||||||
@ApiTags("reports")
|
@ApiTags("reports")
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(LocalActorAuthGuard, RolesGuard)
|
@UseGuards(LocalActorAuthGuard, RolesGuard)
|
||||||
@Roles(RoleEnum.DAMAGE_EXPERT, RoleEnum.EXPERT, RoleEnum.COMPANY)
|
@Roles(RoleEnum.COMPANY)
|
||||||
@Controller("reports")
|
@Controller("reports")
|
||||||
export class ReportsController {
|
export class ReportsController {
|
||||||
constructor(private readonly reportsService: ReportsService) {}
|
constructor(private readonly reportsService: ReportsService) {}
|
||||||
|
|
||||||
@Get("/report/requests")
|
@Get("report/insurer/requests")
|
||||||
async getAllRequestsReport(@CurrentUser() actor, @ClientKey() client) {
|
@ApiOperation({
|
||||||
return await this.reportsService.getAllRequestsReportCount(actor, client);
|
summary: "Insurer: claim/blame status buckets + unified file count",
|
||||||
|
description:
|
||||||
|
"Claim and blame counts use the same V2 bucket rules as expert panels (IN_PROGRESS grouping), scoped to the insurer JWT tenant. unifiedByPublicId.total counts distinct publicId values like GET expert-insurer/files.",
|
||||||
|
})
|
||||||
|
async getInsurerRequestsSummary(@CurrentUser() actor) {
|
||||||
|
return await this.reportsService.getInsurerRequestsSummary(actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("/report/perMonthRequests")
|
@Get("report/insurer/per-month-requests")
|
||||||
async getAllRequestsReportPerMonth(
|
@ApiOperation({
|
||||||
|
summary: "Insurer: same summary as report/insurer/requests, per calendar month",
|
||||||
|
description:
|
||||||
|
"Last five calendar months; each slice filters blame/claim rows by createdAt in that month, then claim buckets, blame buckets, and unified publicId count.",
|
||||||
|
})
|
||||||
|
async getInsurerRequestsSummaryPerMonth(@CurrentUser() actor) {
|
||||||
|
return await this.reportsService.getInsurerRequestsSummaryPerMonth(actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("report/insurer/checked-requests")
|
||||||
|
@ApiOperation({
|
||||||
|
summary: "Insurer: summary filtered by optional createdAt range",
|
||||||
|
description:
|
||||||
|
"Same payload as report/insurer/requests. When from/to are omitted, all tenant files are included. When provided, only blame/claim rows whose createdAt falls in the range are counted (inclusive).",
|
||||||
|
})
|
||||||
|
@ApiQuery({
|
||||||
|
name: "from",
|
||||||
|
required: false,
|
||||||
|
description: "Optional start datetime (ISO string)",
|
||||||
|
})
|
||||||
|
@ApiQuery({
|
||||||
|
name: "to",
|
||||||
|
required: false,
|
||||||
|
description: "Optional end datetime (ISO string)",
|
||||||
|
})
|
||||||
|
async getInsurerRequestsSummaryByDateRange(
|
||||||
@CurrentUser() actor,
|
@CurrentUser() actor,
|
||||||
@ClientKey() client,
|
@Query("from") from?: string,
|
||||||
|
@Query("to") to?: string,
|
||||||
) {
|
) {
|
||||||
return await this.reportsService.getAllRequestsReportPerMonth(
|
return await this.reportsService.getInsurerRequestsSummaryByDateRange(
|
||||||
actor,
|
actor,
|
||||||
client,
|
from,
|
||||||
|
to,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("/report/checkedRequests")
|
|
||||||
async getAllCheckedRequestsCount(@CurrentUser() actor, @ClientKey() client) {
|
|
||||||
return await this.reportsService.getAllCheckedRequestsCount(actor, client);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||||
import { Types } from "mongoose";
|
|
||||||
import { ClaimCaseDbService } from "src/claim-request-management/entites/db-service/claim-case.db.service";
|
import { ClaimCaseDbService } from "src/claim-request-management/entites/db-service/claim-case.db.service";
|
||||||
import { BlameRequestDbService } from "src/request-management/entities/db-service/blame-request.db.service";
|
|
||||||
import { CaseStatus } from "src/Types&Enums/blame-request-management/caseStatus.enum";
|
|
||||||
import { ClaimCaseStatus } from "src/Types&Enums/claim-request-management/claim-case-status.enum";
|
|
||||||
import { requireActorClientKey } from "src/helpers/tenant-scope";
|
|
||||||
import {
|
import {
|
||||||
BlameCaseStatusCountReportDtoRs,
|
blameCaseStatusToReportBucket,
|
||||||
ClaimCaseStatusCountReportDtoRs,
|
claimCaseStatusToReportBucket,
|
||||||
CompanyAllRequestsCountReportDtoRs,
|
initialBlameExpertReportBuckets,
|
||||||
|
initialClaimExpertReportBuckets,
|
||||||
|
} from "src/helpers/expert-panel-status-report";
|
||||||
|
import {
|
||||||
|
blameCaseTouchesClient,
|
||||||
|
claimCaseTouchesClient,
|
||||||
|
requireActorClientKey,
|
||||||
|
} from "src/helpers/tenant-scope";
|
||||||
|
import { BlameRequestDbService } from "src/request-management/entities/db-service/blame-request.db.service";
|
||||||
|
import {
|
||||||
|
InsurerPerMonthReportRowDtoRs,
|
||||||
|
InsurerRequestsSummaryDtoRs,
|
||||||
} from "./dto/reports.dto";
|
} from "./dto/reports.dto";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -18,180 +24,158 @@ export class ReportsService {
|
|||||||
private readonly claimCaseDbService: ClaimCaseDbService,
|
private readonly claimCaseDbService: ClaimCaseDbService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
private clientObjectId(client: string | undefined): Types.ObjectId {
|
private parseDateRange(from?: string, to?: string) {
|
||||||
const ck = requireActorClientKey({ clientKey: client });
|
const fromDate = from ? new Date(from) : undefined;
|
||||||
return new Types.ObjectId(ck);
|
const toDate = to ? new Date(to) : undefined;
|
||||||
|
|
||||||
|
if (fromDate && Number.isNaN(fromDate.getTime())) {
|
||||||
|
throw new BadRequestException("Invalid 'from' date");
|
||||||
|
}
|
||||||
|
if (toDate && Number.isNaN(toDate.getTime())) {
|
||||||
|
throw new BadRequestException("Invalid 'to' date");
|
||||||
|
}
|
||||||
|
if (fromDate && toDate && fromDate > toDate) {
|
||||||
|
throw new BadRequestException("'from' must be before or equal to 'to'");
|
||||||
|
}
|
||||||
|
return { fromDate, toDate };
|
||||||
}
|
}
|
||||||
|
|
||||||
private isBlameForClient(r: any, client: Types.ObjectId): boolean {
|
private isInDateRange(
|
||||||
const idStr = String(client);
|
value: unknown,
|
||||||
return (r?.parties || []).some(
|
fromDate?: Date,
|
||||||
(p) => String(p?.person?.clientId || "") === idStr,
|
toDate?: Date,
|
||||||
);
|
): boolean {
|
||||||
|
if (!fromDate && !toDate) return true;
|
||||||
|
if (!value) return false;
|
||||||
|
const d = new Date(value as string | Date);
|
||||||
|
if (Number.isNaN(d.getTime())) return false;
|
||||||
|
if (fromDate && d < fromDate) return false;
|
||||||
|
if (toDate && d > toDate) return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private isClaimForClient(r: any, client: Types.ObjectId): boolean {
|
private publicIdKey(doc: Record<string, unknown>): string {
|
||||||
return String(r?.owner?.userClientKey || "") === String(client);
|
return String(doc.publicId ?? doc._id ?? "");
|
||||||
}
|
}
|
||||||
|
|
||||||
private countBlameByCaseStatus(
|
private buildClaimBucketsForInsurer(
|
||||||
blames: any[],
|
rows: Record<string, unknown>[],
|
||||||
clientId: Types.ObjectId,
|
clientKey: string,
|
||||||
|
dateFrom?: Date,
|
||||||
|
dateTo?: Date,
|
||||||
): Record<string, number> {
|
): Record<string, number> {
|
||||||
const out: Record<string, number> = { all: 0 };
|
const buckets = initialClaimExpertReportBuckets();
|
||||||
for (const s of Object.values(CaseStatus)) {
|
for (const doc of rows) {
|
||||||
out[s] = 0;
|
if (!claimCaseTouchesClient(doc, clientKey)) continue;
|
||||||
|
if (!this.isInDateRange(doc.createdAt, dateFrom, dateTo)) continue;
|
||||||
|
const st = String(doc.status ?? "");
|
||||||
|
const key = claimCaseStatusToReportBucket(st);
|
||||||
|
buckets.all++;
|
||||||
|
buckets[key] = (buckets[key] ?? 0) + 1;
|
||||||
}
|
}
|
||||||
for (const r of blames) {
|
return buckets;
|
||||||
if (!this.isBlameForClient(r, clientId)) continue;
|
|
||||||
const st = r?.status as string;
|
|
||||||
if (st in out) out[st]++;
|
|
||||||
else out[st] = (out[st] ?? 0) + 1;
|
|
||||||
out.all++;
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private countClaimByCaseStatus(
|
private buildBlameBucketsForInsurer(
|
||||||
claims: any[],
|
rows: Record<string, unknown>[],
|
||||||
clientId: Types.ObjectId,
|
clientKey: string,
|
||||||
|
dateFrom?: Date,
|
||||||
|
dateTo?: Date,
|
||||||
): Record<string, number> {
|
): Record<string, number> {
|
||||||
const out: Record<string, number> = { all: 0 };
|
const buckets = initialBlameExpertReportBuckets();
|
||||||
for (const s of Object.values(ClaimCaseStatus)) {
|
for (const doc of rows) {
|
||||||
out[s] = 0;
|
if (!blameCaseTouchesClient(doc, clientKey)) continue;
|
||||||
|
if (!this.isInDateRange(doc.createdAt, dateFrom, dateTo)) continue;
|
||||||
|
const st = String(doc.status ?? "");
|
||||||
|
const key = blameCaseStatusToReportBucket(st);
|
||||||
|
buckets.all++;
|
||||||
|
buckets[key] = (buckets[key] ?? 0) + 1;
|
||||||
}
|
}
|
||||||
for (const r of claims) {
|
return buckets;
|
||||||
if (!this.isClaimForClient(r, clientId)) continue;
|
|
||||||
const st = r?.status as string;
|
|
||||||
if (st in out) out[st]++;
|
|
||||||
else out[st] = (out[st] ?? 0) + 1;
|
|
||||||
out.all++;
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getAllRequestsCountByRole(role: string, client: string | undefined) {
|
|
||||||
const clientId = this.clientObjectId(client);
|
|
||||||
const [blames, claims] = await Promise.all([
|
|
||||||
this.blameRequestDbService.find({}, { lean: true }),
|
|
||||||
this.claimCaseDbService.find({}, { lean: true }),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (role === "expert") {
|
|
||||||
return this.countBlameByCaseStatus(blames as any[], clientId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (role === "damage_expert") {
|
|
||||||
return this.countClaimByCaseStatus(claims as any[], clientId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (role === "company") {
|
|
||||||
return {
|
|
||||||
blame: this.countBlameByCaseStatus(blames as any[], clientId),
|
|
||||||
claim: this.countClaimByCaseStatus(claims as any[], clientId),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Per calendar month, counts by native `CaseStatus` / `ClaimCaseStatus`.
|
* One insurer “file” per `publicId`, aligned with `ExpertInsurerService.retrieveAllFilesOfClient`.
|
||||||
* Company gets both blame and claim maps; expert / damage_expert get one map.
|
|
||||||
*/
|
*/
|
||||||
async getDateFilteredRequestByStatus(
|
private countUnifiedByPublicId(
|
||||||
role: string,
|
blameRows: Record<string, unknown>[],
|
||||||
client: string | undefined,
|
claimRows: Record<string, unknown>[],
|
||||||
start: Date,
|
clientKey: string,
|
||||||
end: Date,
|
dateFrom?: Date,
|
||||||
) {
|
dateTo?: Date,
|
||||||
const clientId = this.clientObjectId(client);
|
): number {
|
||||||
|
const keys = new Set<string>();
|
||||||
|
for (const doc of blameRows) {
|
||||||
|
if (!blameCaseTouchesClient(doc, clientKey)) continue;
|
||||||
|
if (!this.isInDateRange(doc.createdAt, dateFrom, dateTo)) continue;
|
||||||
|
const k = this.publicIdKey(doc);
|
||||||
|
if (k) keys.add(k);
|
||||||
|
}
|
||||||
|
for (const doc of claimRows) {
|
||||||
|
if (!claimCaseTouchesClient(doc, clientKey)) continue;
|
||||||
|
if (!this.isInDateRange(doc.createdAt, dateFrom, dateTo)) continue;
|
||||||
|
const k = this.publicIdKey(doc);
|
||||||
|
if (k) keys.add(k);
|
||||||
|
}
|
||||||
|
return keys.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildInsurerSummary(
|
||||||
|
blames: Record<string, unknown>[],
|
||||||
|
claims: Record<string, unknown>[],
|
||||||
|
clientKey: string,
|
||||||
|
dateFrom?: Date,
|
||||||
|
dateTo?: Date,
|
||||||
|
): InsurerRequestsSummaryDtoRs {
|
||||||
|
const claim = this.buildClaimBucketsForInsurer(
|
||||||
|
claims,
|
||||||
|
clientKey,
|
||||||
|
dateFrom,
|
||||||
|
dateTo,
|
||||||
|
);
|
||||||
|
const blame = this.buildBlameBucketsForInsurer(
|
||||||
|
blames,
|
||||||
|
clientKey,
|
||||||
|
dateFrom,
|
||||||
|
dateTo,
|
||||||
|
);
|
||||||
|
const unifiedTotal = this.countUnifiedByPublicId(
|
||||||
|
blames,
|
||||||
|
claims,
|
||||||
|
clientKey,
|
||||||
|
dateFrom,
|
||||||
|
dateTo,
|
||||||
|
);
|
||||||
|
return new InsurerRequestsSummaryDtoRs(claim, blame, unifiedTotal);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getInsurerRequestsSummary(actor: {
|
||||||
|
clientKey?: string;
|
||||||
|
}): Promise<InsurerRequestsSummaryDtoRs> {
|
||||||
|
const clientKey = requireActorClientKey(actor);
|
||||||
const [blames, claims] = await Promise.all([
|
const [blames, claims] = await Promise.all([
|
||||||
this.blameRequestDbService.find({}, { lean: true }),
|
this.blameRequestDbService.find({}, { lean: true }),
|
||||||
this.claimCaseDbService.find({}, { lean: true }),
|
this.claimCaseDbService.find({}, { lean: true }),
|
||||||
]);
|
]);
|
||||||
|
return this.buildInsurerSummary(
|
||||||
const inRange = (r: any) => {
|
blames as Record<string, unknown>[],
|
||||||
const createdAt = new Date(r.createdAt);
|
claims as Record<string, unknown>[],
|
||||||
return createdAt >= start && createdAt <= end;
|
clientKey,
|
||||||
};
|
|
||||||
|
|
||||||
if (role === "company") {
|
|
||||||
const blameOut: Record<string, number> = { all: 0 };
|
|
||||||
const claimOut: Record<string, number> = { all: 0 };
|
|
||||||
for (const s of Object.values(CaseStatus)) blameOut[s] = 0;
|
|
||||||
for (const s of Object.values(ClaimCaseStatus)) claimOut[s] = 0;
|
|
||||||
|
|
||||||
for (const r of blames as any[]) {
|
|
||||||
if (!this.isBlameForClient(r, clientId) || !inRange(r)) continue;
|
|
||||||
const st = r?.status as string;
|
|
||||||
if (st in blameOut) blameOut[st]++;
|
|
||||||
else blameOut[st] = (blameOut[st] ?? 0) + 1;
|
|
||||||
blameOut.all++;
|
|
||||||
}
|
|
||||||
for (const r of claims as any[]) {
|
|
||||||
if (!this.isClaimForClient(r, clientId) || !inRange(r)) continue;
|
|
||||||
const st = r?.status as string;
|
|
||||||
if (st in claimOut) claimOut[st]++;
|
|
||||||
else claimOut[st] = (claimOut[st] ?? 0) + 1;
|
|
||||||
claimOut.all++;
|
|
||||||
}
|
|
||||||
return { blame: blameOut, claim: claimOut };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (role === "expert") {
|
|
||||||
const out: Record<string, number> = { all: 0 };
|
|
||||||
for (const s of Object.values(CaseStatus)) out[s] = 0;
|
|
||||||
for (const r of blames as any[]) {
|
|
||||||
if (!this.isBlameForClient(r, clientId) || !inRange(r)) continue;
|
|
||||||
const st = r?.status as string;
|
|
||||||
if (st in out) out[st]++;
|
|
||||||
else out[st] = (out[st] ?? 0) + 1;
|
|
||||||
out.all++;
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (role === "damage_expert") {
|
|
||||||
const out: Record<string, number> = { all: 0 };
|
|
||||||
for (const s of Object.values(ClaimCaseStatus)) out[s] = 0;
|
|
||||||
for (const r of claims as any[]) {
|
|
||||||
if (!this.isClaimForClient(r, clientId) || !inRange(r)) continue;
|
|
||||||
const st = r?.status as string;
|
|
||||||
if (st in out) out[st]++;
|
|
||||||
else out[st] = (out[st] ?? 0) + 1;
|
|
||||||
out.all++;
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new BadRequestException("Unsupported role for reports");
|
|
||||||
}
|
|
||||||
|
|
||||||
async getAllRequestsReportCount(actor: any, client: string | undefined) {
|
|
||||||
requireActorClientKey(actor);
|
|
||||||
|
|
||||||
if (actor.role === "damage_expert") {
|
|
||||||
const data = await this.getAllRequestsCountByRole(actor.role, client);
|
|
||||||
return new ClaimCaseStatusCountReportDtoRs(data as Record<string, number>);
|
|
||||||
}
|
|
||||||
if (actor.role === "expert") {
|
|
||||||
const data = await this.getAllRequestsCountByRole(actor.role, client);
|
|
||||||
return new BlameCaseStatusCountReportDtoRs(data as Record<string, number>);
|
|
||||||
}
|
|
||||||
const companyPayload = await this.getAllRequestsCountByRole(
|
|
||||||
"company",
|
|
||||||
client,
|
|
||||||
);
|
|
||||||
return new CompanyAllRequestsCountReportDtoRs(
|
|
||||||
(companyPayload as { blame: Record<string, number> }).blame,
|
|
||||||
(companyPayload as { claim: Record<string, number> }).claim,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllRequestsReportPerMonth(actor: any, client: string | undefined) {
|
async getInsurerRequestsSummaryPerMonth(actor: {
|
||||||
requireActorClientKey(actor);
|
clientKey?: string;
|
||||||
const result: any[] = [];
|
}): Promise<InsurerPerMonthReportRowDtoRs[]> {
|
||||||
|
const clientKey = requireActorClientKey(actor);
|
||||||
|
const [blames, claims] = await Promise.all([
|
||||||
|
this.blameRequestDbService.find({}, { lean: true }),
|
||||||
|
this.claimCaseDbService.find({}, { lean: true }),
|
||||||
|
]);
|
||||||
|
const blameRows = blames as Record<string, unknown>[];
|
||||||
|
const claimRows = claims as Record<string, unknown>[];
|
||||||
|
|
||||||
|
const result: InsurerPerMonthReportRowDtoRs[] = [];
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
for (let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
@@ -209,35 +193,39 @@ export class ReportsService {
|
|||||||
year: "numeric",
|
year: "numeric",
|
||||||
});
|
});
|
||||||
|
|
||||||
let data: any;
|
const data = this.buildInsurerSummary(
|
||||||
if (actor.role === "company") {
|
blameRows,
|
||||||
data = await this.getDateFilteredRequestByStatus(
|
claimRows,
|
||||||
"company",
|
clientKey,
|
||||||
client,
|
|
||||||
monthStart,
|
monthStart,
|
||||||
monthEnd,
|
monthEnd,
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
data = await this.getDateFilteredRequestByStatus(
|
|
||||||
actor.role,
|
|
||||||
client,
|
|
||||||
monthStart,
|
|
||||||
monthEnd,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
result.unshift({
|
result.unshift(
|
||||||
stDate: monthStart,
|
new InsurerPerMonthReportRowDtoRs(monthStart, monthEnd, label, data),
|
||||||
enDate: monthEnd,
|
);
|
||||||
faLabel: label,
|
|
||||||
data,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Same aggregates as `GET /reports/report/requests` (native status keys). */
|
async getInsurerRequestsSummaryByDateRange(
|
||||||
async getAllCheckedRequestsCount(actor: any, client: string | undefined) {
|
actor: { clientKey?: string },
|
||||||
return this.getAllRequestsReportCount(actor, client);
|
from?: string,
|
||||||
|
to?: string,
|
||||||
|
): Promise<InsurerRequestsSummaryDtoRs> {
|
||||||
|
const clientKey = requireActorClientKey(actor);
|
||||||
|
const { fromDate, toDate } = this.parseDateRange(from, to);
|
||||||
|
|
||||||
|
const [blames, claims] = await Promise.all([
|
||||||
|
this.blameRequestDbService.find({}, { lean: true }),
|
||||||
|
this.claimCaseDbService.find({}, { lean: true }),
|
||||||
|
]);
|
||||||
|
return this.buildInsurerSummary(
|
||||||
|
blames as Record<string, unknown>[],
|
||||||
|
claims as Record<string, unknown>[],
|
||||||
|
clientKey,
|
||||||
|
fromDate,
|
||||||
|
toDate,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user