chore: mock server name validation and prevent duplicates (#5524)
This commit is contained in:
parent
881c71560b
commit
213c5436bc
1 changed files with 16 additions and 3 deletions
|
|
@ -7,15 +7,22 @@ import {
|
|||
registerEnumType,
|
||||
} from '@nestjs/graphql';
|
||||
import {
|
||||
IsAlphanumeric,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsString,
|
||||
Matches,
|
||||
Max,
|
||||
MaxLength,
|
||||
MinLength,
|
||||
} from 'class-validator';
|
||||
import { WorkspaceType } from 'src/types/WorkspaceTypes';
|
||||
|
||||
// Regex pattern for mock server name validation
|
||||
// Allows letters, numbers, spaces, dots, underscores, and hyphens
|
||||
const MOCK_SERVER_NAME_PATTERN = /^[a-zA-Z0-9 ._-]+$/;
|
||||
const MOCK_SERVER_NAME_ERROR_MESSAGE =
|
||||
'Name can only contain letters, numbers, spaces, dots, underscores, and hyphens';
|
||||
|
||||
@ObjectType()
|
||||
export class MockServer {
|
||||
@Field(() => ID, {
|
||||
|
|
@ -102,9 +109,12 @@ export class CreateMockServerInput {
|
|||
@Field({
|
||||
description: 'Name of the mock server',
|
||||
})
|
||||
@IsString()
|
||||
@MinLength(1)
|
||||
@MaxLength(255)
|
||||
@IsAlphanumeric()
|
||||
@Matches(MOCK_SERVER_NAME_PATTERN, {
|
||||
message: MOCK_SERVER_NAME_ERROR_MESSAGE,
|
||||
})
|
||||
name: string;
|
||||
|
||||
@Field({
|
||||
|
|
@ -149,10 +159,13 @@ export class UpdateMockServerInput {
|
|||
nullable: true,
|
||||
description: 'Name of the mock server',
|
||||
})
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@MinLength(1)
|
||||
@MaxLength(255)
|
||||
@IsAlphanumeric()
|
||||
@Matches(MOCK_SERVER_NAME_PATTERN, {
|
||||
message: MOCK_SERVER_NAME_ERROR_MESSAGE,
|
||||
})
|
||||
name?: string;
|
||||
|
||||
@Field({
|
||||
|
|
|
|||
Loading…
Reference in a new issue