Skip to content

Commit

Permalink
add limit as required (#659)
Browse files Browse the repository at this point in the history
Co-authored-by: Jerry Wang <jerryappleid761208@gmail.com>
  • Loading branch information
jerry-ey and c1495616js authored Oct 4, 2024
1 parent 080a994 commit 1724bc9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
23 changes: 18 additions & 5 deletions apps/api/src/applicant/dto/ienuser-filter.dto.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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;
}
3 changes: 2 additions & 1 deletion apps/api/src/applicant/external-api.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -140,7 +141,7 @@ export class ExternalAPIController {
@UseGuards(JWTGuard)
@ApiBearerAuth()
@Get('/applicants')
async getApplicants(@Query() filter: IENUserFilterAPIDTO): Promise<ApplicantSyncRO[]> {
async getApplicants(@Query() filter: IENUserLimitFilterAPIDTO): Promise<ApplicantSyncRO[]> {
return await this.externalAPIService.getApplicants(filter);
}
}

0 comments on commit 1724bc9

Please sign in to comment.