|
@@ -9,9 +9,10 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
|
|
|
class CommentService extends CrudService {
|
|
|
constructor(ctx) {
|
|
|
- super(ctx, "comment");
|
|
|
+ super(ctx, 'comment');
|
|
|
this.model = this.ctx.model.Comment;
|
|
|
this.umodel = this.ctx.model.User;
|
|
|
+ this.nmodel = this.ctx.model.News;
|
|
|
}
|
|
|
|
|
|
async query({ skip, limit, ...info }) {
|
|
@@ -24,6 +25,8 @@ class CommentService extends CrudService {
|
|
|
for (let comment of comments) {
|
|
|
comment = JSON.parse(JSON.stringify(comment));
|
|
|
const user = await this.umodel.findById(comment.uid);
|
|
|
+ const news = await this.nmodel.findById(comment.newsid);
|
|
|
+ comment.nname = news.title;
|
|
|
comment.uname = user.name;
|
|
|
newdatas.push(comment);
|
|
|
}
|
|
@@ -34,6 +37,8 @@ class CommentService extends CrudService {
|
|
|
let comment = await this.model.findById(id);
|
|
|
comment = JSON.parse(JSON.stringify(comment));
|
|
|
const user = await this.umodel.findById(comment.uid);
|
|
|
+ const news = await this.nmodel.findById(comment.newsid);
|
|
|
+ comment.nname = news.title;
|
|
|
comment.uname = user.name;
|
|
|
return comment;
|
|
|
}
|