Skip to content

Commit

Permalink
feat: remove min length restriction for name query (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
fityannugroho authored Jan 18, 2024
1 parent b7da35d commit 5ad9fea
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 24 deletions.
5 changes: 2 additions & 3 deletions src/district/district.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
PartialType,
PickType,
} from '@nestjs/swagger';
import { IsNotEmpty, IsNumberString, Length } from 'class-validator';
import { IsNotEmpty, IsNumberString, Length, MaxLength } from 'class-validator';
import { PaginationQuery } from '@/common/dto/pagination.dto';

export class District {
Expand All @@ -17,9 +17,8 @@ export class District {
@ApiProperty({ description: 'The district code', example: '110101' })
code: string;

@IsNotEmpty()
@IsNotSymbol("'()-./")
@Length(3, 255)
@MaxLength(100)
@ApiProperty({ description: 'The district name', example: 'Bakongan' })
name: string;

Expand Down
4 changes: 2 additions & 2 deletions src/island/island.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
IsOptional,
IsString,
Length,
MaxLength,
ValidateIf,
} from 'class-validator';
import { EqualsAny } from '../common/decorator/EqualsAny';
Expand Down Expand Up @@ -41,9 +42,8 @@ export class Island {
@ApiProperty({ example: false })
isPopulated: boolean;

@IsNotEmpty()
@IsNotSymbol("'-/")
@Length(3, 255)
@MaxLength(100)
@ApiProperty({
description: 'The island name',
example: 'Pulau Batukapal',
Expand Down
5 changes: 2 additions & 3 deletions src/province/province.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
PartialType,
PickType,
} from '@nestjs/swagger';
import { IsNotEmpty, IsNumberString, Length } from 'class-validator';
import { IsNotEmpty, IsNumberString, Length, MaxLength } from 'class-validator';
import { PaginationQuery } from '@/common/dto/pagination.dto';

export class Province {
Expand All @@ -17,9 +17,8 @@ export class Province {
@ApiProperty({ description: 'The province code', example: '11' })
code: string;

@IsNotEmpty()
@IsNotSymbol()
@Length(3, 255)
@MaxLength(100)
@ApiProperty({ description: 'The province name', example: 'ACEH' })
name: string;
}
Expand Down
5 changes: 2 additions & 3 deletions src/regency/regency.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
PartialType,
PickType,
} from '@nestjs/swagger';
import { IsNotEmpty, IsNumberString, Length } from 'class-validator';
import { IsNotEmpty, IsNumberString, Length, MaxLength } from 'class-validator';
import { PaginationQuery } from '@/common/dto/pagination.dto';

export class Regency {
Expand All @@ -17,9 +17,8 @@ export class Regency {
@ApiProperty({ description: 'The regency code', example: '1101' })
code: string;

@IsNotEmpty()
@IsNotSymbol()
@Length(3, 255)
@MaxLength(100)
@ApiProperty({
description: 'The regency name',
example: 'KABUPATEN ACEH SELATAN',
Expand Down
5 changes: 2 additions & 3 deletions src/village/village.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
PartialType,
PickType,
} from '@nestjs/swagger';
import { IsNotEmpty, IsNumberString, Length } from 'class-validator';
import { IsNotEmpty, IsNumberString, Length, MaxLength } from 'class-validator';

export class Village {
@IsNotEmpty()
Expand All @@ -17,9 +17,8 @@ export class Village {
@ApiProperty({ description: 'The village code', example: '1101012001' })
code: string;

@IsNotEmpty()
@IsNotSymbol("'()-./")
@Length(3, 255)
@MaxLength(100)
@ApiProperty({ description: 'The village name', example: 'Keude Bakongan' })
name: string;

Expand Down
4 changes: 2 additions & 2 deletions test/district.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ describe('District (e2e)', () => {
});
});

it("should return 400 if the `name` is empty, less than 3 chars, more than 255 chars, or contains any other symbols besides '()-./", async () => {
const invalidNames = ['', 'ab', 'x'.repeat(256), 'b@ndung'];
it("should return 400 if the `name` is more than 100 chars, or contains any other symbols besides '()-./", async () => {
const invalidNames = ['x'.repeat(101), 'b@ndung'];

for (const name of invalidNames) {
await tester.expectBadRequest(`${baseUrl}?name=${name}`);
Expand Down
4 changes: 2 additions & 2 deletions test/island.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ describe('Island (e2e)', () => {
});
});

it('should return 400 if the `name` is empty, less than 3 chars, more than 255 chars, or contains any symbols', async () => {
const invalidNames = ['', 'ab', 'x'.repeat(256), 's@bang'];
it('should return 400 if the `name` is more than 100 chars, or contains any symbols', async () => {
const invalidNames = ['x'.repeat(101), 's@bang'];

for (const name of invalidNames) {
await tester.expectBadRequest(`${baseUrl}?name=${name}`);
Expand Down
4 changes: 2 additions & 2 deletions test/province.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ describe('Province (e2e)', () => {
});

describe(`GET ${baseUrl}?name={name}`, () => {
it('should return 400 if the `name` is empty, less than 3 chars, more than 255 chars, or contains any symbols', async () => {
const invalidNames = ['', 'ab', 'x'.repeat(256), 'j@wa'];
it('should return 400 if the `name` is more than 100 chars, or contains any symbols', async () => {
const invalidNames = ['x'.repeat(101), 'j@wa'];

for (const name of invalidNames) {
await tester.expectBadRequest(`${baseUrl}?name=${name}`);
Expand Down
4 changes: 2 additions & 2 deletions test/regency.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ describe('Regency (e2e)', () => {
});
});

it('should return 400 if the `name` is empty, less than 3 chars, more than 255 chars, or contains any symbols', async () => {
const invalidNames = ['', 'ab', 'x'.repeat(256), 'b@ndung'];
it('should return 400 if the `name` is more than 100 chars, or contains any symbols', async () => {
const invalidNames = ['x'.repeat(101), 'b@ndung'];

for (const name of invalidNames) {
await tester.expectBadRequest(`${baseUrl}?name=${name}`);
Expand Down
4 changes: 2 additions & 2 deletions test/village.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ describe('Village (e2e)', () => {
});
});

it("should return 400 if the `name` is empty, less than 3 chars, more than 255 chars, or contains any other symbols besides '()-./", async () => {
const invalidNames = ['', 'ab', 'x'.repeat(256), 'c!nunuk'];
it("should return 400 if the `name` more than 100 chars, or contains any other symbols besides '()-./", async () => {
const invalidNames = ['x'.repeat(101), 'c!nunuk'];

for (const name of invalidNames) {
await tester.expectBadRequest(`${baseUrl}?name=${name}`);
Expand Down

0 comments on commit 5ad9fea

Please sign in to comment.