Refactoring and adding flight schedule routes
Before we start creating the customer interface for purchasing a boarding ticket, we will need to make several adjustments to our code base. Let us begin by creating a new file located at routes/airplanes.js
and moving the app.post('/airplanes', …)
and app.get('/airplanes/:id', …)
blocks into that file as follows:
async function getAirplane(req, res) { const airplane = await models.Airplane.findByPk (req.params.id); if (!airplane) { return res.sendStatus(404); } res.json(airplane); } exports.getAirplane = getAirplane;
This route will return an Airplane
model record based on the primary key, which is defined in Express’ Request object (indicated by the :id
symbol). If there were no records to be found, then we will return...