So I'm working on search bar function, where you can search name, email, phone, personal number, I had already name and email and it was working good, however, I added phone and personal number and I started to get these error... I can search right now phone and email, but when I try to search personal number and name I'm getting Cannot read property 'match' of null" Error from the console...
user: async () => {
const accessibleUsers = await UserController.getAccessible(req);
const userCollection = db.collection(User.tableName);
const nativeResults = await userCollection.find({
_id: { $in: accessibleUsers.map((val) => ObjectID(val)) },
vc_isLogEntity: false,
// deleted: false, //TODO RN-732 Add back
$or: [
{ email: matchRegex },
{ firstName: matchRegex },
{ lastName: matchRegex },
{ phone: matchRegex },
{ personnelNumber: matchRegex }
]
}, {_id: 1}).toArray();
const users = await User
.find(nativeResults.map(r => `${r._id}`))
.populate('role');
return users.map(user => ({
type: 'user',
value: user,
...getMatches(user, ['email', 'firstName', 'lastName', 'phone', 'personnelNumber'])
}));
I just added { phone: matchRegex },{ personnelNumber: matchRegex } and 'phone', 'personnelNumber' to the code.. Can someone help me how to avoid this error ?
I think personal Number check the spelling and check are you searching for the full name / FirstName and lastName ?