Created
June 12, 2019 09:52
-
-
Save pi0/024947406b13f50761d2db34aa5fc20d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function substractIdArrays(a, b) { | |
return a.filter(x => !b.find(y => y + '' === x + '')) | |
} | |
async function updateArea(areaCode) { | |
const area = await Area.findOne({ areaCode }) | |
const associatedHotels = await Hotel.find({ areaCode }).then(hotels => hotels.map(h => h._id)) | |
const hotelsInArea = await Hotel.find({ | |
location: { | |
$geoWithin: { | |
$geometry: area.polygon | |
} | |
} | |
}).then(hotels => hotels.map(h => h._id)) | |
const hotelsToAdd = substractIdArrays(hotelsInArea, associatedHotels) | |
const hotelsToRemove = substractIdArrays(associatedHotels, hotelsInArea) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment