|
@@ -183,29 +183,36 @@ export default {
|
|
getData: isAdminRequired(async function getSet(session, page, pageSize, properties, sort, queries, operator, cb) {
|
|
getData: isAdminRequired(async function getSet(session, page, pageSize, properties, sort, queries, operator, cb) {
|
|
const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" }, this);
|
|
const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" }, this);
|
|
|
|
|
|
- const newQueries = queries.map(query => {
|
|
|
|
- const { data, filter, filterType } = query;
|
|
|
|
- const newQuery = {};
|
|
|
|
- if (filterType === "regex") {
|
|
|
|
- newQuery[filter.property] = new RegExp(`${data.slice(1, data.length - 1)}`, "i");
|
|
|
|
- } else if (filterType === "contains") {
|
|
|
|
- newQuery[filter.property] = new RegExp(`${data.replaceAll(/[.*+?^${}()|[\]\\]/g, "\\$&")}`, "i");
|
|
|
|
- } else if (filterType === "exact") {
|
|
|
|
- newQuery[filter.property] = data.toString();
|
|
|
|
- }
|
|
|
|
- return newQuery;
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- const queryObject = {};
|
|
|
|
- if (newQueries.length > 0) {
|
|
|
|
- if (operator === "and") queryObject.$and = newQueries;
|
|
|
|
- else if (operator === "or") queryObject.$or = newQueries;
|
|
|
|
- else if (operator === "nor") queryObject.$nor = newQueries;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
async.waterfall(
|
|
async.waterfall(
|
|
[
|
|
[
|
|
next => {
|
|
next => {
|
|
|
|
+ const newQueries = queries.map(query => {
|
|
|
|
+ const { data, filter, filterType } = query;
|
|
|
|
+ const newQuery = {};
|
|
|
|
+ if (filterType === "regex") {
|
|
|
|
+ newQuery[filter.property] = new RegExp(`${data.slice(1, data.length - 1)}`, "i");
|
|
|
|
+ } else if (filterType === "contains") {
|
|
|
|
+ newQuery[filter.property] = new RegExp(
|
|
|
|
+ `${data.replaceAll(/[.*+?^${}()|[\]\\]/g, "\\$&")}`,
|
|
|
|
+ "i"
|
|
|
|
+ );
|
|
|
|
+ } else if (filterType === "exact") {
|
|
|
|
+ newQuery[filter.property] = data.toString();
|
|
|
|
+ }
|
|
|
|
+ return newQuery;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ const queryObject = {};
|
|
|
|
+ if (newQueries.length > 0) {
|
|
|
|
+ if (operator === "and") queryObject.$and = newQueries;
|
|
|
|
+ else if (operator === "or") queryObject.$or = newQueries;
|
|
|
|
+ else if (operator === "nor") queryObject.$nor = newQueries;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ next(null, queryObject);
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ (queryObject, next) => {
|
|
const invalidProperties = [...properties, ...queries.map(query => query.filter.property)].find(
|
|
const invalidProperties = [...properties, ...queries.map(query => query.filter.property)].find(
|
|
property => {
|
|
property => {
|
|
if (
|
|
if (
|
|
@@ -225,16 +232,16 @@ export default {
|
|
}
|
|
}
|
|
);
|
|
);
|
|
if (invalidProperties) next("Invalid paramaters given.");
|
|
if (invalidProperties) next("Invalid paramaters given.");
|
|
- else next();
|
|
|
|
|
|
+ else next(null, queryObject);
|
|
},
|
|
},
|
|
|
|
|
|
- next => {
|
|
|
|
|
|
+ (queryObject, next) => {
|
|
userModel.find(queryObject).count((err, count) => {
|
|
userModel.find(queryObject).count((err, count) => {
|
|
- next(err, count);
|
|
|
|
|
|
+ next(err, queryObject, count);
|
|
});
|
|
});
|
|
},
|
|
},
|
|
|
|
|
|
- (count, next) => {
|
|
|
|
|
|
+ (queryObject, count, next) => {
|
|
userModel
|
|
userModel
|
|
.find(queryObject)
|
|
.find(queryObject)
|
|
.sort(sort)
|
|
.sort(sort)
|