Skip to content

Instantly share code, notes, and snippets.

@LazyFatArrow
Last active May 30, 2019 00:00
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 LazyFatArrow/97d15500fc62de8bb03f4d64127c74b8 to your computer and use it in GitHub Desktop.
Save LazyFatArrow/97d15500fc62de8bb03f4d64127c74b8 to your computer and use it in GitHub Desktop.
import Poll from '../models/poll.model'
export function create(data) {
return Poll.create(data)
}
export function findAll() {
return Poll.find().sort({ createdAt: -1 })
}
export function voteOnPoll(optionId) {
return Poll.findOneAndUpdate({
'options._id': optionId,
}, {
$inc: {
'options.$.votes': 1,
},
}, {
new: true,
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment