Skip to content

Commit

Permalink
Merge cd3d7c4 into 3ea0bd9
Browse files Browse the repository at this point in the history
  • Loading branch information
amitport committed Jan 21, 2018
2 parents 3ea0bd9 + cd3d7c4 commit 8101433
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/common/pipes/parse-int.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { Pipe, ArgumentMetadata } from '../index';
@Pipe()
export class ParseIntPipe implements PipeTransform<string> {
public async transform(value: string, metadata: ArgumentMetadata) {
const val = parseInt(value, 10);
if (isNaN(val)) {
throw new BadRequestException('Validation failed');
if (value.trim().length === value.length) {
const num = +value;

if (Number.isInteger(num)) {
return num;
}
}
return val;

throw new BadRequestException('Validation failed');
}
}

0 comments on commit 8101433

Please sign in to comment.