瀏覽代碼

新增comment中status

reloaded 5 年之前
父節點
當前提交
f7e6b68301
共有 3 個文件被更改,包括 10 次插入3 次删除
  1. 3 2
      app/controller/.comment.js
  2. 1 0
      app/model/comment.js
  3. 6 1
      app/service/comment.js

+ 3 - 2
app/controller/.comment.js

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

+ 1 - 0
app/model/comment.js

@@ -8,6 +8,7 @@ const CommentSchema = {
   uid: { type: String, required: true, maxLength: 500 }, // 用户ID
   content: { type: String, required: true }, // 评论内容
   public_time: { type: String, required: false, maxLength: 500 }, // 发布时间
+  status: { type: String, required: false, maxLength: 100 }, // 状态,0-未审核,1-审核通过,2-审核拒绝
 };
 
 

+ 6 - 1
app/service/comment.js

@@ -9,9 +9,10 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
 
 class CommentService extends CrudService {
   constructor(ctx) {
-    super(ctx, "comment");
+    super(ctx, 'comment');
     this.model = this.ctx.model.Comment;
     this.umodel = this.ctx.model.User;
+    this.nmodel = this.ctx.model.News;
   }
 
   async query({ skip, limit, ...info }) {
@@ -24,6 +25,8 @@ class CommentService extends CrudService {
     for (let comment of comments) {
       comment = JSON.parse(JSON.stringify(comment));
       const user = await this.umodel.findById(comment.uid);
+      const news = await this.nmodel.findById(comment.newsid);
+      comment.nname = news.title;
       comment.uname = user.name;
       newdatas.push(comment);
     }
@@ -34,6 +37,8 @@ class CommentService extends CrudService {
     let comment = await this.model.findById(id);
     comment = JSON.parse(JSON.stringify(comment));
     const user = await this.umodel.findById(comment.uid);
+    const news = await this.nmodel.findById(comment.newsid);
+    comment.nname = news.title;
     comment.uname = user.name;
     return comment;
   }