Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.post('/add', uploadProductImage, (req, res, next) => {
- const { name, description, providerId, price } = req.body
- const img = req.file
- waterfall([
- (cb) => {
- gm(img.path)
- .resize(320, 240)
- .noProfile()
- .write(__dirname + '/../public/images/products/' + img.filename, (err) => cb(err))
- },
- (cb) => {
- deleteFile(img.path, (err) => cb(err))
- },
- (cb) => {
- const product = new Product({
- name,
- description,
- img: img ? img.filename : 'no-photo',
- providers: [{
- price: price,
- id: providerId,
- }],
- })
- product.save((err, item) => cb(err, item))
- }
- ],(err, item) => {
- if (err) {
- return res.status(400).json({ error: err.message })
- }
- return res.json({ data: item })
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment