Created
June 17, 2018 05:48
-
-
Save Ketcap/9daf1eefa2cd680eaf4cffbf92273d0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const CreateUserSearchQuery = (query) => { | |
let search1 = { $or: [] }; | |
let search2 = { $or: [] }; | |
let searchQuery = []; | |
if (!!query.text) { | |
search1['$or'].push({ 'profile.name': { $regex: query.text, $options: 'i' } }); | |
search1['$or'].push({ 'profile.surname': { $regex: query.text, $options: 'i' } }) | |
search1['$or'].push({ 'username': { $regex: query.text, $options: 'i' } }) | |
searchQuery.push(search1); | |
} | |
if (!!query.role && query.role !== 'all') { | |
search2['$or'].push({ 'roles': { $in: [query.role] } }) | |
searchQuery.push(search2); | |
} | |
if (query.role === 'all') { | |
const role = Meteor.user().roles[0]; | |
search2['$or'].push({ 'roles': { $in: RolesReach[role].map(e => e.id) } }); | |
searchQuery.push(search2) | |
} | |
if (!AlaningRoles.userIsInRole(Meteor.userId(), 'admin')) { | |
const query = { companyId: { $in: [Meteor.user().companyId] } }; | |
searchQuery.push(query) | |
} | |
return { | |
_id: { $ne: Meteor.userId() }, | |
$and: searchQuery | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment