feat: correctly get own friends

This commit is contained in:
Zamitto 2024-07-23 15:30:04 -03:00
parent e642bf71b1
commit 380143c780

View file

@ -1,3 +1,4 @@
import { userAuthRepository } from "@main/repository";
import { registerEvent } from "../register-event";
import { HydraApi } from "@main/services";
import { UserFriends } from "@types";
@ -7,9 +8,19 @@ export const getUserFriends = async (
take: number,
skip: number
): Promise<UserFriends> => {
const loggedUser = await userAuthRepository.findOne({ where: { id: 1 } });
if (loggedUser?.userId == userId) {
return HydraApi.get(`/profile/friends`, { take, skip }).catch(
(_err) => {
return { totalFriends: 0, friends: [] };
}
);
}
return HydraApi.get(`/user/${userId}/friends`, { take, skip }).catch(
(_err) => {
return { totalFriends: 0, friends: [] } as UserFriends;
return { totalFriends: 0, friends: [] };
}
);
};