Do not return deleted users
MODIFY
src/storage/mongodb/UserStorage.ts
src/storage/mongodb/UserStorage.ts
@@ -474,19 +474,21 @@ export default class UserStorage {
// Check Skip
dbParams.skip = Utils.checkRecordSkip(dbParams.skip);
const filters: FilterParams = {
- '$or': DatabaseUtils.getNotDeletedFilter()
+ '$and': [{ '$or': DatabaseUtils.getNotDeletedFilter() }]
};
// Create Aggregation
const aggregation = [];
// Filter
if (params.search) {
const searchRegex = Utils.escapeSpecialCharsInRegex(params.search);
- filters.$or = [
+ filters.$and.push({
+ '$or': [
{ 'name': { $regex: searchRegex, $options: 'i' } },
{ 'firstName': { $regex: searchRegex, $options: 'i' } },
{ 'email': { $regex: searchRegex, $options: 'i' } },
{ 'plateID': { $regex: searchRegex, $options: 'i' } }
- ];
+ ]
+ });
}
// Users
if (!Utils.isEmptyArray(params.userIDs)) {
@@ -536,12 +538,14 @@ export default class UserStorage {
}
// Select non-synchronized billing data
if (params.notSynchronizedBillingData) {
- filters.$or = [
+ filters.$and.push({
+ '$or': [
{ 'billingData': { '$exists': false } },
{ 'billingData.lastChangedOn': { '$exists': false } },
{ 'billingData.lastChangedOn': null },
{ $expr: { $gt: ['$lastChangedOn', '$billingData.lastChangedOn'] } }
- ];
+ ]
+ });
}
// Add filters
aggregation.push({
@@ -659,20 +663,22 @@ export default class UserStorage {
// Mongodb aggregation creation
const aggregation = [];
// Mongodb filter block ($match)
- const match: any = { '$or': DatabaseUtils.getNotDeletedFilter() };
+ const match: any = { '$and': [{ '$or': DatabaseUtils.getNotDeletedFilter() }] };
match.issuer = true;
if (params.roles) {
match.role = { '$in': params.roles };
}
if (params.search) {
const searchRegex = Utils.escapeSpecialCharsInRegex(params.search);
- match.$or = [
+ match.$and.push({
+ '$or': [
{ 'name': { $regex: searchRegex, $options: 'i' } },
{ 'firstName': { $regex: searchRegex, $options: 'i' } },
{ 'tags.id': { $regex: searchRegex, $options: 'i' } },
{ 'email': { $regex: searchRegex, $options: 'i' } },
- { 'plateID': { $regex: searchRegex, $options: 'i' } }
- ];
+ { 'plateID': { $regex: searchRegex, $options: 'i' } }]
+ }
+ );
}
aggregation.push({ $match: match });
// Mongodb Lookup block

Do not return deleted users