cleanup group model
This commit is contained in:
@@ -1101,6 +1101,7 @@ api.questLeave = function(req, res, next) {
|
||||
});
|
||||
}
|
||||
|
||||
// TODO port to api v3? in tojson?
|
||||
function _purgeFlagInfoFromChat(group, user) {
|
||||
group.chat = _.filter(group.chat, function(message) { return !message.flagCount || message.flagCount < 2; });
|
||||
_.each(group.chat, function (message) {
|
||||
|
||||
@@ -567,7 +567,7 @@ function _inviteByEmails (emails, group, inviter, req, res, next) {
|
||||
*
|
||||
* @apiSuccess {Object} empty An empty object
|
||||
*/
|
||||
/* api.inviteToGroup = {
|
||||
api.inviteToGroup = {
|
||||
method: 'POST',
|
||||
url: '/groups/:groupId/invite',
|
||||
middlewares: [authWithHeaders(), cron],
|
||||
@@ -598,6 +598,6 @@ function _inviteByEmails (emails, group, inviter, req, res, next) {
|
||||
})
|
||||
.catch(next);
|
||||
},
|
||||
};*/
|
||||
};
|
||||
|
||||
export default api;
|
||||
|
||||
@@ -94,16 +94,6 @@ schema.statics.sanitizeUpdate = function sanitizeUpdate (updateObj) {
|
||||
}
|
||||
}*/
|
||||
|
||||
// FIXME this isn't always triggered, since we sometimes use update() or findByIdAndUpdate()
|
||||
// @see https://github.com/LearnBoost/mongoose/issues/964 -> Add update pre?
|
||||
// TODO necessary?
|
||||
schema.pre('save', function preSaveGroup (next) {
|
||||
// removeDuplicates(this);
|
||||
this.memberCount = _.size(this.members);
|
||||
this.challengeCount = _.size(this.challenges);
|
||||
return next();
|
||||
});
|
||||
|
||||
// TODO test
|
||||
schema.pre('remove', true, function preRemoveGroup (next, done) {
|
||||
next();
|
||||
@@ -135,24 +125,6 @@ schema.post('remove', function postRemoveGroup (group) {
|
||||
firebase.deleteGroup(group._id);
|
||||
});
|
||||
|
||||
/* schema.methods.toJSON = function groupToJSON () {
|
||||
let doc = this.toObject();
|
||||
// removeDuplicates(doc);
|
||||
doc._isMember = this._isMember; // TODO ?
|
||||
|
||||
// TODO migration
|
||||
// fix(groups): temp fix to remove chat entries stored as strings (not sure why that's happening..).
|
||||
// Required as angular 1.3 is strict on dupes, and no message.id to `track by`
|
||||
_.remove(doc.chat, msg => !msg.id);
|
||||
|
||||
// TODO should not be needed here
|
||||
// @see pre('save') comment above
|
||||
this.memberCount = _.size(this.members);
|
||||
this.challengeCount = _.size(this.challenges);
|
||||
|
||||
return doc;
|
||||
};*/
|
||||
|
||||
// TODO populate (invites too), isMember?
|
||||
schema.statics.getGroup = function getGroup (user, groupId, fields) {
|
||||
let query;
|
||||
@@ -170,7 +142,7 @@ schema.statics.getGroup = function getGroup (user, groupId, fields) {
|
||||
.select(fields)
|
||||
.exec(); // TODO catch errors here?
|
||||
|
||||
// TODO purge chat flags info?
|
||||
// TODO purge chat flags info? in tojson?
|
||||
};
|
||||
|
||||
// TODO move to its own model
|
||||
|
||||
Reference in New Issue
Block a user