forked from Yara724/api
Fix SMS, and added pagination+sorting+searching for GETs
This commit is contained in:
@@ -48,6 +48,8 @@ import {
|
||||
VideoCaptureV2ResponseDto,
|
||||
} from "./dto/capture-part-v2.dto";
|
||||
import { GetMyClaimsV2ResponseDto, ClaimListItemV2Dto } from "./dto/my-claims-v2.dto";
|
||||
import { ListQueryV2Dto } from "src/common/dto/list-query-v2.dto";
|
||||
import { applyListQueryV2 } from "src/helpers/list-query-v2";
|
||||
import { ClaimDetailsV2ResponseDto } from "./dto/claim-details-v2.dto";
|
||||
import { ClaimCaseStatus } from "src/Types&Enums/claim-request-management/claim-case-status.enum";
|
||||
import { ClaimRequiredDocumentType, CarAngle } from "src/Types&Enums/claim-request-management/required-document-type.enum";
|
||||
@@ -6009,6 +6011,7 @@ export class ClaimRequestManagementService {
|
||||
async getMyClaimsV2(
|
||||
currentUserId: string,
|
||||
actor?: { sub: string; role?: string },
|
||||
query: ListQueryV2Dto = {},
|
||||
): Promise<GetMyClaimsV2ResponseDto> {
|
||||
try {
|
||||
let claims: any[];
|
||||
@@ -6050,7 +6053,25 @@ export class ClaimRequestManagementService {
|
||||
createdAt: c.createdAt,
|
||||
blameRequestId: c.blameRequestId?.toString(),
|
||||
})) as ClaimListItemV2Dto[];
|
||||
return { list, total: list.length };
|
||||
|
||||
const paged = applyListQueryV2(list, {
|
||||
publicId: (r) => r.publicId,
|
||||
createdAt: (r) => r.createdAt,
|
||||
requestNo: (r) => r.requestNo,
|
||||
status: (r) => r.status,
|
||||
searchExtras: (r) =>
|
||||
[r.claimRequestId, r.claimStatus, r.currentStep, r.blameRequestId].filter(
|
||||
Boolean,
|
||||
) as string[],
|
||||
}, query);
|
||||
|
||||
return {
|
||||
list: paged.list,
|
||||
total: paged.total,
|
||||
page: paged.page,
|
||||
limit: paged.limit,
|
||||
totalPages: paged.totalPages,
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof HttpException) throw error;
|
||||
this.logger.error('getMyClaimsV2 failed', error);
|
||||
|
||||
@@ -41,6 +41,7 @@ import {
|
||||
VideoCaptureV2ResponseDto,
|
||||
} from "./dto/capture-part-v2.dto";
|
||||
import { GetMyClaimsV2ResponseDto } from "./dto/my-claims-v2.dto";
|
||||
import { ListQueryV2Dto } from "src/common/dto/list-query-v2.dto";
|
||||
import { ClaimDetailsV2ResponseDto } from "./dto/claim-details-v2.dto";
|
||||
import { UserObjectionV2Dto } from "./dto/user-objection-v2.dto";
|
||||
import { UserRatingDto } from "./dto/user-rating.dto";
|
||||
@@ -60,16 +61,24 @@ export class ClaimRequestManagementV2Controller {
|
||||
@Get("requests")
|
||||
@ApiOperation({
|
||||
summary: "Get My Claims (V2)",
|
||||
description: "Get list of all claim requests for the current user.",
|
||||
description:
|
||||
"Claims for the current user (or field-expert in-person files). Optional query: `search`, `sortBy` (publicId | createdAt | requestNo | status), `sortOrder`, `page`, `limit`. Without `page`/`limit`, returns the full filtered list.",
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: "List of user claims",
|
||||
type: GetMyClaimsV2ResponseDto,
|
||||
})
|
||||
async getMyClaims(@CurrentUser() user: any): Promise<GetMyClaimsV2ResponseDto> {
|
||||
async getMyClaims(
|
||||
@CurrentUser() user: any,
|
||||
@Query() query: ListQueryV2Dto,
|
||||
): Promise<GetMyClaimsV2ResponseDto> {
|
||||
try {
|
||||
return await this.claimRequestManagementService.getMyClaimsV2(user.sub, user);
|
||||
return await this.claimRequestManagementService.getMyClaimsV2(
|
||||
user.sub,
|
||||
user,
|
||||
query,
|
||||
);
|
||||
} catch (error) {
|
||||
if (error instanceof HttpException) throw error;
|
||||
throw new InternalServerErrorException(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
|
||||
export class ClaimListItemV2Dto {
|
||||
@ApiProperty({ description: 'Claim case ID', example: '507f1f77bcf86cd799439011' })
|
||||
@@ -34,6 +34,17 @@ export class GetMyClaimsV2ResponseDto {
|
||||
@ApiProperty({ description: 'List of user claims', type: [ClaimListItemV2Dto] })
|
||||
list: ClaimListItemV2Dto[];
|
||||
|
||||
@ApiProperty({ description: 'Total count', example: 5 })
|
||||
@ApiProperty({ description: 'Total count after search filter', example: 5 })
|
||||
total: number;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: 'Current page when `page` or `limit` query params were sent',
|
||||
})
|
||||
page?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'Page size when paginating' })
|
||||
limit?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'Total pages when paginating' })
|
||||
totalPages?: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user