chore: mock server name validation and prevent duplicates (#5524)

This commit is contained in:
Mir Arif Hasan 2025-10-29 14:41:52 +06:00 committed by GitHub
parent 881c71560b
commit 213c5436bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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({