diff --git a/src/api/auth/auth.ts b/src/api/auth/auth.ts index 3d06bab..b466e56 100644 --- a/src/api/auth/auth.ts +++ b/src/api/auth/auth.ts @@ -8,11 +8,11 @@ import { const fetchLoginApi = async ( request: IFetchLoginRequest, ): Promise => { - return await callApi(HTTP.POST, `auth/login`, request); + return await callApi(HTTP.POST, `auth/login`, request, true); }; const fetchRefreshApi = async (): Promise => { - return await callApi(HTTP.GET_REFRESH, `auth/refresh`); + return await callApi(HTTP.GET, `auth/refresh`, undefined, true); }; export { fetchLoginApi, fetchRefreshApi }; diff --git a/src/api/channel/types.ts b/src/api/channel/types.ts index 797ff36..c76b499 100644 --- a/src/api/channel/types.ts +++ b/src/api/channel/types.ts @@ -1,6 +1,7 @@ interface IFetchChannel { id: string; name: string; + description?: string; communityId: string; creationDate: number; } diff --git a/src/api/community/types.ts b/src/api/community/types.ts index bd5d2f0..7605fc3 100644 --- a/src/api/community/types.ts +++ b/src/api/community/types.ts @@ -1,11 +1,19 @@ +interface IFetchCommunity { + id: string; + name: string; + description?: string; + ownerId: string; + creationDate: number; +} + interface IFetchCommunityRequest { id: string; } -interface IFetchCommunityResponse { - id: string; - name: string; - description: string; -} +interface IFetchCommunityResponse extends IFetchCommunity {} -export { type IFetchCommunityRequest, type IFetchCommunityResponse }; +export { + type IFetchCommunity, + type IFetchCommunityRequest, + type IFetchCommunityResponse, +}; diff --git a/src/api/role/types.ts b/src/api/role/types.ts index ab15a58..9eca948 100644 --- a/src/api/role/types.ts +++ b/src/api/role/types.ts @@ -1,7 +1,9 @@ interface IFetchRole { id: string; name: string; + description?: string; communityId: string; + permissions: string[]; creationDate: number; } diff --git a/src/api/tools.ts b/src/api/tools.ts index d36128d..0aa09f8 100644 --- a/src/api/tools.ts +++ b/src/api/tools.ts @@ -2,33 +2,26 @@ import { state } from "../store/state"; import config from "./config.json"; enum HTTP { - GET_REFRESH, GET, POST, PATCH, DELETE, } -async function callApi(type: HTTP, path: string, body?: object) { +async function callApi( + type: HTTP, + path: string, + body?: object, + includeCookies?: boolean, +) { let response: Response; switch (type) { - case HTTP.GET_REFRESH: - response = await fetch( - `${config.schema}://${config.url}:${config.port}/${config.path}/${path}`, - { - method: "GET", - credentials: "include", - headers: { - "Content-Type": "application/json", - }, - }, - ); - break; case HTTP.GET: response = await fetch( `${config.schema}://${config.url}:${config.port}/${config.path}/${path}`, { method: "GET", + credentials: includeCookies ? "include" : "omit", headers: { "Content-Type": "application/json", Authorization: `Bearer ${state.auth.session?.token}`, @@ -41,6 +34,7 @@ async function callApi(type: HTTP, path: string, body?: object) { `${config.schema}://${config.url}:${config.port}/${config.path}/${path}`, { method: "POST", + credentials: includeCookies ? "include" : "omit", headers: { "Content-Type": "application/json", Authorization: `Bearer ${state.auth.session?.token}`, @@ -54,6 +48,7 @@ async function callApi(type: HTTP, path: string, body?: object) { `${config.schema}://${config.url}:${config.port}/${config.path}/${path}`, { method: "PATCH", + credentials: includeCookies ? "include" : "omit", headers: { "Content-Type": "application/json", Authorization: `Bearer ${state.auth.session?.token}`, @@ -67,6 +62,7 @@ async function callApi(type: HTTP, path: string, body?: object) { `${config.schema}://${config.url}:${config.port}/${config.path}/${path}`, { method: "DELETE", + credentials: includeCookies ? "include" : "omit", headers: { "Content-Type": "application/json", Authorization: `Bearer ${state.auth.session?.token}`, diff --git a/src/api/user/types.ts b/src/api/user/types.ts index c7744de..769293b 100644 --- a/src/api/user/types.ts +++ b/src/api/user/types.ts @@ -1,3 +1,13 @@ +interface IFetchUser { + id: string; + username: string; + email?: string; + description?: string; + admin: boolean; + registerDate: number; + lastLogin: number; +} + interface IFetchLoggedUserResponse { id: string; } @@ -6,11 +16,7 @@ interface IFetchUserRequest { id: string; } -interface IFetchUserResponse { - id: string; - username: string; - description: string; -} +interface IFetchUserResponse extends IFetchUser {} interface IFetchUserCommunitiesRequest { id: string; @@ -28,6 +34,7 @@ interface IFetchUserCommunity { } export { + type IFetchUser, type IFetchLoggedUserResponse, type IFetchUserRequest, type IFetchUserResponse, diff --git a/src/store/channel/types.ts b/src/store/channel/types.ts index cfbac09..d7a0590 100644 --- a/src/store/channel/types.ts +++ b/src/store/channel/types.ts @@ -5,7 +5,9 @@ interface IChannelState { interface IChannel { id: string; name?: string; + description?: string; communityId?: string; + creationDate?: number; } export { type IChannelState, type IChannel }; diff --git a/src/store/community/types.ts b/src/store/community/types.ts index d8d660b..3c92888 100644 --- a/src/store/community/types.ts +++ b/src/store/community/types.ts @@ -6,6 +6,8 @@ interface ICommunity { id: string; name?: string; description?: string; + owner?: string; + creationDate?: number; } export { type ICommunityState, type ICommunity }; diff --git a/src/store/role/types.ts b/src/store/role/types.ts index 16a8893..539caf9 100644 --- a/src/store/role/types.ts +++ b/src/store/role/types.ts @@ -5,7 +5,10 @@ interface IRoleState { interface IRole { id: string; name?: string; + description?: string; communityId?: string; + permissions?: string[]; + creationDate?: number; } export { type IRoleState, type IRole }; diff --git a/src/store/user/types.ts b/src/store/user/types.ts index d72a97e..c8cd60d 100644 --- a/src/store/user/types.ts +++ b/src/store/user/types.ts @@ -6,7 +6,11 @@ interface IUserState { interface IUser { id: string; username?: string; + email?: string; description?: string; + admin?: boolean; + registerDate?: number; + lastLogin?: number; communities?: string[]; }