Skip to content

Commit

Permalink
Merge pull request #172 from agiledev-students-fall2023/Loginroute
Browse files Browse the repository at this point in the history
simple search backend
  • Loading branch information
Ceiceiceii authored Dec 5, 2023
2 parents b8e6352 + 78279f9 commit 68b88b7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions back-end/src/routes/search.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import Event from '../models/Event.mjs';

const handleSearch = async (query) => {
try {
// Use regex to perform case-insensitive search on 'name' and 'location'
const results = await Event.find({
$or: [
{ name: { $regex: query, $options: 'i' } },
{ location: { $regex: query, $options: 'i' } },
],
});

return results;
} catch (error) {
console.error(error);
throw new Error('Error while searching for events');
}
};

export default handleSearch;

0 comments on commit 68b88b7

Please sign in to comment.