notifications: fixes

This commit is contained in:
Matteo Pagliazzi
2018-02-04 13:28:05 +01:00
parent 2af99d7c65
commit 4efbbd7bac
15 changed files with 118 additions and 37 deletions

View File

@@ -163,10 +163,12 @@ schema.methods.addNotification = function addUserNotification (type, data = {},
*/
schema.statics.pushNotification = async function pushNotification (query, type, data = {}, seen = false) {
let newNotification = new UserNotification({type, data, seen});
let validationResult = newNotification.validateSync();
if (validationResult) {
throw validationResult;
}
await this.update(query, {$push: {notifications: newNotification.toObject()}}, {multi: true}).exec();
};