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/open-auth-window";
import "./auth/get-session-hash"; import "./auth/get-session-hash";
import "./user/get-user"; import "./user/get-user";
import "./user/get-user-friends";
import "./profile/get-friend-requests"; import "./profile/get-friend-requests";
import "./profile/get-me"; import "./profile/get-me";
import "./profile/update-friend-request"; import "./profile/update-friend-request";

View File

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

View File

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

View File

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