🏷️(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';
|
import { fetchAPI } from '@/api';
|
||||||
|
|
||||||
/**
|
import { User } from './types';
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously retrieves the current user's data from the API.
|
* Asynchronously retrieves the current user's data from the API.
|
||||||
@@ -20,12 +10,12 @@ export interface UserData {
|
|||||||
* @async
|
* @async
|
||||||
* @function getMe
|
* @function getMe
|
||||||
* @throws {Error} Throws an error if the API request fails.
|
* @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/`);
|
const response = await fetchAPI(`users/me/`);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Couldn't fetch user data: ${response.statusText}`);
|
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 './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 './Auth';
|
||||||
export * from './useAuthStore';
|
export * from './useAuthStore';
|
||||||
|
export * from './api/types';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
|
|
||||||
import { UserData, getMe } from '@/features/auth/api';
|
import { User, getMe } from '@/features/auth/api';
|
||||||
|
|
||||||
export const login = () => {
|
export const login = () => {
|
||||||
window.location.replace(
|
window.location.replace(
|
||||||
@@ -12,7 +12,7 @@ interface AuthStore {
|
|||||||
authenticated: boolean;
|
authenticated: boolean;
|
||||||
initAuth: () => void;
|
initAuth: () => void;
|
||||||
logout: () => void;
|
logout: () => void;
|
||||||
userData?: UserData;
|
userData?: User;
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
@@ -26,7 +26,7 @@ export const useAuthStore = create<AuthStore>((set) => ({
|
|||||||
|
|
||||||
initAuth: () => {
|
initAuth: () => {
|
||||||
getMe()
|
getMe()
|
||||||
.then((data: UserData) => {
|
.then((data: User) => {
|
||||||
set({ authenticated: true, userData: data });
|
set({ authenticated: true, userData: data });
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { User } from '@/features/auth/';
|
||||||
|
|
||||||
export enum Role {
|
export enum Role {
|
||||||
MEMBER = 'member',
|
MEMBER = 'member',
|
||||||
ADMIN = 'administrator',
|
ADMIN = 'administrator',
|
||||||
@@ -8,6 +10,13 @@ export interface Access {
|
|||||||
id: string;
|
id: string;
|
||||||
role: Role;
|
role: Role;
|
||||||
user: User;
|
user: User;
|
||||||
|
abilities: {
|
||||||
|
delete: boolean;
|
||||||
|
get: boolean;
|
||||||
|
patch: boolean;
|
||||||
|
put: boolean;
|
||||||
|
set_role_to: Role[];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Team {
|
export interface Team {
|
||||||
@@ -16,10 +25,11 @@ export interface Team {
|
|||||||
accesses: Access[];
|
accesses: Access[];
|
||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
}
|
abilities: {
|
||||||
|
delete: boolean;
|
||||||
export interface User {
|
get: boolean;
|
||||||
id: string;
|
manage_accesses: boolean;
|
||||||
email: string;
|
patch: boolean;
|
||||||
name?: string;
|
put: boolean;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user