From 1724bc9dff5f7fb86efe4e2f28e2ebb7b6d68819 Mon Sep 17 00:00:00 2001 From: Jerry-EY <146475472+jerry-ey@users.noreply.github.com> Date: Fri, 4 Oct 2024 07:07:56 -0700 Subject: [PATCH] add limit as required (#659) Co-authored-by: Jerry Wang --- .../src/applicant/dto/ienuser-filter.dto.ts | 23 +++++++++++++++---- .../src/applicant/external-api.controller.ts | 3 ++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/apps/api/src/applicant/dto/ienuser-filter.dto.ts b/apps/api/src/applicant/dto/ienuser-filter.dto.ts index f2e6346ba..5c56f0f4c 100644 --- a/apps/api/src/applicant/dto/ienuser-filter.dto.ts +++ b/apps/api/src/applicant/dto/ienuser-filter.dto.ts @@ -1,7 +1,7 @@ -import { IsNumberString, IsOptional, IsString, IsDateString } from 'class-validator'; +import { IsNumberString, IsOptional, IsString, IsDateString, IsNotEmpty } from 'class-validator'; import { ApiPropertyOptional } from '@nestjs/swagger'; -export class IENUserFilterAPIDTO { +export class IENUserBaseFilterAPIDTO { @ApiPropertyOptional({ description: 'Start date for range', example: '2020-01-01', @@ -25,17 +25,30 @@ export class IENUserFilterAPIDTO { @IsString() organization?: string; + @ApiPropertyOptional({ + description: 'Skip the number of results', + }) + @IsOptional() + @IsNumberString() + skip?: number; +} +export class IENUserFilterAPIDTO extends IENUserBaseFilterAPIDTO { @ApiPropertyOptional({ description: 'Limit the number of results', }) @IsOptional() @IsNumberString() limit?: number; +} +/** + * As class-validator does not override the decorator @IsOptional when override the parent class, we need to create a separate class for the filter with limit + */ +export class IENUserLimitFilterAPIDTO extends IENUserBaseFilterAPIDTO { @ApiPropertyOptional({ - description: 'Skip the number of results', + description: 'Limit the number of results', }) - @IsOptional() + @IsNotEmpty() @IsNumberString() - skip?: number; + limit!: number; } diff --git a/apps/api/src/applicant/external-api.controller.ts b/apps/api/src/applicant/external-api.controller.ts index f73dd2b57..a6740efd7 100644 --- a/apps/api/src/applicant/external-api.controller.ts +++ b/apps/api/src/applicant/external-api.controller.ts @@ -24,6 +24,7 @@ import { IENUserFilterAPIDTO, SyncApplicantsResultDTO } from './dto'; import { AuthGuard } from '../auth/auth.guard'; import { JWTGuard } from 'src/auth/jwt.guard'; import { ApplicantSyncRO } from './ro/sync.ro'; +import { IENUserLimitFilterAPIDTO } from './dto/ienuser-filter.dto'; @Controller('external-api') @ApiTags('External API data process') @@ -140,7 +141,7 @@ export class ExternalAPIController { @UseGuards(JWTGuard) @ApiBearerAuth() @Get('/applicants') - async getApplicants(@Query() filter: IENUserFilterAPIDTO): Promise { + async getApplicants(@Query() filter: IENUserLimitFilterAPIDTO): Promise { return await this.externalAPIService.getApplicants(filter); } }