🏷️(app-desk) update interfaces business logic
Update interfaces of User / Team / Access to get what is needed for the frontend.
This commit is contained in:
@@ -1,16 +1,6 @@
|
||||
import { fetchAPI } from '@/api';
|
||||
|
||||
/**
|
||||
* Represents user data retrieved from the API.
|
||||
* This interface is incomplete, and will be
|
||||
* refactored in a near future.
|
||||
*
|
||||
* @interface UserData
|
||||
* @property {string} email - The email of the user.
|
||||
*/
|
||||
export interface UserData {
|
||||
email: string;
|
||||
}
|
||||
import { User } from './types';
|
||||
|
||||
/**
|
||||
* Asynchronously retrieves the current user's data from the API.
|
||||
@@ -20,12 +10,12 @@ export interface UserData {
|
||||
* @async
|
||||
* @function getMe
|
||||
* @throws {Error} Throws an error if the API request fails.
|
||||
* @returns {Promise<UserData>} A promise that resolves to the user data.
|
||||
* @returns {Promise<User>} A promise that resolves to the user data.
|
||||
*/
|
||||
export const getMe = async (): Promise<UserData> => {
|
||||
export const getMe = async (): Promise<User> => {
|
||||
const response = await fetchAPI(`users/me/`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Couldn't fetch user data: ${response.statusText}`);
|
||||
}
|
||||
return response.json() as Promise<UserData>;
|
||||
return response.json() as Promise<User>;
|
||||
};
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
export * from './getMe';
|
||||
export * from './types';
|
||||
|
||||
12
src/frontend/apps/desk/src/features/auth/api/types.ts
Normal file
12
src/frontend/apps/desk/src/features/auth/api/types.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Represents user retrieved from the API.
|
||||
* @interface User
|
||||
* @property {string} id - The id of the user.
|
||||
* @property {string} email - The email of the user.
|
||||
* @property {string} name - The name of the user.
|
||||
*/
|
||||
export interface User {
|
||||
id: string;
|
||||
email: string;
|
||||
name?: string;
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from './Auth';
|
||||
export * from './useAuthStore';
|
||||
export * from './api/types';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { create } from 'zustand';
|
||||
|
||||
import { UserData, getMe } from '@/features/auth/api';
|
||||
import { User, getMe } from '@/features/auth/api';
|
||||
|
||||
export const login = () => {
|
||||
window.location.replace(
|
||||
@@ -12,7 +12,7 @@ interface AuthStore {
|
||||
authenticated: boolean;
|
||||
initAuth: () => void;
|
||||
logout: () => void;
|
||||
userData?: UserData;
|
||||
userData?: User;
|
||||
}
|
||||
|
||||
const initialState = {
|
||||
@@ -26,7 +26,7 @@ export const useAuthStore = create<AuthStore>((set) => ({
|
||||
|
||||
initAuth: () => {
|
||||
getMe()
|
||||
.then((data: UserData) => {
|
||||
.then((data: User) => {
|
||||
set({ authenticated: true, userData: data });
|
||||
})
|
||||
.catch(() => {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { User } from '@/features/auth/';
|
||||
|
||||
export enum Role {
|
||||
MEMBER = 'member',
|
||||
ADMIN = 'administrator',
|
||||
@@ -8,6 +10,13 @@ export interface Access {
|
||||
id: string;
|
||||
role: Role;
|
||||
user: User;
|
||||
abilities: {
|
||||
delete: boolean;
|
||||
get: boolean;
|
||||
patch: boolean;
|
||||
put: boolean;
|
||||
set_role_to: Role[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface Team {
|
||||
@@ -16,10 +25,11 @@ export interface Team {
|
||||
accesses: Access[];
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface User {
|
||||
id: string;
|
||||
email: string;
|
||||
name?: string;
|
||||
abilities: {
|
||||
delete: boolean;
|
||||
get: boolean;
|
||||
manage_accesses: boolean;
|
||||
patch: boolean;
|
||||
put: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user