Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public getParamFilters(parsed: CrudRequest['parsed']): ObjectLiteral {
let filters = {};
/* istanbul ignore else */
if (hasLength(parsed.paramsFilter)) {
for (const filter of parsed.paramsFilter) {
filters[filter.field] = filter.value;
}
}
return filters;
}
public async createMany(
req: CrudRequest,
dto: CreateManyDto>,
): Promise {
/* istanbul ignore if */
if (!isObject(dto) || !isArrayFull(dto.bulk)) {
this.throwBadRequestException(`Empty data. Nothing to save.`);
}
const bulk = dto.bulk
.map((one) => this.prepareEntityBeforeSave(one, req.parsed))
.filter((d) => !isUndefined(d));
/* istanbul ignore if */
if (!hasLength(bulk)) {
this.throwBadRequestException(`Empty data. Nothing to save.`);
}
return this.repo.save(bulk, { chunk: 50 });
}
{
$or: [
parser.convertFilterToSearch(parser.filter[0]),
parser.convertFilterToSearch(parser.or[0]),
],
},
]
: [
{
$or: [
{ $and: parser.filter.map(parser.convertFilterToSearch) },
{ $and: parser.or.map(parser.convertFilterToSearch) },
],
},
];
} else if (hasLength(parser.filter)) {
search = parser.filter.map(parser.convertFilterToSearch);
} else {
if (hasLength(parser.or)) {
search =
parser.or.length === 1
? [parser.convertFilterToSearch(parser.or[0])]
: /* istanbul ignore next */ [
{
$or: parser.or.map(parser.convertFilterToSearch),
},
];
}
}
return [...paramsSearch, ...optionsFilter, ...search];
}
getFields() {
if (!util_1.hasLength(this._fields)) {
return '';
}
const param = this.getParamName('fields');
const value = this._fields.join(this.options.delimStr);
return `${param}=${value}&`;
}
getCondition(cond) {
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);
}
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;
}