travopti/backend/routes/place.js

84 lines
2.1 KiB
JavaScript

/**
* @swagger
* tags:
* name: Places
* description: Access to the Google Place API
*/
const router = require("express").Router()
// Models
const getPlace = require("../models/getPlace.js")
const getPlaceNearby = require("../models/getPlaceNearby.js")
const getPlacePhoto = require("../models/getPlacePhoto.js")
// Utils
const sqlSanitzer = require("../util/sqlstring_sanitizer.js")
module.exports = dbConn => {
/**
* @swagger
* path:
* /place:
* get:
* summary: Get a specific place
* tags: [Places]
* responses:
* "200":
* description: Returns a place from the google places API.
* content:
* application/json:
* schema:
* $ref: ''
*/
router.get("/api/v1/place", async (req, res) => {
const place = await getPlace(req.query.q)
res.json(place)
});
/**
* @swagger
* path:
* /place/nearby:
* get:
* summary: Get nearby places
* tags: [Places]
* responses:
* "200":
* description: Returns nearby places from the google places API.
* content:
* application/json:
* schema:
* $ref: ''
*/
router.get("/api/v1/place/nearby", async (req, res) => {
const lat = req.query.lat
const lng = req.query.lng
const place = await getPlaceNearby(lat, lng)
res.json(place)
});
/**
* @swagger
* path:
* /place/photo:
* get:
* summary: Get a photo for a place
* tags: [Places]
* responses:
* "200":
* description: Returns the matching photo for a photo_reference.
* content:
* application/json:
* schema:
* $ref: ''
*/
router.get("/api/v1/place/photo", async (req, res) => {
const photoref = req.query.photoref
const photo = await getPlacePhoto(photoref)
res.json(photo)
});
return router;
};