Advertisement
kuznets

OrderController.v1.1.js

Apr 12th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var bodyParser = require('body-parser');
  2. var db = require('../config/db.js');
  3. var authorize = require(__dirname + '/authorize.js')({db: db}).authorize;
  4.  
  5. module.exports = function (app) {
  6. //Find all orders by username
  7.     app.get('/api/orders', function (req, res, next) {
  8.         authorize(req).then(function (foundUser) {
  9.             db.orders.findAll({where: {userId: foundUser.id}})
  10.                 .then(function (orders) {
  11.                     console.log('OrderController order list:');
  12.                     //console.log(orders);
  13.                     res.json({message: 'OK', body: orders});
  14.                     next();
  15.                 });
  16.         }), function (err) {
  17.             res.status(200).send('User not found');
  18.             return next();
  19.         }
  20.     });
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement