More endpoints

This commit is contained in:
gaba
2016-11-07 11:27:05 -08:00
parent cffee1ec18
commit 6f0698b950
3 changed files with 146 additions and 22 deletions
+14 -9
View File
@@ -32,10 +32,10 @@ const CommentSchema = new Schema({
/**
* Finds a comment by the id.
* @param {String} asset_id identifier of comment (uuid)
* @param {String} id identifier of comment (uuid)
*/
CommentSchema.statics.findById = function(id) {
return Comment.findOne({id});
return Comment.findOne({'id': id});
};
/**
@@ -48,13 +48,19 @@ CommentSchema.statics.findByAssetId = function(asset_id) {
/**
* Change the status of a comment.
* @param {String} comment_id identifier of the comment (uuid)
* @param {String} id identifier of the comment (uuid)
* @param {String} status the new status of the comment
*/
CommentSchema.statics.changeStatus = function(id, status) {
var comment = Comment.findOne({id});
comment.status = status;
return comment.save();
return Comment.update({'id': id}, {$set: {'status': status}}, {upsert: false}).then(() => {
Comment.findById(id).then((comment) => {
return comment;
}).catch((err) => {
console.log('Error updating status for the comment.', err);
});
}).catch((err) => {
console.log('Error updating status for the comment.', err);
});
};
/**
@@ -64,10 +70,9 @@ CommentSchema.statics.changeStatus = function(id, status) {
*/
CommentSchema.statics.addAction = function(id, user_id, action_type) {
// check that the comment exist
var item_type = 'comment';
let action = new Action({
var action = new Action({
action_type: action_type,
item_type: item_type,
item_type: 'comment',
item_id: id,
user_id: user_id
});