Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | 2x 2x 2x 2x 2x 2x 2x 2x | const Airport = require("../models/airport.model.js"); const { body, validationResult } = require('express-validator') exports.search = (req, res) => { const errors = validationResult(req); if (!errors.isEmpty()) { console.log(errors.array()); return res.status(422).json({ errors: errors.array() }); } var term = req.body.term; Airport.search(term, (err, data) => { if (err) { if (err.kind === "not_found") { res.status(404).send({ message: `Not found Airport with term ${term}.` }); } else { res.status(500).send({ message: "Error retrieving Airport with term " + term }); } } else res.send(data); }); }; exports.get = (req, res) => { Airport.get((err, data) => { if (err) { if (err.kind === "not_found") { res.status(404).send({ message: `No Airport found` }); } else { res.status(500).send({ message: "Error retrieving Airport" }); } } else res.send(data); }); }; exports.getByID = (req, res) => { var airportID = req.params.airportID; if (!airportID) { console.log("airportID is empty"); return res.status(422).json({ errors: "airportID is empty" }); } Airport.getByID(airportID, (err, data) => { if (err) { if (err.kind === "not_found") { res.status(404).send({ message: `No Airport found` }); } else { res.status(500).send({ message: "Error retrieving Airport" }); } } else res.send(data); }); }; exports.validate = (method) => { switch (method) { case 'search': { return [ body('term', "term is empty").exists(), ] } } }; |