Add Endpoint for Reloading Imgurl for speicific place
This commit is contained in:
parent
3dece30145
commit
df083fd78e
33
backend/models/handleUpdateRegionNearbyImgUrlById.js
Normal file
33
backend/models/handleUpdateRegionNearbyImgUrlById.js
Normal file
@ -0,0 +1,33 @@
|
||||
const getRegionNearbyById = require("../models/getRegionNearbyById.js")
|
||||
const getPlacePhoto = require("../models/getPlacePhoto.js")
|
||||
|
||||
module.exports = async (dbConn,id) => {
|
||||
try {
|
||||
const region_ids = await dbConn.query(`
|
||||
SELECT distinct region_id
|
||||
FROM regions_nearby
|
||||
WHERE region_id = ?`,
|
||||
[id])
|
||||
|
||||
|
||||
for (let region_id of region_ids) {
|
||||
const nearby = await getRegionNearbyById(dbConn, region_id.region_id)
|
||||
|
||||
for (let place of nearby) {
|
||||
const url = await getPlacePhoto(place.photo_reference)
|
||||
|
||||
console.log("# Setting image Url:", region_id, place.place_name, url)
|
||||
|
||||
await dbConn.query(`
|
||||
UPDATE regions_nearby
|
||||
SET img_url = "${url}"
|
||||
WHERE id = ${place.place_id}`)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
|
||||
const res = "region nearby img url update finished"
|
||||
return res
|
||||
}
|
||||
@ -6,6 +6,7 @@ const getRegionNearbyById = require("../models/getRegionNearbyById.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")
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const _ = require('lodash')
|
||||
@ -52,5 +53,9 @@ module.exports = dbConn => {
|
||||
router.patch("/api/v1/regions/update/nearby_imgurl", async (req,res) => {
|
||||
res.json(await handleUpdateRegionNearbyImgUrl(dbConn))
|
||||
});
|
||||
|
||||
router.patch("/api/v1/regions/update/nearby_imgurl/:id", async (req,res) => {
|
||||
res.json(await handleUpdateRegionNearbyImgUrlById(dbConn, req.params.id))
|
||||
});
|
||||
return router;
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user