Added album check to uploads

This commit is contained in:
Pitu 2017-08-30 04:48:17 -03:00
parent f8d6cc7db6
commit 80117235f9
2 changed files with 68 additions and 59 deletions

View File

@ -62,6 +62,14 @@ uploadsController.upload = function(req, res, next) {
album = req.params.albumid
}
db.table('albums').where({ id: album, userid: userid }).then((albums) => {
if (albums.length === 0) {
return res.json({
success: false,
description: 'Album doesn\'t exist or it doesn\'t belong to the user'
})
}
upload(req, res, function (err) {
if (err) {
console.error(err)
@ -126,6 +134,7 @@ uploadsController.upload = function(req, res, next) {
})
})
})
})
}).catch(function(error) { console.log(error); res.json({ success: false, description: 'error' }) })
}