Skip to content

Instantly share code, notes, and snippets.

@pi0
Created June 12, 2019 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pi0/024947406b13f50761d2db34aa5fc20d to your computer and use it in GitHub Desktop.
Save pi0/024947406b13f50761d2db34aa5fc20d to your computer and use it in GitHub Desktop.
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