소스 검색

更改评论查询

liuyu 5 년 전
부모
커밋
1bcd1fbfdc
1개의 변경된 파일5개의 추가작업 그리고 2개의 파일을 삭제
  1. 5 2
      app/service/comment.js

+ 5 - 2
app/service/comment.js

@@ -16,6 +16,7 @@ class CommentService extends CrudService {
   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));
+    const newdatas = [];
     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, {
@@ -25,11 +26,13 @@ class CommentService extends CrudService {
         },
         dataType: 'json',
       });
+      const newdata = { ...JSON.parse(JSON.stringify(comment)) };
       if (user.data.errcode === 0) {
-        comment.uname = user.data.data.name;
+        newdata.uname = user.data.data.name;
       }
+      newdatas.push(newdata);
     }
-    return { data: comments, total };
+    return { data: newdatas, total };
   }
 
 }