Skip to content

Commit

Permalink
"completed search controller and router, need to test it with front end
Browse files Browse the repository at this point in the history
  • Loading branch information
fullstackfrench committed Jan 8, 2025
1 parent 2723325 commit 5b2aef1
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions server/controllers/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,32 @@ const companyController = {
next(error)
}
},
searchCompany: async (req, res, next ) => {
let companies = await Company.aggregate([

])
searchCompany: async (req, res, next) => {
try {
let companies = await Company.aggregate([
{
$search: {
index: "kinfolk-search",
text: {
query: req.body.search,
path: {
wildcard: "*"
}
}
}
}
]);
// if (companies.length === 1) {
// // If exactly one company matches, return it
// res.json({ redirect: true, company: companies[0] });
// } else {
// // Otherwise, return the list of companies
// res.json({ redirect: false, companies });
// }
res.json(companies); // Send the companies data as JSON response
} catch (error) {
next(error); // Handle errors appropriately
}
}
}

Expand Down

0 comments on commit 5b2aef1

Please sign in to comment.