lrf402788946 4 years ago
parent
commit
5654a3886f

+ 9 - 0
app/controller/users/.person_chat.js

@@ -52,4 +52,13 @@ module.exports = {
       count: true,
     },
   },
+  allRead: {
+    parameters: {
+      query: {
+        user_id: "user_id",
+        room_id: "room_id",
+      },
+    },
+    service: "allRead",
+  },
 };

+ 1 - 0
app/router/users/person_chat.js

@@ -7,6 +7,7 @@ module.exports = app => {
   const vision = 'v0';
   const index = 'users';
   const target = 'personChat';
+  router.get(target, `${profix}${vision}/${index}/${target}/read`, controller[index][target].allRead);
   router.resources(target, `${profix}${vision}/${index}/${target}`, controller[index][target]); // index、create、show、destroy
   router.post(target, `${profix}${vision}/${index}/${target}/update/:id`, controller[index][target].update);
 };

+ 6 - 0
app/service/users/person_chat.js

@@ -31,6 +31,12 @@ class Person_chatService extends CrudService {
     }
     return res;
   }
+
+  async allRead({ user_id, room_id }) {
+    assert(user_id && room_id, '缺少信息');
+    const res = await this.model.updateMany({ receiver_id: user_id, room_id }, { is_read: true });
+    return res;
+  }
 }
 
 module.exports = Person_chatService;