Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
});
andParams.push({
and: manualAnd
});
}
finalQuery = {
where: {
and: andParams
}
};
}
// Merging the query formed with the existing query if any.
mergeQuery(ctx.query, finalQuery);
log.debug(ctx.options, 'Final formed query', JSON.stringify(ctx.query));
next();
}
query[key] = regexObj;
mergeQuery(ctx.query, {
where: query
});
} else {
for (let i = 0; i <= depth; i++) {
query = {};
if (i === 0) {
modifiedRegex = `${regexString}$`;
} else {
modifiedRegex = `${modifiedRegex.substr(0, modifiedRegex.length - 1)}[[:alnum:]]*,$`;
}
query[key] = toRegExp(modifiedRegex);
orParms.push(query);
}
mergeQuery(ctx.query, {
where: {
or: orParms
}
});
}
} else {
if (depth === '*') {
depth = regexString.split(',').length - 2;
}
for (let j = 0; j <= depth; j++) {
query = {};
if (j === 0) {
modifiedRegex = `${regexString}$`;
} else {
const hierarchyArray = modifiedRegex.split(',');
hierarchyArray.splice(hierarchyArray.length - 2, 1);
for (let j = 0; j <= depth; j++) {
query = {};
if (j === 0) {
modifiedRegex = `${regexString}$`;
} else {
const hierarchyArray = modifiedRegex.split(',');
hierarchyArray.splice(hierarchyArray.length - 2, 1);
modifiedRegex = hierarchyArray.join();
}
if (modifiedRegex === ',$' || modifiedRegex === '$') {
break;
}
query[key] = toRegExp(modifiedRegex);
orParms.push(query);
}
mergeQuery(ctx.query, {
where: {
or: orParms
}
});
}
}
Model.checkIdempotencyForDelete = function modelCheckIdempotencyForDeletecb(context, cb) {
var filter;
if (context.id) {
filter = { where: context.where, fetchDeleted: true };
Model.findOne(filter, context.options, function modelFindOnecb(err, res) {
if (err) {
return cb(err);
}
if (res) {
return cb(err, { count: 1 });
}
return cb();
});
} else if (context.options && context.options.requestId) {
filter = { where: context.where, fetchDeleted: true };
mergeQuery(filter, {
where: {
_requestId: context.options.requestId
}
});
Model.find(filter, context.options, function modelFindcb(err, res) {
if (err) {
return cb(err);
}
if (res.length > 0) {
return cb(err, { count: res.length });
}
return cb();
});
} else {
return cb();
}
Object.keys(filterUsed).forEach(function filterUsedForEach(group) {
if (filterUsed[group].length === 1) {
mergeQuery(filter, {
'where': {
'and': filterUsed[group]
}
});
} else {
mergeQuery(filter, {
'where': {
'or': filterUsed[group]
}
});
}
});
function addLbFiltertoCtx(ctx, filter, cb) {
ctx.args.filter = ctx.args.filter || {};
mergeQuery(ctx.args.filter, filter);
cb();
}
function addSoftDeleteFilter(ctx, next) {
if (!ctx.Model.settings._softDelete) {
return next();
}
ctx.query = ctx.query || {};
if (ctx.query.fetchDeleted) {
mergeQuery(ctx.query, {
where: {
_isDeleted: true
}
});
} else {
mergeQuery(ctx.query, {
where: {
_isDeleted: false
}
});
}
next();
}