Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
dto: DeepPartial,
parsed: CrudRequest['parsed'],
): T {
/* istanbul ignore if */
if (!isObject(dto)) {
return undefined;
}
if (hasLength(parsed.paramsFilter)) {
for (const filter of parsed.paramsFilter) {
dto[filter.field] = filter.value;
}
}
/* istanbul ignore if */
if (!hasLength(objKeys(dto))) {
return undefined;
}
return dto instanceof this.entityType
? Object.assign(dto, parsed.authPersist)
: plainToClass(this.entityType, { ...dto, ...parsed.authPersist });
}
static setExtraModels(swaggerModels: any) {
/* istanbul ignore else */
if (swaggerConst) {
const meta = Swagger.getExtraModels(swaggerModels.get);
const models: any[] = [
...meta,
...objKeys(swaggerModels)
.map((name) => swaggerModels[name])
.filter((one) => one && one.name !== swaggerModels.get.name),
];
R.set(swaggerConst.DECORATORS.API_EXTRA_MODELS, models, swaggerModels.get);
}
}
protected setSearchFieldObjectCondition(
builder: SelectQueryBuilder,
condition: SConditionKey,
field: string,
object: any,
) {
/* istanbul ignore else */
if (isObject(object)) {
const operators = objKeys(object);
if (operators.length === 1) {
const operator = operators[0] as ComparisonOperator;
const value = object[operator];
if (isObject(object.$or)) {
const orKeys = objKeys(object.$or);
this.setSearchFieldObjectCondition(
builder,
orKeys.length === 1 ? condition : '$or',
field,
object.$or,
);
} else {
this.builderSetWhere(builder, condition, field, value, operator);
}
static createPathParasmMeta(options: ParamsOptions): any[] {
return swaggerConst
? objKeys(options).map((param) => ({
name: param,
required: true,
in: 'path',
type: options[param].type === 'number' ? Number : String,
}))
: /* istanbul ignore next */ [];
}
options: CrudRequestOptions,
many = true,
): Promise> {
// create query builder
const builder = this.repo.createQueryBuilder(this.alias);
// get select fields
const select = this.getSelect(parsed, options.query);
// select fields
builder.select(select);
// search
this.setSearchCondition(builder, parsed.search);
// set joins
const joinOptions = options.query.join || {};
const allowedJoins = objKeys(joinOptions);
if (hasLength(allowedJoins)) {
const eagerJoins: any = {};
for (let i = 0; i < allowedJoins.length; i++) {
/* istanbul ignore else */
if (joinOptions[allowedJoins[i]].eager) {
const cond = parsed.join.find((j) => j && j.field === allowedJoins[i]) || {
field: allowedJoins[i],
};
this.setJoin(cond, joinOptions, builder);
eagerJoins[allowedJoins[i]] = true;
}
}
if (isArrayFull(parsed.join)) {
parseQuery(query) {
if (util_1.isObject(query)) {
const paramNames = util_1.objKeys(query);
if (util_1.hasLength(paramNames)) {
this._query = query;
this._paramNames = paramNames;
this.fields =
this.parseQueryParam('fields', this.fieldsParser.bind(this))[0] || [];
this.filter = this.parseQueryParam('filter', this.conditionParser.bind(this, 'filter'));
this.or = this.parseQueryParam('or', this.conditionParser.bind(this, 'or'));
this.join = this.parseQueryParam('join', this.joinParser.bind(this));
this.sort = this.parseQueryParam('sort', this.sortParser.bind(this));
this.limit = this.parseQueryParam('limit', this.numericParser.bind(this, 'limit'))[0];
this.offset = this.parseQueryParam('offset', this.numericParser.bind(this, 'offset'))[0];
this.page = this.parseQueryParam('page', this.numericParser.bind(this, 'page'))[0];
this.cache = this.parseQueryParam('cache', this.numericParser.bind(this, 'cache'))[0];
}
}
return this;
'lt',
'gte',
'lte',
'starts',
'ends',
'cont',
'excl',
'in',
'notin',
'isnull',
'notnull',
'between',
];
export const comparisonOperatorsList = [
...deprecatedComparisonOperatorsList,
...objKeys(CondOperator).map((n) => CondOperator[n]),
];
export const sortOrdersList = ['ASC', 'DESC'];
const comparisonOperatorsListStr = comparisonOperatorsList.join();
const sortOrdersListStr = sortOrdersList.join();
export function validateFields(fields: QueryFields): void {
if (!isArrayStrings(fields)) {
throw new RequestQueryException('Invalid fields. Array of strings expected');
}
}
export function validateCondition(
val: QueryFilter,
cond: 'filter' | 'or' | 'search',
prepareEntityBeforeSave(dto, paramsFilter) {
if (!util_1.isObject(dto)) {
return undefined;
}
if (util_1.hasLength(paramsFilter)) {
for (const filter of paramsFilter) {
dto[filter.field] = filter.value;
}
}
if (!util_1.hasLength(util_1.objKeys(dto))) {
return undefined;
}
return dto instanceof this.entityType ? dto : class_transformer_1.plainToClass(this.entityType, dto);
}
hasColumn(column) {
private prepareEntityBeforeSave(dto: T, paramsFilter: QueryFilter[]): T {
if (!isObject(dto)) {
return undefined;
}
if (hasLength(paramsFilter)) {
for (const filter of paramsFilter) {
dto[filter.field] = filter.value;
}
}
if (!hasLength(objKeys(dto))) {
return undefined;
}
return dto instanceof this.entityType ? dto : plainToClass(this.entityType, dto);
}