Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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`);
}
}
}
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,
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)]),
];
}
}
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;
}
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`);
}
}
private setNumeric(n: number, cond: 'limit' | 'offset' | 'page' | 'cache'): void {
if (!isNil(n)) {
validateNumeric(n, cond);
this.queryObject[this.paramNames[cond]] = n;
}
}
}
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;
}
getNumeric(num) {
if (util_1.isNil(this[`_${num}`])) {
return '';
}
const param = this.getParamName(num);
const value = this[`_${num}`];
return `${param}=${value}&`;
}
}
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);
}