How to use the class-validator.Max function in class-validator

To help you get started, we’ve selected a few class-validator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xmlking / ngx-starter-kit / apps / api / src / app / project / dto / resource-quota.ts View on Github external
// namespace level hard limits
export class ResourceQuota implements IResourceQuota {
  @IsNotEmpty()
  @ValidateNested()
  @Type(() => Requests)
  requests: Requests;

  @IsNotEmpty()
  @ValidateNested()
  @Type(() => Limits)
  limits: Limits;

  @IsOptional()
  @IsNumber()
  @Min(0)
  @Max(10156)
  cpu ? = 1;

  @IsOptional()
  @IsNumber()
  @Min(0)
  @Max(10720)
  memory ? = 1;
}
github goparrot / geocoder / src / model / query.ts View on Github external
static readonly DEFAULT_RESULT_LIMIT: number = 5;
    static readonly DEFAULT_RESULT_LANGUAGE: string = 'en';

    @IsOptional()
    @IsEnum(AccuracyEnum)
    accuracy?: AccuracyEnum;

    @IsOptional()
    @IsString()
    @MinLength(2)
    @MaxLength(2)
    countryCode?: string;

    @IsNumber()
    @Min(1)
    @Max(100)
    limit: number = Query.DEFAULT_RESULT_LIMIT;

    @IsString()
    @MinLength(2)
    @MaxLength(2)
    language: string = Query.DEFAULT_RESULT_LANGUAGE;

    @ToBoolean()
    @IsBoolean()
    fillMissingQueryProperties: boolean = true;

    @ToBoolean()
    @IsBoolean()
    withRaw: boolean = false;
}
github xmlking / ngx-starter-kit / apps / api / src / app / project / dto / limits.ts View on Github external
import { Limits as ILimits } from '@ngx-starter-kit/models';
import { IsNotEmpty, IsNumber, Max, Min } from 'class-validator';

export class Limits implements ILimits {
  @IsNumber()
  @IsNotEmpty()
  @Min(0)
  @Max(10156)
  cpu = 1;

  @IsNumber()
  @IsNotEmpty()
  @Min(0)
  @Max(10720)
  memory = 1;
}
github magishift / magishift.core / src / crud / crud.filter.ts View on Github external
@IsOptional()
  @IsArray()
  @Field(() => [String], {
    nullable: true,
    description: 'ex. ["id ASC", "title DESC"]',
    defaultValue: ['id ASC'],
  })
  @ApiModelProperty()
  order?: string[];

  @Field(() => Int, { nullable: true })
  @ApiModelProperty()
  @IsOptional()
  @IsInt()
  @Min(1)
  @Max(1000)
  limit?: number;

  @Field(() => Int, { nullable: true })
  @ApiModelProperty()
  @IsOptional()
  @IsInt()
  @Min(0)
  offset?: number;

  @IsOptional()
  @IsBoolean()
  @Field({ nullable: true })
  @ApiModelProperty()
  isShowDeleted?: boolean;

  @IsOptional()
github scalio / bazel-nx-example / apps / api / src / cats / dto / create-cat.dto.ts View on Github external
import { ICreateCatDto } from '@api-interface';
import { ApiModelProperty } from '@nestjs/swagger';
import { IsInt, IsNotEmpty, Max, Min } from 'class-validator';

export class CreateCatDto implements ICreateCatDto {
  @ApiModelProperty()
  @IsNotEmpty()
  name: string;

  @ApiModelProperty()
  @IsInt()
  @Min(1)
  @Max(200)
  age: number;
}
github xmlking / ngx-starter-kit / apps / api / src / app / project / dto / requests.ts View on Github external
import { Requests as IRequests } from '@ngx-starter-kit/models';
import { IsNotEmpty, IsNumber, IsOptional, Max, Min } from 'class-validator';

export class Requests implements IRequests {
  @IsNumber()
  @IsNotEmpty()
  @Min(0)
  @Max(10156)
  cpu = 1;

  @IsNumber()
  @IsNotEmpty()
  @Min(0)
  @Max(10720)
  memory = 1;

  @IsNumber()
  @IsOptional()
  @Min(0)
  @Max(25)
  gpu: number;
}
github Roche / lxdhub / packages / api / src / common / pagination-options.dto.ts View on Github external
import { Type } from 'class-transformer';
import { IsInt, IsOptional, Min, Max } from 'class-validator';

/**
 * This interface represents
 * options for iterating through
 * paginated lists.
 */
export class PaginationOptionsDto {
    /**
     * The maximum amount of items to request.
     */
    @IsInt()
    @Min(1)
    @Max(200)
    @IsOptional()
    @Type(() => Number)
    readonly limit: number = 20;

    /**
     * The offset of the items
     */
    @IsInt()
    @Min(0)
    @IsOptional()
    @Type(() => Number)
    readonly offset: number = 0;
}
github MichalLytek / type-graphql / examples / automatic-validation / recipes-arguments.ts View on Github external
import { Max, Min } from "class-validator";
import { ArgsType, Field, Int } from "../../src";

@ArgsType()
export class RecipesArguments {
  @Field(type => Int)
  @Min(0)
  skip: number = 0;

  @Field(type => Int)
  @Min(1)
  @Max(50)
  take: number = 10;
}
github EndyKaufman / ngx-dynamic-form-builder / apps / demo / src / app / shared / models / company.ts View on Github external
name: 'Name',
    regionNum: 'Region num'
  };

  id: number;

  @Validate(TextLengthMore15, {
    message: 'The company name must be longer than 15'
  })
  @IsNotEmpty()
  @MaxLength(20)
  name: string;

  @IsOptional()
  @Min(1)
  @Max(99)
  regionNum: number;

  toString() {
    const arr: string[] = [];
    if (arr.length === 0 && this.name) {
      arr.push(this.name);
    }
    return arr.join(' ');
  }

  constructor(data?: any) {
    plainToClassFromExist(this, data);
  }
}