mirror of
https://github.com/wassname/talk.git
synced 2026-07-25 13:30:59 +08:00
Move all DB functions into models. Clean up tests.
This commit is contained in:
+27
-1
@@ -28,7 +28,7 @@ ActionSchema.statics.findById = function(id) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Finds users in an array of ids.
|
||||
* Finds actions in an array of ids.
|
||||
* @param {String} ids array of user identifiers (uuid)
|
||||
*/
|
||||
ActionSchema.statics.findByItemIdArray = function(item_ids) {
|
||||
@@ -37,6 +37,32 @@ ActionSchema.statics.findByItemIdArray = function(item_ids) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Finds all comments for a specific action.
|
||||
* @param {String} action_type type of action
|
||||
* @param {String} item_type type of item the action is on
|
||||
*/
|
||||
ActionSchema.statics.findByType = function(action_type, item_type) {
|
||||
return Action.find({
|
||||
'action_type': action_type,
|
||||
'item_type': item_type
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Finds all comments ids for a specific action.
|
||||
* @param {String} action_type type of action
|
||||
* @param {String} item_type type of item the action is on
|
||||
*/
|
||||
ActionSchema.statics.findCommentsIdByActionType = function(action_type, item_type) {
|
||||
return Action.find({
|
||||
'action_type': action_type,
|
||||
'item_type': item_type
|
||||
},
|
||||
'item_id'
|
||||
);
|
||||
};
|
||||
|
||||
const Action = mongoose.model('Action', ActionSchema);
|
||||
|
||||
module.exports = Action;
|
||||
|
||||
Reference in New Issue
Block a user