news.js 863 B

123456789101112131415161718192021222324252627282930313233343536
  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. if (news) {
  15. const url = 'http://127.0.0.1:9999/api/auth/user/' + news.uid;
  16. const user = await this.ctx.curl(url, {
  17. method: 'get',
  18. headers: {
  19. 'content-type': 'application/json',
  20. },
  21. dataType: 'json',
  22. });
  23. if (user.data.name) {
  24. news.uname = user.data.name;
  25. }
  26. }
  27. return news;
  28. }
  29. }
  30. module.exports = NewsService;