Skip to content

Instantly share code, notes, and snippets.

@johanbrook
Created January 12, 2016 17:30
Show Gist options
  • Select an option

  • Save johanbrook/c332f43161b75726d02f to your computer and use it in GitHub Desktop.

Select an option

Save johanbrook/c332f43161b75726d02f to your computer and use it in GitHub Desktop.

Revisions

  1. johanbrook created this gist Jan 12, 2016.
    45 changes: 45 additions & 0 deletions api.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    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);
    1 change: 1 addition & 0 deletions methods.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    Nightclubs.methods.updateVisitors = new ValidatedMethod(/* ... */);