Skip to content

Commit

Permalink
Moved updateResults function to a static method of Location
Browse files Browse the repository at this point in the history
  • Loading branch information
cmccormack committed Jun 11, 2018
1 parent 9245f14 commit b9ddf93
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions models/Location.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ const locationSchema = new mongoose.Schema({
},],
})

locationSchema.methods.goingCount = function() {
console.log("location.going.length: " + this.going.length)
return this.going.length


locationSchema.statics.updateResults = function(results) {
return this.find({ id: { $in: results, }, })
.populate("going", "twitter.displayName")
}

const Location = mongoose.model("Location", locationSchema, "locations")
Expand Down
5 changes: 3 additions & 2 deletions routes/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ module.exports = () => {
// Return db entries based on received Location IDs
///////////////////////////////////////////////////////////
router.post("/updatedresults", async (req, res, next) => {
if (!req.body) return next(Error("Must supply array of locations"))

const { resultIds, } = req.body
const updates = await Location.updateResults(resultIds)

const updates = await Location.find({ id: { $in: resultIds,},})
console.log(updates)
res.json({success: true, updates,})
})

Expand Down

0 comments on commit b9ddf93

Please sign in to comment.