diff --git a/apps/api/src/applicant/dto/ienuser-filter.dto.ts b/apps/api/src/applicant/dto/ienuser-filter.dto.ts index f2e6346b..5c56f0f4 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 f73dd2b5..a6740efd 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); } }