class-validator#IsDefined TypeScript Examples

The following examples show how to use class-validator#IsDefined. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: queue.module.ts    From nest-amqp with MIT License 6 votes vote down vote up
private static getConnectionOptions(options: AMQPConnectionOptions): AMQPConnectionOptions {
    const { connectionOptions, connectionUri, throwExceptionOnConnectionError } = options;

    return {
      connectionUri,
      ...(isDefined(connectionOptions) ? { connectionOptions } : {}),
      ...(isDefined(throwExceptionOnConnectionError) ? { throwExceptionOnConnectionError } : {}),
    };
  }
Example #2
Source File: block-query.dto.ts    From ironfish-api with Mozilla Public License 2.0 6 votes vote down vote up
@ApiPropertyOptional({
    description:
      'Block sequence. Will only return blocks on the main chain if provided',
  })
  @ValidateIf((o: BlockQueryDto) => o.hash === undefined)
  @IsDefined({
    message: '"hash" or "sequence" required to query for single block',
  })
  @Max(Number.MAX_SAFE_INTEGER)
  @Min(1)
  @IsInt()
  @Type(() => Number)
  readonly sequence?: number;
Example #3
Source File: timeseries.ts    From Deep-Lynx with MIT License 5 votes vote down vote up
@IsDefined()
    value: any;
Example #4
Source File: user.ts    From ts-di-starter with MIT License 5 votes vote down vote up
@IsDefined()
  user: admin.auth.UserRecord;
Example #5
Source File: type_mapping.ts    From Deep-Lynx with MIT License 5 votes vote down vote up
@IsDefined()
    sample_payload?: any;
Example #6
Source File: type_transformation.ts    From Deep-Lynx with MIT License 5 votes vote down vote up
@IsDefined()
    value?: any;
Example #7
Source File: type_transformation.ts    From Deep-Lynx with MIT License 5 votes vote down vote up
@IsDefined()
    original_value: any;
Example #8
Source File: data_source.ts    From Deep-Lynx with MIT License 5 votes vote down vote up
@IsDefined()
    data_type: 'json' | 'csv' = 'json';
Example #9
Source File: data_source.ts    From Deep-Lynx with MIT License 5 votes vote down vote up
@IsDefined()
    auth_method: 'none' | 'basic' | 'token' = 'none';
Example #10
Source File: import.ts    From Deep-Lynx with MIT License 5 votes vote down vote up
@IsDefined()
    data: any;
Example #11
Source File: task.ts    From Deep-Lynx with MIT License 5 votes vote down vote up
@IsOptional()
    @IsDefined()
    data?: any;
Example #12
Source File: block-query.dto.ts    From ironfish-api with Mozilla Public License 2.0 5 votes vote down vote up
@ApiPropertyOptional({ description: 'Block hash' })
  @ValidateIf((o: BlockQueryDto) => o.sequence === undefined)
  @IsDefined({
    message: '"hash" or "sequence" required to query for single block',
  })
  @IsString()
  readonly hash?: string;
Example #13
Source File: create-user.dto.ts    From ironfish-api with Mozilla Public License 2.0 5 votes vote down vote up
@ValidateIf((o: CreateUserDto) => o.telegram === undefined)
  @IsDefined({
    message: '"discord" or "telegram" required when registering',
  })
  readonly discord?: string;
Example #14
Source File: create-user.dto.ts    From ironfish-api with Mozilla Public License 2.0 5 votes vote down vote up
@ValidateIf((o: CreateUserDto) => o.discord === undefined)
  @IsDefined({
    message: '"discord" or "telegram" required when registering',
  })
  readonly telegram?: string;
Example #15
Source File: order.entity.ts    From rest-api.ts with MIT License 5 votes vote down vote up
@IsDefined()
  @ManyToOne(() => User, user => user.orders)
  user: User;
Example #16
Source File: placement.entity.ts    From rest-api.ts with MIT License 5 votes vote down vote up
@IsDefined()
  @ManyToOne(() => Product, product => product.placements)
  product: Product;
Example #17
Source File: placement.entity.ts    From rest-api.ts with MIT License 5 votes vote down vote up
@IsDefined()
  @ManyToOne(() => Order, order => order.placements)
  order: Order;
Example #18
Source File: product.entity.ts    From rest-api.ts with MIT License 5 votes vote down vote up
@IsDefined()
  @Column({type: 'text', nullable: false})
  title: string;
Example #19
Source File: product.entity.ts    From rest-api.ts with MIT License 5 votes vote down vote up
@IsPositive()
  @IsDefined()
  @Column({type: 'float', nullable: false})
  price: number;
Example #20
Source File: user.entity.ts    From rest-api.ts with MIT License 5 votes vote down vote up
@IsDefined()
  @IsEmail()
  @Column({unique: true})
  email: string;
Example #21
Source File: user.entity.ts    From rest-api.ts with MIT License 5 votes vote down vote up
@IsDefined()
  @Column()
  hashedPassword: string;
Example #22
Source File: CreateMediaAdapter.ts    From typescript-clean-architecture with MIT License 5 votes vote down vote up
@Expose()
  @IsDefined()
  public file: Buffer|NodeJS.ReadableStream;
Example #23
Source File: index.ts    From office-hours with GNU General Public License v3.0 5 votes vote down vote up
@IsOptional()
  @IsDefined() // TODO: use ValidateNested instead, for some reason it's crunked
  courses!: KhouryCourse[] | KhouryProfCourse[];
Example #24
Source File: ParametersValidator.ts    From affinidi-core-sdk with Apache License 2.0 5 votes vote down vote up
static async process(schema: any, index: number) {
    const { type: Schema, isRequired, value: SchemaValue } = schema

    const allErrors: any = []

    const isUndefined = !isDefined(SchemaValue)

    if (isRequired && isUndefined) {
      allErrors.push({ value: SchemaValue, message: `Required parameter at index [${index}] is missing.` })
    }

    if (isUndefined) {
      return allErrors
    }

    if (isPrimitive(Schema)) {
      const { isValid, message } = ParametersValidator.validatePrimitive(Schema, SchemaValue)

      if (!isValid) {
        allErrors.push({ value: SchemaValue, message })
      }
    } else if (Object.keys(jsonSchemas).indexOf(Schema) !== -1) {
      try {
        const ajv = new Ajv()
        const isValid = ajv.validate(jsonSchemas[Schema as keyof typeof jsonSchemas].valueOf(), SchemaValue)

        if (!isValid) {
          allErrors.push({ value: SchemaValue, message: ajv.errorsText() })
        }
      } catch (error) {
        allErrors.push({ value: SchemaValue, message: error })
      }
    } else {
      const schema = new Schema()

      for (const [key, value] of Object.entries(SchemaValue)) {
        schema[key] = value
      }

      const errors = await validate(schema)
      const schemaErrors = []

      for (const error of errors) {
        const { property, value, constraints } = error

        schemaErrors.push({
          argument: property,
          value: value,
          message: constraints,
        })
      }

      if (schemaErrors.length > 0) {
        allErrors.push(schemaErrors)
      }
    }

    return allErrors
  }
Example #25
Source File: shared.dto.ts    From affinidi-core-sdk with Apache License 2.0 5 votes vote down vote up
@IsDefined()
  @IsArray()
  context: unknown[]
Example #26
Source File: shards.ts    From Discord-Bot-TypeScript-Template with MIT License 5 votes vote down vote up
@IsDefined()
    @IsString()
    @Length(1, 128)
    name: string;
Example #27
Source File: shards.ts    From Discord-Bot-TypeScript-Template with MIT License 5 votes vote down vote up
@IsDefined()
    @IsUrl()
    url: string;
Example #28
Source File: clusters.ts    From Discord-Bot-TypeScript-Template with MIT License 5 votes vote down vote up
@IsDefined()
    @IsUrl({ require_tld: false })
    url: string;
Example #29
Source File: clusters.ts    From Discord-Bot-TypeScript-Template with MIT License 5 votes vote down vote up
@IsDefined()
    @IsString()
    @Length(5, 2000)
    token: string;