wuyi 2 роки тому
батько
коміт
4afdc43caf

+ 0 - 1
src/comment/comment.controller.ts

@@ -25,7 +25,6 @@ export class CommentController {
 
 
     @Post()
     @Post()
     public async list(@Req() req, @Body() page: PageRequest<Comment>) {
     public async list(@Req() req, @Body() page: PageRequest<Comment>) {
-        console.log(req.user.userId)
         return await this.commentService.findAll(page, req.user.userId)
         return await this.commentService.findAll(page, req.user.userId)
     }
     }
 
 

+ 5 - 1
src/comment/comment.service.ts

@@ -91,6 +91,8 @@ export class CommentService {
         childList.forEach(comment => {
         childList.forEach(comment => {
             if (targetIds.includes(comment.id)) {
             if (targetIds.includes(comment.id)) {
                 comment.isLiked = true
                 comment.isLiked = true
+            } else {
+                comment.isLiked = false
             }
             }
             if (Boolean(comment.rootCommentId)) {
             if (Boolean(comment.rootCommentId)) {
                 const root = rootMap.get(comment.rootCommentId)
                 const root = rootMap.get(comment.rootCommentId)
@@ -106,7 +108,9 @@ export class CommentService {
         })
         })
 
 
         const newItems = Array.from(rootMap.values());
         const newItems = Array.from(rootMap.values());
-        newItems.forEach(comment => { if (targetIds.includes(comment.id)) { comment.isLiked = true } })
+        newItems.forEach(comment => {
+            comment.isLiked = targetIds.includes(comment.id) ? true : false
+        })
 
 
         const result: Pagination<Comment> = {
         const result: Pagination<Comment> = {
             items: newItems,
             items: newItems,

+ 2 - 3
src/moments/moments.service.ts

@@ -17,6 +17,7 @@ import { ChatRoleService } from '../chat-role/chat-role.service'
 import { LikesService } from 'src/likes/likes.service'
 import { LikesService } from 'src/likes/likes.service'
 import { ChatRole } from 'src/chat-role/entities/chat-role.entity'
 import { ChatRole } from 'src/chat-role/entities/chat-role.entity'
 import { Likes } from 'src/likes/entities/likes.entity'
 import { Likes } from 'src/likes/entities/likes.entity'
+import { el } from 'date-fns/locale'
 
 
 @Injectable()
 @Injectable()
 export class MomentsService {
 export class MomentsService {
@@ -55,9 +56,7 @@ export class MomentsService {
         const map = await this.chatRoleService.findMapByIds(ids);
         const map = await this.chatRoleService.findMapByIds(ids);
         page.items.forEach(c => {
         page.items.forEach(c => {
             c.chatRole = map.get(c.userId)
             c.chatRole = map.get(c.userId)
-            if (targetIds.includes(c.id)) {
-                c.isLiked = true
-            }
+            c.isLiked = targetIds.includes(c.id) ? true : false
         })
         })
 
 
         return page
         return page