Skip to content

Commit

Permalink
fix: closes #117
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis3797 committed Jun 13, 2024
1 parent 12229db commit c99e768
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions apps/api/src/controller/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "../types/types";
import { decreaseFollowing, increaseFollowing } from "../service/user.service";
import {
AchievementType,
Achievement,
Follows,
Notification,
Stream,
Expand All @@ -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[];
};
Expand Down Expand Up @@ -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: []
});
};
Expand Down

0 comments on commit c99e768

Please sign in to comment.