flightController.js
module.exports = {
findAll: (req, res) => {
let ans = flights
if (req.query.departure_times) {
ans = ans.filter((el) => {
return el.departure_times.includes(req.query.departure_times)
})
}
if (req.query.arrival_times) {
ans = ans.filter((el) => {
return el.arrival_times.includes(req.query.arrival_times)
})
}
if (req.query.destination) {
ans = flights.filter((el) => {
return el.destination.includes(req.query.destination)
})
}
if (req.query.departure) {
ans = ans.filter((el) => {
return el.departure.includes(req.query.departure)
})
}
return res.json(ans);
},
findById: (req, res) => {
let ans = flights
if (req.params.id) {
return res.json(ans.filter((el) => {
return el.uuid.includes(req.params.id)
}))
}
},
bookController.js
let booking = [];
module.exports = {
findById: (req, res) => {
if (req.query.flight_uuid) {
let ans = booking.filter((el) => {
return el.flight_uuid.includes(req.query.flight_uuid)
})
return res.status(200).json(ans)
}
if (req.query.phone) {
let ans = booking.filter((el) => {
return el.phone.includes(req.query.phone)
})
return res.status(200).json(...ans)
}
return res.status(200).json(booking);
},
create: (req, res) => {
if ('flight_uuid' in req.body) {
booking.push(req.body)
}
else {
return res.status(400)
}
return res.status(201).json({});
},
deleteById: (req, res) => {
if (req.query.phone) {
booking = booking.filter((el) => {
return !(el.phone.includes(req.query.phone))
})
}
return res.status(200).json(booking);
}
};