Kaynağa Gözat

点赞修改

wuyi 2 yıl önce
ebeveyn
işleme
9d94fe9761

+ 2 - 2
src/moments/moments.controller.ts

@@ -18,9 +18,9 @@ export class MomentsController {
     }
 
     @Get('/get/:id')
-    public async get(@Param('id') id: string) {
+    public async get(@Param('id') id: string, @Req() req) {
         try {
-            return await this.momentsService.findById(Number(id))
+            return await this.momentsService.findById(Number(id),req.user.userId)
         } catch (err) {
             throw new BadRequestException(err, 'Error: Moments not existent!')
         }

+ 10 - 1
src/moments/moments.service.ts

@@ -62,9 +62,18 @@ export class MomentsService {
         return page
     }
 
-    async findById(id: number): Promise<Moments> {
+    async findById(id: number, userId: number): Promise<Moments> {
         const moments = await this.momentsRepository.findOneBy({ id: +id })
         const chatRole = await this.chatRoleService.findById(moments.userId)
+        const likes = await this.likesRepository.findOneBy({
+            userId: +userId,
+            targetId: id,
+            type: 1,
+            isValid: true
+        })
+        if (likes) {
+            moments.isLiked = true
+        }
         moments.chatRole = chatRole
         return moments
     }