Skip to content

Commit

Permalink
search api
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanField15 committed Oct 26, 2023
1 parent 3e69bf0 commit 992c9c7
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions controllers/tripController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,35 @@ exports.aliasTopTrips = (req, res, next) => {
next();
};

exports.searchAllTrips = async (req, res) => {
try {
const { origin, destination, deptDate } = req.body;
const deptDateObject = new Date(deptDate);

// Perform a database query to find trips matching the criteria
const trips = await Trip.find({
origin,
destination,
deptDate: deptDateObject,
})
.sort({ deptTime: 1 })
.limit(5);

res.status(200).json({
status: 'success',
results: trips.length,
data: {
trips,
},
});
} catch (err) {
res.status(404).json({
status: 'fail',
message: err,
});
}
};

exports.getAllTrips = async (req, res) => {
try {
// EXECUTE QUERY
Expand Down

0 comments on commit 992c9c7

Please sign in to comment.