Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// search: {$and: [{}, {}, ...]}
else {
this.builderAddBrackets(
builder,
condition,
new Brackets((qb: any) => {
search.$and.forEach((item: any) => {
this.setSearchCondition(qb, item, '$and');
});
}),
);
}
}
// search: {$or: [...], ...}
else if (isArrayFull(search.$or)) {
// search: {$or: [...]}
if (keys.length === 1) {
// search: {$or: [{}]}
if (search.$or.length === 1) {
this.setSearchCondition(builder, search.$or[0], condition);
}
// search: {$or: [{}, {}, ...]}
else {
this.builderAddBrackets(
builder,
condition,
new Brackets((qb: any) => {
search.$or.forEach((item: any) => {
this.setSearchCondition(qb, item, '$or');
});
}),
parseQueryParam(type, parser) {
const param = this.getParamNames(type);
if (util_1.isArrayFull(param)) {
return param.reduce((a, name) => [...a, ...this.getParamValues(this._query[name], parser)], []);
}
return [];
}
parseValue(val) {
private canCreateRoute(name: string) {
const only = this.options.routes.only;
const exclude = this.options.routes.exclude;
if (isArrayFull(only)) {
return only.some((route) => route === name);
}
if (isArrayFull(exclude)) {
return !exclude.some((route) => route === name);
}
return true;
}
private getParamValues(value: string | string[], parser: Function): string[] {
if (isStringFull(value)) {
return [parser.call(this, value)];
}
if (isArrayFull(value)) {
return (value as string[]).map((val) => parser(val));
}
return [];
}
async createBuilder(parsed, options, many = true) {
const builder = this.repo.createQueryBuilder(this.alias);
const select = this.getSelect(parsed, options.query);
builder.select(select);
if (util_1.isArrayFull(options.query.filter)) {
for (let i = 0; i < options.query.filter.length; i++) {
this.setAndWhere(options.query.filter[i], `optionsFilter${i}`, builder);
}
}
const filters = [...parsed.paramsFilter, ...parsed.filter];
const hasFilter = util_1.isArrayFull(filters);
const hasOr = util_1.isArrayFull(parsed.or);
if (hasFilter && hasOr) {
if (filters.length === 1 && parsed.or.length === 1) {
this.setOrWhere(filters[0], `filter0`, builder);
this.setOrWhere(parsed.or[0], `or0`, builder);
}
else if (filters.length === 1) {
this.setAndWhere(filters[0], `filter0`, builder);
builder.orWhere(new typeorm_1.Brackets((qb) => {
for (let i = 0; i < parsed.or.length; i++) {
this.setAndWhere(parsed.or[i], `or${i}`, qb);
}
}));
}
else if (parsed.or.length === 1) {
this.setAndWhere(parsed.or[0], `or0`, builder);
}
}
const joinOptions = options.query.join || {};
const allowedJoins = util_1.objKeys(joinOptions);
if (util_1.hasLength(allowedJoins)) {
let eagerJoins = {};
for (let i = 0; i < allowedJoins.length; i++) {
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 (util_1.isArrayFull(parsed.join)) {
for (let i = 0; i < parsed.join.length; i++) {
if (!eagerJoins[parsed.join[i].field]) {
this.setJoin(parsed.join[i], joinOptions, builder);
}
}
}
}
if (many) {
const sort = this.getSort(parsed, options.query);
builder.orderBy(sort);
const take = this.getTake(parsed, options.query);
if (isFinite(take)) {
builder.take(take);
}
const skip = this.getSkip(parsed, take);
if (isFinite(skip)) {
async createBuilder(parsed, options, many = true) {
const builder = this.repo.createQueryBuilder(this.alias);
const select = this.getSelect(parsed, options.query);
builder.select(select);
if (util_1.isArrayFull(options.query.filter)) {
for (let i = 0; i < options.query.filter.length; i++) {
this.setAndWhere(options.query.filter[i], `optionsFilter${i}`, builder);
}
}
const filters = [...parsed.paramsFilter, ...parsed.filter];
const hasFilter = util_1.isArrayFull(filters);
const hasOr = util_1.isArrayFull(parsed.or);
if (hasFilter && hasOr) {
if (filters.length === 1 && parsed.or.length === 1) {
this.setOrWhere(filters[0], `filter0`, builder);
this.setOrWhere(parsed.or[0], `or0`, builder);
}
else if (filters.length === 1) {
this.setAndWhere(filters[0], `filter0`, builder);
builder.orWhere(new typeorm_1.Brackets((qb) => {
for (let i = 0; i < parsed.or.length; i++) {