From c99e768ee5d6e20ddfee5f3f35d436e98ede6e1e Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 14 Jun 2024 01:33:51 +0200 Subject: [PATCH] fix: closes #117 --- apps/api/src/controller/user.controller.ts | 32 ++++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/apps/api/src/controller/user.controller.ts b/apps/api/src/controller/user.controller.ts index 7279747..7336273 100644 --- a/apps/api/src/controller/user.controller.ts +++ b/apps/api/src/controller/user.controller.ts @@ -9,7 +9,7 @@ import { } from "../types/types"; import { decreaseFollowing, increaseFollowing } from "../service/user.service"; import { - AchievementType, + Achievement, Follows, Notification, Stream, @@ -26,17 +26,9 @@ export const getUserInfo = async ( res: Response< TypedResponse<{ user: User & { + subscribed: boolean; userToAchievement: { - achievement: { - id: string; - type: AchievementType; - name: string; - level: number; - bannerUrl: string; - condition: number; - progress: number; - promotionPoints: number; - }; + achievement: Achievement; }[]; streams: Stream[]; }; @@ -64,9 +56,25 @@ export const getUserInfo = async ( }); } + let subscribed = false; + + if (user.id !== req.user!.id) { + const checkSubscribed = await prismaClient.follows.findUnique({ + where: { + followingId_followedById: { + followedById: req.user!.id, + followingId: user.id + } + } + }); + subscribed = !!checkSubscribed; + } + + const result = { ...user, subscribed }; + return res.status(httpStatus.OK).json({ success: true, - data: { user }, + data: { user: result }, error: [] }); };