How to use the @nestjsx/util.isNil function in @nestjsx/util

To help you get started, we’ve selected a few @nestjsx/util 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 nestjsx / crud / packages / crud-typeorm / src / typeorm-crud.service.ts View on Github external
private checkFilterIsArray(cond: QueryFilter, withLength?: boolean) {
    /* istanbul ignore if */
    if (
      !Array.isArray(cond.value) ||
      !cond.value.length ||
      (!isNil(withLength) ? withLength : false)
    ) {
      this.throwBadRequestException(`Invalid column '${cond.field}' value`);
    }
  }
}
github nestjsx / crud / packages / crud / src / crud / validation.helper.ts View on Github external
static createBulkDto(options: MergedCrudOptions): any {
    /* istanbul ignore else */
    if (validator && transformer && !isFalse(options.validation)) {
      const { IsArray, ArrayNotEmpty, ValidateNested } = validator;
      const { Type } = transformer;
      const hasDto = !isNil(options.dto.create);
      const groups = !hasDto ? [CrudValidationGroups.CREATE] : undefined;
      const always = hasDto ? true : undefined;
      const Model = hasDto ? options.dto.create : options.model.type;

      // tslint:disable-next-line:max-classes-per-file
      class BulkDtoImpl implements CreateManyDto {
        @ApiProperty({ type: Model, isArray: true })
        @IsArray({ groups, always })
        @ArrayNotEmpty({ groups, always })
        @ValidateNested({ each: true, groups, always })
        @Type(() => Model)
        bulk: T[];
      }

      Object.defineProperty(BulkDtoImpl, 'name', {
        writable: false,
github nestjsx / crud / packages / crud-request / src / request-query.builder.ts View on Github external
private setCondition(
    f: QueryFilter | QueryFilterArr | Array,
    cond: 'filter' | 'or',
  ): void {
    if (!isNil(f)) {
      const param = this.checkQueryObjectParam(cond, []);
      this.queryObject[param] = [
        ...this.queryObject[param],
        ...(Array.isArray(f) && !isString(f[0])
          ? (f as Array).map((o) => this.cond(o, cond))
          : [this.cond(f as QueryFilter | QueryFilterArr, cond)]),
      ];
    }
  }
github nestjsx / crud / packages / crud-request / src / request-query.builder.ts View on Github external
setJoin(j: QueryJoin | QueryJoinArr | Array): this {
    if (!isNil(j)) {
      const param = this.checkQueryObjectParam('join', []);
      this.queryObject[param] = [
        ...this.queryObject[param],
        ...(Array.isArray(j) && !isString(j[0])
          ? (j as Array).map((o) => this.addJoin(o))
          : [this.addJoin(j as QueryJoin | QueryJoinArr)]),
      ];
    }
    return this;
  }
github nestjsx / crud / packages / crud-request / src / request-query.validator.ts View on Github external
export function validateParamOption(options: ParamsOptions, name: string) {
  if (!isObject(options)) {
    throw new RequestQueryException(`Invalid param ${name}. Invalid crud options`);
  }
  const option = options[name];
  if (option && option.disabled) {
    return;
  }
  if (!isObject(option) || isNil(option.field) || isNil(option.type)) {
    throw new RequestQueryException(`Invalid param option in Crud`);
  }
}
github nestjsx / crud / packages / crud-request / src / request-query.builder.ts View on Github external
private setNumeric(n: number, cond: 'limit' | 'offset' | 'page' | 'cache'): void {
    if (!isNil(n)) {
      validateNumeric(n, cond);
      this.queryObject[this.paramNames[cond]] = n;
    }
  }
}
github nestjsx / crud / packages / crud-request / src / request-query.builder.ts View on Github external
sortBy(s: QuerySort | QuerySortArr | Array): this {
    if (!isNil(s)) {
      const param = this.checkQueryObjectParam('sort', []);
      this.queryObject[param] = [
        ...this.queryObject[param],
        ...(Array.isArray(s) && !isString(s[0])
          ? (s as Array).map((o) => this.addSortBy(o))
          : [this.addSortBy(s as QuerySort | QuerySortArr)]),
      ];
    }
    return this;
  }
github nestjsx / crud / packages / crud-request / lib / request-query.builder.js View on Github external
getNumeric(num) {
        if (util_1.isNil(this[`_${num}`])) {
            return '';
        }
        const param = this.getParamName(num);
        const value = this[`_${num}`];
        return `${param}=${value}&`;
    }
}
github nestjsx / crud / packages / crud / src / crud / crud-routes.factory.ts View on Github external
private setRouteArgs(name: BaseRouteName) {
    let rest = {};
    const routes: BaseRouteName[] = [
      'createManyBase',
      'createOneBase',
      'updateOneBase',
      'replaceOneBase',
    ];

    if (isIn(name, routes)) {
      const action = this.routeNameAction(name);
      const hasDto = !isNil(this.options.dto[action]);
      const { UPDATE, CREATE } = CrudValidationGroups;
      const groupEnum = isIn(name, ['updateOneBase', 'replaceOneBase']) ? UPDATE : CREATE;
      const group = !hasDto ? groupEnum : undefined;

      rest = R.setBodyArg(1, [Validation.getValidationPipe(this.options, group)]);
    }

    R.setRouteArgs({ ...R.setParsedRequestArg(0), ...rest }, this.target, name);
  }