Skip to content

Commit

Permalink
feat: validation to receive a valid card number
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleymichael committed Sep 4, 2023
1 parent 32dcc88 commit 056bf39
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/cards/dto/cards.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsBoolean, IsNotEmpty, IsString } from 'class-validator';
import {
IsBoolean,
IsNotEmpty,
IsString,
Length,
Matches,
} from 'class-validator';

export class CardsDTO {
@IsString()
Expand All @@ -13,9 +19,13 @@ export class CardsDTO {
@IsString()
@IsNotEmpty()
@ApiProperty({
example: '11112222333344445555',
example: '1111222233334444',
description: 'Card number',
})
@Length(16, 16)
@Matches(/^[0-9]*$/, {
message: 'O número do cartão deve conter apenas dígitos numéricos.',
})
number: string;

@IsString()
Expand Down

0 comments on commit 056bf39

Please sign in to comment.