Skip to content

Instantly share code, notes, and snippets.

@johanbrook
Created January 12, 2016 17:30
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 johanbrook/c332f43161b75726d02f to your computer and use it in GitHub Desktop.
Save johanbrook/c332f43161b75726d02f to your computer and use it in GitHub Desktop.
const updateNightclub = (req, res, next) => {
const nightclubId = req.params.id;
const {value} = req.body;
console.log(nightclubId, value);
Nightclubs.methods.updateVisitors.call({nightclubId, value}, (err, result) => {
const response = {
code: 200
};
if (err) {
console.log(err)
return JsonRoutes.sendResult(res, {
data: {message: "There was an error"},
code: 500
});
}
if (result === 1) {
response.data = {
message: "Success",
nightclub: Nightclubs.findOne(nightclubId),
value: 1
};
} else if (result === -1) {
response.data = {
message: "Success",
nightclub: Nightclubs.findOne(nightclubId),
value: -1
};
} else {
response.code = 404;
response.data = {
message: "Did not find a nightclub with that ID",
nightclubId: nightclubId,
value: 0
};
}
console.log(response);
JsonRoutes.sendResult(res, response);
});
};
JsonRoutes.add('put', 'nightclubs/:id', updateNightclub);
Nightclubs.methods.updateVisitors = new ValidatedMethod(/* ... */);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment