travopti/backend/routes/countries.js

58 lines
1.4 KiB
JavaScript

/**
* @swagger
* tags:
* name: Countries
* description: Access country data
*/
const router = require("express").Router();
// Models
const getCountries = require("../models/getCountries.js");
const getCountryById = require("../models/getCountryById.js");
// Utils
const sqlSanitzer = require("../util/sqlstring_sanitizer.js")
module.exports = dbConn => {
/**
* @swagger
* path:
* /countries:
* get:
* summary: Get all countries
* tags: [Countries]
* responses:
* "200":
* description: Returns all countries and aviable data
* content:
* application/json:
* schema:
* $ref: ''
*/
router.get("/api/v1/countries", async (req, res) => {
res.json(await getCountries(dbConn));
});
/**
* @swagger
* path:
* /countries/:id:
* get:
* summary: Get a specific country by ID
* tags: [Countries]
* responses:
* "200":
* description: Returns the selected country and aviable data
* content:
* application/json:
* schema:
* $ref: ''
*/
router.get("/api/v1/countries/:id", async (req, res) => {
const id = sqlSanitzer(req.params.id);
res.json(await getCountryById(dbConn, id))
});
return router;
};