12345678910111213141516171819202122232425262728293031323334353637383940 |
- '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 CommentService extends CrudService {
- constructor(ctx) {
- super(ctx, 'live_comment');
- this.model = this.ctx.model.Comment;
- }
- 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, {
- method: 'get',
- headers: {
- 'content-type': 'application/json',
- },
- dataType: 'json',
- });
- const newdata = { ...JSON.parse(JSON.stringify(comment)) };
- if (user.data.errcode === 0) {
- newdata.uname = user.data.data.name;
- }
- newdatas.push(newdata);
- }
- return { data: newdatas, total };
- }
- }
- module.exports = CommentService;
|