feat: add getUserFriends event

This commit is contained in:
Zamitto 2024-07-23 18:37:19 -03:00
parent 380143c780
commit 010f07373d
4 changed files with 15 additions and 9 deletions

View File

@ -43,6 +43,7 @@ import "./auth/sign-out";
import "./auth/open-auth-window";
import "./auth/get-session-hash";
import "./user/get-user";
import "./user/get-user-friends";
import "./profile/get-friend-requests";
import "./profile/get-me";
import "./profile/update-friend-request";

View File

@ -8,21 +8,23 @@ export const getUserFriends = async (
take: number,
skip: number
): Promise<UserFriends> => {
const loggedUser = await userAuthRepository.findOne({ where: { id: 1 } });
try {
const loggedUser = await userAuthRepository.findOne({ where: { id: 1 } });
if (loggedUser?.userId == userId) {
return HydraApi.get(`/profile/friends`, { take, skip }).catch(
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: [] };
}
);
} catch (err) {
return { totalFriends: 0, friends: [] };
}
return HydraApi.get(`/user/${userId}/friends`, { take, skip }).catch(
(_err) => {
return { totalFriends: 0, friends: [] };
}
);
};
const getUserFriendsEvent = async (

View File

@ -145,6 +145,7 @@ contextBridge.exposeInMainWorld("electron", {
/* User */
getUser: (userId: string) => ipcRenderer.invoke("getUser", userId),
getUserFriends: (userId: string) => ipcRenderer.invoke("getUserFriends", userId),
/* Auth */
signOut: () => ipcRenderer.invoke("signOut"),

View File

@ -16,6 +16,7 @@ import type {
UserProfile,
FriendRequest,
FriendRequestAction,
UserFriends,
} from "@types";
import type { DiskSpace } from "check-disk-space";
@ -127,6 +128,7 @@ declare global {
/* User */
getUser: (userId: string) => Promise<UserProfile | null>;
getUserFriends: (userId: string) => Promise<UserFriends>;
/* Profile */
getMe: () => Promise<UserProfile | null>;