/**
* @HttpMethod('/album')
*/
define('album', __filename, function ($errors, $mongodb, albumModel, imageModel) {
var ObjectId = $mongodb.ObjectID;
return {
/**
*
* @Validation(fields='name')
* @HttpMethod(method='POST')
*/
new: function(req, res){
var name = req.param('name', '');
return albumModel.insert(req.user, name).then(function(album){
return res.send(204, '');
});
},
/**
*
* @Validation(fields='albumId,name', type='album')
* @HttpMethod(url='rename', method='POST')
*/
rename: function(req, res){
var name = req.param('name', ''),
albumId = req.param('albumId', '');
return albumModel.update({_id: new ObjectId(albumId)}, {name: name}).then(function(){
return res.send(204, '');
});
},
/**
*
* @Validation(fields='albumId', type='album')
* @HttpMethod(url='remove', method='POST')
*/
remove: function(req, res){
var albumId = req.param('albumId', '');
return albumModel.findOne({_id: new ObjectId(albumId)}).then(function(album){
if (album.isOther) throw new $errors.HttpError(401, res.locals.__('messages.accessDenied'));
}).then(function(){
return imageModel.remove({albumId: new ObjectId(albumId)}).then(function(){
return albumModel.remove({_id: new ObjectId(albumId)});
}).then(function(){
return res.send(204, '')
});
})
},
};
});