reloaded 5 anni fa
parent
commit
ea71664561
3 ha cambiato i file con 23 aggiunte e 5 eliminazioni
  1. 4 4
      app/controller/.comment.js
  2. 0 1
      app/model/comment.js
  3. 19 0
      app/service/comment.js

+ 4 - 4
app/controller/.comment.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ["!newsid", "uid", "name", "content", "public_time"],
+    requestBody: ["!newsid", "uid", "content", "public_time"],
   },
   destroy: {
     params: ["!id"],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ["!id"],
-    requestBody: ["!newsid", "uid", "name", "content", "public_time"],
+    requestBody: ["!newsid", "uid", "content", "public_time"],
   },
   show: {
     parameters: {
@@ -19,8 +19,8 @@ module.exports = {
   index: {
     parameters: {
       query: {
-        name: "newsid",
-        site: "uid",
+        newsid: "newsid",
+        uid: "uid",
       },
     },
     service: "query",

+ 0 - 1
app/model/comment.js

@@ -6,7 +6,6 @@ const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 const CommentSchema = {
   newsid: { type: String, required: true, maxLength: 500 }, // 信息ID
   uid: { type: String, required: true, maxLength: 500 }, // 用户ID
-  name: { type: String, required: true, maxLength: 500 }, // 用户名称
   content: { type: String, required: true }, // 评论内容
   public_time: { type: String, required: false, maxLength: 500 }, // 发布时间
 };

+ 19 - 0
app/service/comment.js

@@ -13,6 +13,25 @@ class CommentService extends CrudService {
     this.model = this.ctx.model.Comment;
   }
 
+  async query({ skip, limit, ...info }) {
+    const total = await (await this.model.find(info)).length;
+    const comments = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
+    for (const comment of comments) {
+      const url = "http://127.0.0.1:9999/api/auth/user/" + comment.uid;
+      const user = await this.ctx.curl(url, {
+        method: 'get',
+        headers: {
+          'content-type': 'application/json',
+        },
+        dataType: 'json',
+      });
+      if (user.data.errcode === 0) {
+        comment.uname = user.data.data.name;
+      }
+    }
+    return { data: comments, total };
+  }
+
 }
 
 module.exports = CommentService;