Ver código fonte

修改查询方法

liuyu 5 anos atrás
pai
commit
b857645b03
1 arquivos alterados com 18 adições e 0 exclusões
  1. 18 0
      app/service/news.js

+ 18 - 0
app/service/news.js

@@ -13,6 +13,24 @@ class NewsService extends CrudService {
     this.model = this.ctx.model.News;
     this.model = this.ctx.model.News;
   }
   }
 
 
+  async fetch({ id }) {
+    const news = await this.model.findById(id);
+    if (news) {
+      const url = 'http://127.0.0.1:9999/api/auth/user/' + news.uid;
+      const user = await this.ctx.curl(url, {
+        method: 'get',
+        headers: {
+          'content-type': 'application/json',
+        },
+        dataType: 'json',
+      });
+      if (user.data.data.name) {
+        news.uname = user.data.data.name;
+      }
+    }
+    return news;
+  }
+
 }
 }
 
 
 module.exports = NewsService;
 module.exports = NewsService;