How to use the class-validator.IsIn 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 vladimiry / ElectronMail / src / electron-main / database / entity / mail.ts View on Github external
@ValidateNested()
    @IsArray()
    @Type(() => MailAddress)
    bccRecipients!: MailAddress[];

    @ValidateNested()
    @IsArray()
    @Type(() => File)
    attachments!: File[];

    @IsNotEmpty()
    @IsBoolean()
    unread!: Model.Mail["unread"];

    @IsIn(Model.MAIL_STATE._.values)
    state!: Model.Mail["state"];

    // TODO consider making Mail.confidential field optional, not used by protonmail?
    @IsNotEmpty()
    @IsBoolean()
    confidential!: Model.Mail["confidential"];

    @IsIn(Model.REPLY_TYPE._.values)
    replyType!: Model.Mail["replyType"];

    @ValidateNested()
    @Type(() => MailFailedDownload)
    failedDownload?: MailFailedDownload;
}
github nestjsx / crud / dist / dto / filter-param.dto.js View on Github external
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
const class_validator_1 = require("class-validator");
const operators_list_1 = require("../operators.list");
class FilterParamDto {
}
__decorate([
    class_validator_1.IsNotEmpty(),
    class_validator_1.IsString(),
    __metadata("design:type", String)
], FilterParamDto.prototype, "field", void 0);
__decorate([
    class_validator_1.IsNotEmpty(),
    class_validator_1.IsIn(operators_list_1.COMPARISON_OPERATORS),
    __metadata("design:type", String)
], FilterParamDto.prototype, "operator", void 0);
__decorate([
    class_validator_1.IsOptional(),
    __metadata("design:type", Object)
], FilterParamDto.prototype, "value", void 0);
exports.FilterParamDto = FilterParamDto;
//# sourceMappingURL=filter-param.dto.js.map
github vladimiry / ElectronMail / src / electron-main / database / entity / folder.ts View on Github external
import {IsIn, IsNotEmpty, IsString} from "class-validator";

import * as Model from "src/shared/model/database";
import {Entity} from "./base";

export class Folder extends Entity implements Model.Folder {
    @IsIn(Model.MAIL_FOLDER_TYPE._.values)
    folderType!: Model.Folder["folderType"];

    @IsString()
    name!: Model.Folder["name"];

    @IsNotEmpty()
    @IsString()
    mailFolderId!: Model.Folder["mailFolderId"];
}
github devonfw / devon4node / template / src / shared / user / models / dto / user.dto.ts View on Github external
export class UserDTO extends BaseModelDTO {
  @ApiModelProperty()
  @IsNotEmpty()
  username!: string;

  @ApiModelProperty()
  @IsNotEmpty()
  @IsEmail()
  mail!: string;

  @ApiModelPropertyOptional({
    enum: Object.keys(UserRole),
    default: UserRole.User,
    example: UserRole.User,
  })
  @IsIn(Object.keys(UserRole))
  role?: string;
}
github new-eden-social / new-eden-social / src / modules / post / post.interface.ts View on Github external
import { IsIn, IsNumber, IsOptional, IsString, ValidateIf } from 'class-validator';
import { ICharacterResponse } from '../character/character.interface';
import { CREATABLE_TYPES } from './post.constants';

export class ICreatePostRequest {

  @IsString()
  content: string;

  @IsIn(Object.keys(CREATABLE_TYPES))
  type: string;

  @IsOptional()
  @IsNumber()
  locationId: number;

  @ValidateIf(o => !o.characterId)
  @IsNumber()
  corporationId: number;

  @ValidateIf(o => !o.corporationId)
  @IsNumber()
  characterId: number;

}
github Kibibit / achievibit / src / config / achievibit-config.model.ts View on Github external
import { Exclude, Expose, Transform } from 'class-transformer';
import { IsBoolean, IsIn, IsNumber, IsOptional, IsString, IsUrl, Matches } from 'class-validator';
import { trim } from 'lodash';
import { v1 as uuidv1 } from 'uuid';

export const NODE_ENVIRONMENT_OPTIONS = [ 'development', 'production', 'test' ];
export const SMEE_IO_REGEX = /^https:\/\/(?:www\.)?smee\.io\/[a-zA-Z0-9_-]+\/?/;
export const ENDPONT_PATH_REGEX = /^([\w]+)?(\/[\w-]+)*$/;

@Exclude()
export class AchievibitConfig {
  @Expose()
  @IsString()
  @IsIn(NODE_ENVIRONMENT_OPTIONS)
  nodeEnv = 'development';

  @Expose()
  @IsNumber()
  port = 10101;

  @Expose()
  @IsOptional()
  @IsString()
  @IsUrl({ protocols: [ 'mongodb', 'mongodb+srv' ], require_tld: false }, {
    message: '$property should be a valid mongodb URL'
  })
  dbUrl: string;

  @Expose()
  @Matches(SMEE_IO_REGEX)
github danielwii / asuna-node-server / src / modules / core / token / controller.ts View on Github external
readonly expiredAt?: Date;

  @IsNumber()
  @Max(999)
  @Min(1)
  @IsOptional()
  @Transform(value => (value || value === 0 ? Number(value) : null))
  readonly remainingCount?: number;

  constructor(o: ObtainOperationTokenDto) {
    Object.assign(this, deserializeSafely(ObtainOperationTokenDto, o));
  }
}

class RedeemQuery {
  @IsIn(_.keys(TokenRule))
  readonly role: keyof typeof TokenRule = 'operation';

  @IsString()
  @Transform(value => _.trim(value))
  readonly key: string;

  @IsString()
  @Transform(value => _.trim(value))
  readonly service: string;
}

class GetParams {
  @IsString()
  @Transform(value => _.trim(value))
  readonly token: string;
}
github vladimiry / ElectronMail / src / electron-main / database / entity / contact.ts View on Github external
year?: Model.Birthday["year"];
}

class ContactMailAddress extends Entity implements Model.ContactMailAddress {
    @IsIn(Model.CONTACT_ADDRESS_TYPE._.values)
    type!: Model.ContactMailAddress["type"];

    @IsString()
    customTypeName!: Model.ContactMailAddress["customTypeName"];

    @IsString()
    address!: Model.ContactMailAddress["address"];
}

class ContactPhoneNumber extends Entity implements Model.ContactPhoneNumber {
    @IsIn(Model.CONTACT_PHONE_NUMBER_TYPE._.values)
    type!: Model.ContactPhoneNumber["type"];

    @IsString()
    customTypeName!: Model.ContactPhoneNumber["customTypeName"];

    @IsString()
    @IsNotEmpty()
    number!: Model.ContactPhoneNumber["number"];
}

class ContactSocialId extends Entity implements Model.ContactSocialId {
    @IsIn(Model.CONTACT_SOCIAL_TYPE._.values)
    type!: Model.ContactSocialId["type"];

    @IsString()
    customTypeName!: Model.ContactSocialId["customTypeName"];
github nestjsx / crud / dist / dto / sort-param.dto.js View on Github external
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
const class_validator_1 = require("class-validator");
const operators_list_1 = require("../operators.list");
class SortParamDto {
}
__decorate([
    class_validator_1.IsNotEmpty(),
    class_validator_1.IsString(),
    __metadata("design:type", String)
], SortParamDto.prototype, "field", void 0);
__decorate([
    class_validator_1.IsNotEmpty(),
    class_validator_1.IsString(),
    class_validator_1.IsIn(operators_list_1.ORDER_BY),
    __metadata("design:type", String)
], SortParamDto.prototype, "order", void 0);
exports.SortParamDto = SortParamDto;
//# sourceMappingURL=sort-param.dto.js.map
github penta-jelly / re-radio / server / src / radio / songs-explorer / dto / SongExplorersWhereInput.dto.ts View on Github external
import { Type } from 'class-transformer';
import { IsIn, IsNumber, IsOptional, Max, Min, ValidateNested } from 'class-validator';
import { Order, orders } from '../youtube/interfaces/YouTubeVideo';

export class SongExplorersWhereDTO {
  q: string;

  @IsNumber()
  @Min(0)
  @Max(50)
  @IsOptional()
  maxResults?: number;

  @IsIn(orders)
  @IsOptional()
  order?: Order;
}

export class SongExplorersWhereInputDTO {
  @ValidateNested()
  @Type(() => SongExplorersWhereDTO)
  where: SongExplorersWhereDTO;
}