Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add PROMO server-side validation route #2318

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

m-amaya
Copy link
Contributor

@m-amaya m-amaya commented May 11, 2016

No description provided.

@m-amaya m-amaya added the RFR label May 11, 2016
@m-amaya m-amaya self-assigned this May 11, 2016

var where = { promo_code };

db.promos.findOne( where, (err, result) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works nicely, but I think we can make it even better by consolidating the two database calls into one by adding a join:

var where = { promo_code, 'promos_applied.order_id': order_id };

var options = {
  joins:  [ { type: 'left'
            , target: 'promos_applied'
            , on: { promo_id: '$promos.id$' }
            }
          ]
};

db.promos.findOne( where, options, (err, result) => {
  if( !result ) {
    res.error( errors.promos.DOES_NOT_EXIST );
    return;
  }

  if( result.order_id ) {
    res.error( errors.promos.ALREADY_APPLIED );
    return;
  }

  res.sendStatus(204);
});

@jrf0110
Copy link
Member

jrf0110 commented May 26, 2016

connnnnnnnnnflict

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants