news.js 944 B

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. const assert = require('assert');
  3. const _ = require('lodash');
  4. const { ObjectId } = require('mongoose').Types;
  5. const { CrudService } = require('naf-framework-mongoose/lib/service');
  6. const { BusinessError, ErrorCode } = require('naf-core').Error;
  7. class NewsService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'news');
  10. this.model = this.ctx.model.News;
  11. }
  12. async fetch({ id }) {
  13. const news = await this.model.findById(id);
  14. const newdata = { ...JSON.parse(JSON.stringify(news)) };
  15. if (news) {
  16. const url = 'http://127.0.0.1:9999/api/auth/user/' + news.uid;
  17. const user = await this.ctx.curl(url, {
  18. method: 'get',
  19. headers: {
  20. 'content-type': 'application/json',
  21. },
  22. dataType: 'json',
  23. });
  24. if (user.data.errcode === 0) {
  25. newdata.uname = user.data.data.name;
  26. }
  27. }
  28. return newdata;
  29. }
  30. }
  31. module.exports = NewsService;