Просмотр исходного кода

added the ability to save snapshots of pageId

Shun Miyazawa 4 лет назад
Родитель
Сommit
9e23ff2d15

+ 1 - 0
packages/app/src/interfaces/in-app-notification.ts

@@ -16,6 +16,7 @@ export interface IInAppNotification {
   status: InAppNotificationStatuses
   actionUsers: IUser[]
   createdAt: Date
+  pageIdSnapshot: string
 }
 
 /*

+ 5 - 0
packages/app/src/server/models/in-app-notification.ts

@@ -20,6 +20,7 @@ export interface InAppNotificationDocument extends Document {
   activities: ActivityDocument[]
   status: string
   createdAt: Date
+  pageIdSnapshot: string
 }
 
 
@@ -73,6 +74,10 @@ const inAppNotificationSchema = new Schema<InAppNotificationDocument, InAppNotif
     type: Date,
     default: Date.now,
   },
+  pageIdSnapshot: {
+    type: String,
+    require: true,
+  },
 });
 inAppNotificationSchema.plugin(mongoosePaginate);
 

+ 3 - 2
packages/app/src/server/service/in-app-notification.ts

@@ -53,7 +53,7 @@ export default class InAppNotificationService {
   }
 
   upsertByActivity = async function(
-      users: Types.ObjectId[], activity: ActivityDocument, createdAt?: Date | null,
+      users: Types.ObjectId[], activity: ActivityDocument, pageIdSnapshot: string, createdAt?: Date | null,
   ): Promise<void> {
     const {
       _id: activityId, targetModel, target, action,
@@ -62,7 +62,7 @@ export default class InAppNotificationService {
     const lastWeek = subDays(now, 7);
     const operations = users.map((user) => {
       const filter = {
-        user, target, action, createdAt: { $gt: lastWeek },
+        user, target, action, createdAt: { $gt: lastWeek }, pageIdSnapshot,
       };
       const parameters = {
         user,
@@ -71,6 +71,7 @@ export default class InAppNotificationService {
         action,
         status: STATUS_UNREAD,
         createdAt: now,
+        pageIdSnapshot,
         $addToSet: { activities: activityId },
       };
       return {