Guest User

Untitled

a guest
Jul 21st, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. router.post('/add', uploadProductImage, (req, res, next) => {
  2.   const { name, description, providerId, price } = req.body
  3.   const img = req.file
  4.  
  5.   waterfall([
  6.     (cb) => {
  7.       gm(img.path)
  8.         .resize(320, 240)
  9.         .noProfile()
  10.         .write(__dirname + '/../public/images/products/' + img.filename, (err) => cb(err))
  11.     },
  12.     (cb) => {
  13.       deleteFile(img.path, (err) => cb(err))
  14.     },
  15.     (cb) => {
  16.       const product = new Product({
  17.         name,
  18.         description,
  19.         img: img ? img.filename : 'no-photo',
  20.         providers: [{
  21.           price: price,
  22.           id: providerId,
  23.         }],
  24.       })
  25.       product.save((err, item) => cb(err, item))
  26.     }
  27.   ],(err, item) => {
  28.     if (err) {
  29.       return res.status(400).json({ error: err.message })
  30.     }
  31.     return res.json({ data: item })
  32.   })
  33. })
Advertisement
Add Comment
Please, Sign In to add comment