|
@@ -26,10 +26,6 @@ export interface InAppNotificationDocument extends Document {
|
|
|
export interface InAppNotificationModel extends Model<InAppNotificationDocument> {
|
|
export interface InAppNotificationModel extends Model<InAppNotificationDocument> {
|
|
|
findLatestInAppNotificationsByUser(user: Types.ObjectId, skip: number, offset: number): Promise<InAppNotificationDocument[]>
|
|
findLatestInAppNotificationsByUser(user: Types.ObjectId, skip: number, offset: number): Promise<InAppNotificationDocument[]>
|
|
|
|
|
|
|
|
- // commented out type 'Query' temporary to avoid ts error
|
|
|
|
|
- removeEmpty()/* : Query<any> */
|
|
|
|
|
- read(user) /* : Promise<Query<any>> */
|
|
|
|
|
-
|
|
|
|
|
open(user, id: Types.ObjectId): Promise<InAppNotificationDocument | null>
|
|
open(user, id: Types.ObjectId): Promise<InAppNotificationDocument | null>
|
|
|
getUnreadCountByUser(user: Types.ObjectId): Promise<number | undefined>
|
|
getUnreadCountByUser(user: Types.ObjectId): Promise<number | undefined>
|
|
|
|
|
|
|
@@ -101,31 +97,6 @@ inAppNotificationSchema.statics.findLatestInAppNotificationsByUser = function(us
|
|
|
.exec();
|
|
.exec();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-inAppNotificationSchema.statics.removeEmpty = function() {
|
|
|
|
|
- return InAppNotification.deleteMany({ activities: { $size: 0 } });
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
-inAppNotificationSchema.statics.read = async function(user) {
|
|
|
|
|
- const query = { user, status: STATUS_UNREAD };
|
|
|
|
|
- const parameters = { status: STATUS_UNOPENED };
|
|
|
|
|
-
|
|
|
|
|
- return InAppNotification.updateMany(query, parameters);
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
-inAppNotificationSchema.statics.getUnreadCountByUser = async function(user) {
|
|
|
|
|
- const query = { user, status: STATUS_UNREAD };
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- const count = await InAppNotification.countDocuments(query);
|
|
|
|
|
-
|
|
|
|
|
- return count;
|
|
|
|
|
- }
|
|
|
|
|
- catch (err) {
|
|
|
|
|
- logger.error('Error on getUnreadCountByUser', err);
|
|
|
|
|
- throw err;
|
|
|
|
|
- }
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
inAppNotificationSchema.statics.STATUS_UNOPENED = function() {
|
|
inAppNotificationSchema.statics.STATUS_UNOPENED = function() {
|
|
|
return STATUS_UNOPENED;
|
|
return STATUS_UNOPENED;
|
|
|
};
|
|
};
|