forked from Yara724/api
Fix searching on GET APIs
This commit is contained in:
@@ -141,7 +141,15 @@ import {
|
||||
/** Maximum sum of line `totalPayment` across the claim (Toman; priced parts + factor lines after validation). */
|
||||
import { getClaimV2TotalPaymentCapToman } from "src/constants/repair-amount-limits";
|
||||
import { ListQueryV2Dto } from "src/common/dto/list-query-v2.dto";
|
||||
import { applyListQueryV2 } from "src/helpers/list-query-v2";
|
||||
import {
|
||||
UnifiedFileStatusReportDto,
|
||||
UnifiedFileStatusReportQueryDto,
|
||||
} from "src/common/dto/unified-file-status-report.dto";
|
||||
import {
|
||||
applyListQueryV2,
|
||||
isInListDateRange,
|
||||
parseListDateRange,
|
||||
} from "src/helpers/list-query-v2";
|
||||
import {
|
||||
countUnifiedFileStatuses,
|
||||
getUnifiedFileStatusCatalog,
|
||||
@@ -3416,13 +3424,37 @@ export class ExpertClaimService {
|
||||
return buckets;
|
||||
}
|
||||
|
||||
async getUnifiedFileStatusReportV2(actor: any) {
|
||||
async getUnifiedFileStatusReportV2(
|
||||
actor: any,
|
||||
query: UnifiedFileStatusReportQueryDto = {},
|
||||
): Promise<UnifiedFileStatusReportDto> {
|
||||
const { claims, blameById } =
|
||||
await this.collectClaimPortfolioWithBlame(actor);
|
||||
const { fromDate, toDate } = parseListDateRange(query.from, query.to);
|
||||
const filteredClaims = claims.filter((c) => {
|
||||
if (
|
||||
!isInListDateRange(
|
||||
c.createdAt as Date | string | undefined,
|
||||
fromDate,
|
||||
toDate,
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (!query.fileType) return true;
|
||||
const blame = c.blameRequestId
|
||||
? blameById.get(String(c.blameRequestId))
|
||||
: undefined;
|
||||
const type =
|
||||
blame?.type ??
|
||||
(c as { snapshot?: { accident?: { type?: string } } })?.snapshot
|
||||
?.accident?.type;
|
||||
return type === query.fileType;
|
||||
});
|
||||
return {
|
||||
statuses: getUnifiedFileStatusCatalog(),
|
||||
counts: countUnifiedFileStatuses(
|
||||
claims.map((c) => {
|
||||
filteredClaims.map((c) => {
|
||||
const blame = c.blameRequestId
|
||||
? blameById.get(String(c.blameRequestId))
|
||||
: undefined;
|
||||
@@ -3532,6 +3564,7 @@ export class ExpertClaimService {
|
||||
createdAt: (r) => r.createdAt,
|
||||
requestNo: (r) => r.publicId,
|
||||
status: (r) => r.unifiedFileStatus ?? r.status,
|
||||
fileType: (r) => r.blameRequestType,
|
||||
searchExtras: (r) =>
|
||||
[
|
||||
r.claimRequestId,
|
||||
|
||||
@@ -31,6 +31,10 @@ import { RoleEnum } from "src/Types&Enums/role.enum";
|
||||
import { ExpertFileAssignResultDto } from "src/common/dto/expert-file-assign-result.dto";
|
||||
import { ExpertClaimService } from "./expert-claim.service";
|
||||
import { ListQueryV2Dto } from "src/common/dto/list-query-v2.dto";
|
||||
import {
|
||||
UnifiedFileStatusReportDto,
|
||||
UnifiedFileStatusReportQueryDto,
|
||||
} from "src/common/dto/unified-file-status-report.dto";
|
||||
import { GetClaimListV2ResponseDto } from "./dto/claim-list-v2.dto";
|
||||
import {
|
||||
ClaimSubmitResendV2Dto,
|
||||
@@ -69,10 +73,17 @@ export class ExpertClaimV2Controller {
|
||||
@ApiOperation({
|
||||
summary: "Unified file status catalog + counts (claim + linked blame)",
|
||||
description:
|
||||
"Calculatable statuses for this expert's claim portfolio. Filter lists with `unifiedStatus` query param.",
|
||||
"Calculatable statuses for this expert's claim portfolio. Filter lists with `unifiedStatus` and `fileType` query params. Optional `from` / `to` ISO dates narrow the counted portfolio.",
|
||||
})
|
||||
async getUnifiedFileStatusReportV2(@CurrentUser() actor: any) {
|
||||
return await this.expertClaimService.getUnifiedFileStatusReportV2(actor);
|
||||
@ApiResponse({ status: 200, type: UnifiedFileStatusReportDto })
|
||||
async getUnifiedFileStatusReportV2(
|
||||
@CurrentUser() actor: any,
|
||||
@Query() query: UnifiedFileStatusReportQueryDto,
|
||||
): Promise<UnifiedFileStatusReportDto> {
|
||||
return await this.expertClaimService.getUnifiedFileStatusReportV2(
|
||||
actor,
|
||||
query,
|
||||
);
|
||||
}
|
||||
|
||||
@Get("report/status-counts")
|
||||
@@ -127,7 +138,8 @@ export class ExpertClaimV2Controller {
|
||||
summary: "List available claim requests for damage expert",
|
||||
description:
|
||||
"Damage experts: tenant queue (`WAITING_FOR_DAMAGE_EXPERT`), locked/in-progress, factor validation. " +
|
||||
"Field experts: all claims linked to blame files they initiated (`initiatedByFieldExpertId` or matching `blameRequestId`). Optional query: `search`, `sortBy`, `sortOrder`, `page`, `limit`, `unifiedStatus`.",
|
||||
"Field experts: all claims linked to blame files they initiated (`initiatedByFieldExpertId` or matching `blameRequestId`). " +
|
||||
"Optional query: `search`, `sortBy`, `sortOrder`, `page`, `limit`, `unifiedStatus`, `fileType` (THIRD_PARTY | CAR_BODY).",
|
||||
})
|
||||
@ApiResponse({ status: 200, type: GetClaimListV2ResponseDto })
|
||||
async getClaimListV2(
|
||||
|
||||
Reference in New Issue
Block a user