Display travels per day and display better marks on the map
This commit is contained in:
@ -20,15 +20,30 @@ app.get("/api", (req, res) => {
|
||||
|
||||
app.get("/api/airports", (req, res) => {
|
||||
const search = req.query.search.toLowerCase()
|
||||
let where = {}
|
||||
let options = {}
|
||||
|
||||
if (search) {
|
||||
let or_array = []
|
||||
for (let col_name of ['name', 'icao_code', 'iata_code'])
|
||||
or_array.push(db.sequelize.where(db.sequelize.fn('lower', db.sequelize.col(col_name)),
|
||||
{[db.Sequelize.Op.like]: `%${search}%`}))
|
||||
where = {[db.Sequelize.Op.or]: or_array}
|
||||
options.where = {[db.Sequelize.Op.or]: or_array}
|
||||
}
|
||||
Airport.findAll({where: where}).then(airports => res.json(airports))
|
||||
|
||||
options.limit = 10
|
||||
if (req.query.limit) {
|
||||
const limit = parseInt(req.query.limit)
|
||||
if (limit >= 1)
|
||||
options.limit = limit
|
||||
}
|
||||
|
||||
if (req.query.page) {
|
||||
const page = parseInt(req.query.page)
|
||||
if (page > 1)
|
||||
options.offset = (page - 1) * options.limit
|
||||
}
|
||||
|
||||
Airport.findAll(options).then(airports => res.json(airports))
|
||||
})
|
||||
|
||||
app.get("/api/airport/:icao_code", (req, res) => {
|
||||
@ -43,7 +58,7 @@ app.get("/api/airport/:icao_code", (req, res) => {
|
||||
|
||||
app.get("/api/flights/:dep_icao", (req, res) => {
|
||||
const dep_icao = req.params.dep_icao
|
||||
Flight.findAll({where: {dep_icao: dep_icao}}).then(data => {
|
||||
Flight.findAll({order: [['dep_time_utc']], where: {dep_icao: dep_icao}}).then(data => {
|
||||
if (data)
|
||||
res.json(data)
|
||||
else
|
||||
@ -54,7 +69,7 @@ app.get("/api/flights/:dep_icao", (req, res) => {
|
||||
app.get("/api/flights/:dep_icao/:arr_icao", (req, res) => {
|
||||
const dep_icao = req.params.dep_icao
|
||||
const arr_icao = req.params.arr_icao
|
||||
Flight.findAll({where: {dep_icao: dep_icao, arr_icao: arr_icao}}).then(data => {
|
||||
Flight.findAll({order: [['dep_time_utc']], where: {dep_icao: dep_icao, arr_icao: arr_icao}}).then(data => {
|
||||
if (data)
|
||||
res.json(data)
|
||||
else
|
||||
|
Reference in New Issue
Block a user