34 lines
999 B
JavaScript
34 lines
999 B
JavaScript
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
|
|
}
|