'use strict'; const assert = require('assert'); const _ = require('lodash'); const { ObjectId } = require('mongoose').Types; const { CrudService } = require('naf-framework-mongoose/lib/service'); const { BusinessError, ErrorCode } = require('naf-core').Error; class NewsService extends CrudService { constructor(ctx) { super(ctx, 'news'); this.model = this.ctx.model.News; } async fetch({ id }) { const news = await this.model.findById(id); const newdata = { ...JSON.parse(JSON.stringify(news)) }; 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.errcode === 0) { newdata.uname = user.data.data.name; } } return newdata; } } module.exports = NewsService;