forked from Yara724/api
Fix searching on GET APIs
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
ApiOperation,
|
||||
ApiParam,
|
||||
ApiQuery,
|
||||
ApiResponse,
|
||||
ApiTags,
|
||||
} from "@nestjs/swagger";
|
||||
import { Types } from "mongoose";
|
||||
@@ -27,6 +28,10 @@ import { FileRating } from "src/request-management/entities/schema/request-manag
|
||||
import { RoleEnum } from "src/Types&Enums/role.enum";
|
||||
import { ExpertInsurerService } from "./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 {
|
||||
CreateBlameExpertByInsurerDto,
|
||||
@@ -166,7 +171,7 @@ export class ExpertInsurerController {
|
||||
@ApiOperation({
|
||||
summary: "List insurer files (blame + claim merged by publicId)",
|
||||
description:
|
||||
"Optional query: `search`, `sortBy` (publicId | createdAt | requestNo | status), `sortOrder`, `page`, `limit`, `unifiedStatus`.",
|
||||
"Optional query: `search`, `sortBy` (publicId | createdAt | requestNo | status), `sortOrder`, `page`, `limit`, `unifiedStatus`, `fileType` (THIRD_PARTY | CAR_BODY).",
|
||||
})
|
||||
async getAllFiles(
|
||||
@CurrentUser() insurer,
|
||||
@@ -182,27 +187,16 @@ export class ExpertInsurerController {
|
||||
@ApiOperation({
|
||||
summary: "Unified file status catalog + counts (blame + claim)",
|
||||
description:
|
||||
"Returns calculatable unified statuses and per-status counts for this insurer's files. Use `unifiedStatus` on GET files to filter.",
|
||||
})
|
||||
@ApiQuery({
|
||||
name: "from",
|
||||
required: false,
|
||||
description: "Optional start datetime (ISO string)",
|
||||
})
|
||||
@ApiQuery({
|
||||
name: "to",
|
||||
required: false,
|
||||
description: "Optional end datetime (ISO string)",
|
||||
"Calculatable unified statuses and per-status counts for this insurer's files. Filter lists with `unifiedStatus` and `fileType`. Optional `from` / `to` ISO dates narrow the counted portfolio.",
|
||||
})
|
||||
@ApiResponse({ status: 200, type: UnifiedFileStatusReportDto })
|
||||
async getUnifiedFileStatusReport(
|
||||
@CurrentUser() actor,
|
||||
@Query("from") from?: string,
|
||||
@Query("to") to?: string,
|
||||
) {
|
||||
@Query() query: UnifiedFileStatusReportQueryDto,
|
||||
): Promise<UnifiedFileStatusReportDto> {
|
||||
return await this.expertInsurerService.getInsurerUnifiedFileStatusReport(
|
||||
actor,
|
||||
from,
|
||||
to,
|
||||
query,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,15 @@ import { enrichBlamePartiesForAgreementView } from "src/helpers/blame-party-agre
|
||||
import { BlameRequestType } from "src/Types&Enums/blame-request-management/blameRequestType.enum";
|
||||
import { PartyRole } from "src/request-management/entities/schema/partyRole.enum";
|
||||
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,
|
||||
@@ -1328,6 +1336,7 @@ export class ExpertInsurerService {
|
||||
createdAt: (f) => f.updatedAt ?? f.createdAt,
|
||||
requestNo: (f) => f.publicId,
|
||||
status: (f) => f.unifiedFileStatus,
|
||||
fileType: (f) => f.fileType,
|
||||
searchExtras: (f) =>
|
||||
[
|
||||
f.fileType,
|
||||
@@ -1352,16 +1361,18 @@ export class ExpertInsurerService {
|
||||
|
||||
async getInsurerUnifiedFileStatusReport(
|
||||
actor: any,
|
||||
from?: string,
|
||||
to?: string,
|
||||
) {
|
||||
query: UnifiedFileStatusReportQueryDto = {},
|
||||
): Promise<UnifiedFileStatusReportDto> {
|
||||
const clientObjectId = this.getClientId(actor);
|
||||
const { fromDate, toDate } = this.parseDateRange(from, to);
|
||||
const { fromDate, toDate } = parseListDateRange(query.from, query.to);
|
||||
|
||||
const files = await this.buildMergedInsurerFiles(clientObjectId);
|
||||
const inRange = files.filter((f) =>
|
||||
this.isInDateRange(f.createdAt, fromDate, toDate),
|
||||
let inRange = files.filter((f) =>
|
||||
isInListDateRange(f.createdAt, fromDate, toDate),
|
||||
);
|
||||
if (query.fileType) {
|
||||
inRange = inRange.filter((f) => f.fileType === query.fileType);
|
||||
}
|
||||
|
||||
return {
|
||||
statuses: getUnifiedFileStatusCatalog(),
|
||||
@@ -1946,7 +1957,10 @@ export class ExpertInsurerService {
|
||||
under_review: number;
|
||||
waiting_for_documents_resend: number;
|
||||
}> {
|
||||
const report = await this.getInsurerUnifiedFileStatusReport(actor, from, to);
|
||||
const report = await this.getInsurerUnifiedFileStatusReport(actor, {
|
||||
from,
|
||||
to,
|
||||
});
|
||||
const counts = report.counts;
|
||||
return {
|
||||
all: counts.all ?? 0,
|
||||
|
||||
Reference in New Issue
Block a user