Просмотр исходного кода

Merge branch 'comment' of xiongzhu/chat-api into master

wuyi 2 лет назад
Родитель
Сommit
fd3f8bccc1
2 измененных файлов с 9 добавлено и 5 удалено
  1. 8 4
      src/comment/comment.service.ts
  2. 1 1
      src/comment/entities/comment.entity.ts

+ 8 - 4
src/comment/comment.service.ts

@@ -20,7 +20,6 @@ export class CommentService {
 
 
     async findAll(req: PageRequest<Comment>): Promise<Pagination<Comment>> {
-
         const query = await this.commentRepository.createQueryBuilder()
             .where('comment.isDel = false')
 
@@ -54,9 +53,14 @@ export class CommentService {
         items.forEach(comment => {
             if (!Boolean(comment.rootCommentId)) {
                 rootMap.set(comment.id, comment)
-            } else {
+            }
+        })
+
+        items.forEach(comment => {
+            console.log(rootMap)
+            if (Boolean(comment.rootCommentId)) {
                 const root = rootMap.get(comment.rootCommentId)
-                if (Boolean(root.childList)) {
+                if (root.hasOwnProperty('childList')) {
                     root.childList.push(comment)
                 } else {
                     const childList: Comment[] = []
@@ -66,8 +70,8 @@ export class CommentService {
                 rootMap.set(root.id, root)
             }
         })
-        const newItems = Array.from(rootMap.values());
 
+        const newItems = Array.from(rootMap.values());
         const result: Pagination<Comment> = {
             items: newItems,
             meta

+ 1 - 1
src/comment/entities/comment.entity.ts

@@ -38,6 +38,6 @@ export class Comment {
     createdAt: Date
 
     @Exclude()
-    childList: Comment[]
+    childList?: Comment[]
 
 }