/** * @swagger * tags: * name: Update * description: Endpoint for updating region specific data. Only for manual use in the prototype application! */ const router = require("express").Router(); // Models const handleClimateUpdate = require("../models/handleClimateUpdate.js") const handleClimateUpdateV2 = require("../models/handleClimateUpdateV2.js") const handleUpdateRegionNearby = require("../models/handleUpdateRegionNearby.js") const handleUpdateRegionNearbyById = require("../models/handleUpdateRegionNearbyById.js") const handleUpdateRegionNearbyImgUrl = require("../models/handleUpdateRegionNearbyImgUrl.js") const handleUpdateRegionNearbyImgUrlById = require("../models/handleUpdateRegionNearbyImgUrlById.js") // Utils const sqlSanitzer = require("../util/sqlstring_sanitizer.js") module.exports = dbConn => { /** * @swagger * /update/climate/v1: * put: * summary: Pull monthly data from meteostat API V1 * tags: [Update] * responses: * "200": * description: Update information is logged in backend */ router.put("/api/v1/update/climate/v1", async (req, res) => { const update = await handleClimateUpdate(dbConn) res.json(update) }); /** * @swagger * /update/climate/v2: * put: * summary: Pull daily data from meteostat API V2. Data is written to Travopti database and must be processed manually before it can be used. * tags: [Update] * responses: * "200": * description: Update information is logged in backend */ router.put("/api/v1/update/climate/v2", async (req, res) => { const update = await handleClimateUpdateV2(dbConn) res.json(update) }); /** * @swagger * /update/regions/all/nearby: * put: * summary: Updates all nearby data for all regions * tags: [Update] * responses: * "200": * description: Updates all nearby data for all regions */ router.put("/api/v1/update/regions/all/nearby", async (req, res) => { res.json(await handleUpdateRegionNearby(dbConn)) }); /** * @swagger * /update/regions/all/lonlat: * put: * summary: Updates all coordinate data for all regions * tags: [Update] * responses: * "200": * description: Updates all coordinate data for all regions */ router.put("/api/v1/update/regions/all/lonlat", async (req,res) => { res.json(await handleRegionLonLat(dbConn)) }); /** * @swagger * /update/regions/all/nearby/image: * put: * summary: Updates the nearby image urls for all regions * tags: [Update] * responses: * "200": * description: Updates the nearby image urls for all regions */ router.put("/api/v1/update/regions/all/nearby/image", async (req, res) => { res.json(await handleUpdateRegionNearbyImgUrl(dbConn)) }); /** * @swagger * /update/regions/{id}/nearby: * put: * summary: Updates the nearby data for a specific region * tags: [Update] * parameters: * - name: "id" * in: "path" * required: true * type: int * responses: * "200": * description: Updates the nearby data for a specific region */ router.put("/api/v1/update/regions/:id/nearby", async (req, res) => { const id = sqlSanitzer(req.params.id); res.json(await handleUpdateRegionNearbyById(dbConn, id)) }); /** * @swagger * /update/regions/{id}/nearby/image: * put: * summary: Updates the nearby image urls for a specific region * tags: [Update] * parameters: * - name: "id" * in: "path" * required: true * type: int * responses: * "200": * description: Updates the nearby image urls for a specific region */ router.put("/api/v1/update/regions/:id/nearby/image", async (req, res) => { const id = sqlSanitzer(req.params.id); res.json(await handleUpdateRegionNearbyImgUrlById(dbConn, id)) }); return router }