daily pastebin goal
17%
SHARE
TWEET

Untitled

a guest Jun 30th, 2018 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. router.post('/services/catering', (req, res, next) => {
  2.     if (
  3.         !req.body.buyer ||
  4.         !req.body.molType ||
  5.         !Number.isInteger(req.body.cateringId) ||
  6.         !req.body.name
  7.     ) {
  8.         return next(new APIError(module, 400, 'Invalid catering'));
  9.     }
  10.  
  11.     req.details.buyer = req.body.buyer;
  12.  
  13.     const molToCheck = {
  14.         type: req.body.molType,
  15.         data: req.body.buyer,
  16.         blocked: false
  17.     };
  18.  
  19.     req.app.locals.models.MeanOfLogin.where(molToCheck)
  20.         .fetch({
  21.             withRelated: ['user']
  22.         })
  23.         .then(mol => (mol ? mol.toJSON() : null))
  24.         .then(mol => {
  25.             if (!mol || !mol.user || !mol.user.id) {
  26.                 // Don't create a new account if the card was already assigned
  27.                 if (!req.event.useCardData) {
  28.                     return Promise.reject(new APIError(module, 400, 'Invalid buyer'));
  29.                 }
  30.  
  31.                 return createUser(
  32.                     req.app.locals.models,
  33.                     req.event,
  34.                     req.user,
  35.                     req.point,
  36.                     {},
  37.                     [],
  38.                     [molToCheck],
  39.                     [req.event.defaultGroup_id],
  40.                     false,
  41.                     true
  42.                 );
  43.             }
  44.  
  45.             return Promise.resolve(mol.user);
  46.         })
  47.         .then(user => {
  48.             req.buyer = user;
  49.             req.buyer.pin = '';
  50.             req.buyer.password = '';
  51.  
  52.             req.details.buyer = req.buyer.id;
  53.  
  54.             next();
  55.         })
  56.         .catch(err => dbCatch(module, err, next));
  57. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top