refactor: userpreferences are now in the DB
This commit is contained in:
@@ -52,6 +52,13 @@ export class HttpClient {
|
||||
});
|
||||
}
|
||||
|
||||
async put<T>(endpoint: string, data?: unknown): Promise<T> {
|
||||
return this.request<T>(endpoint, {
|
||||
method: 'PUT',
|
||||
body: data ? JSON.stringify(data) : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
async patch<T>(endpoint: string, data?: unknown): Promise<T> {
|
||||
return this.request<T>(endpoint, {
|
||||
method: 'PATCH',
|
||||
|
||||
77
clients/user-preferences-client.ts
Normal file
77
clients/user-preferences-client.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { httpClient } from './base/http-client';
|
||||
import { UserPreferences, KanbanFilters, ViewPreferences, ColumnVisibility } from '@/lib/types';
|
||||
|
||||
export interface UserPreferencesResponse {
|
||||
success: boolean;
|
||||
data?: UserPreferences;
|
||||
message?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface UserPreferencesUpdateResponse {
|
||||
success: boolean;
|
||||
message?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Client HTTP pour les préférences utilisateur
|
||||
*/
|
||||
export const userPreferencesClient = {
|
||||
/**
|
||||
* Récupère toutes les préférences utilisateur
|
||||
*/
|
||||
async getPreferences(): Promise<UserPreferences> {
|
||||
const response = await httpClient.get<UserPreferencesResponse>('/user-preferences');
|
||||
|
||||
if (!response.success || !response.data) {
|
||||
throw new Error(response.error || 'Erreur lors de la récupération des préférences');
|
||||
}
|
||||
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sauvegarde toutes les préférences utilisateur
|
||||
*/
|
||||
async savePreferences(preferences: UserPreferences): Promise<void> {
|
||||
const response = await httpClient.put<UserPreferencesUpdateResponse>('/user-preferences', preferences);
|
||||
|
||||
if (!response.success) {
|
||||
throw new Error(response.error || 'Erreur lors de la sauvegarde des préférences');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Met à jour les filtres Kanban
|
||||
*/
|
||||
async updateKanbanFilters(filters: Partial<KanbanFilters>): Promise<void> {
|
||||
const response = await httpClient.patch<UserPreferencesUpdateResponse>('/user-preferences/kanban-filters', filters);
|
||||
|
||||
if (!response.success) {
|
||||
throw new Error(response.error || 'Erreur lors de la mise à jour des filtres Kanban');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Met à jour les préférences de vue
|
||||
*/
|
||||
async updateViewPreferences(preferences: Partial<ViewPreferences>): Promise<void> {
|
||||
const response = await httpClient.patch<UserPreferencesUpdateResponse>('/user-preferences/view-preferences', preferences);
|
||||
|
||||
if (!response.success) {
|
||||
throw new Error(response.error || 'Erreur lors de la mise à jour des préférences de vue');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Met à jour la visibilité des colonnes
|
||||
*/
|
||||
async updateColumnVisibility(visibility: Partial<ColumnVisibility>): Promise<void> {
|
||||
const response = await httpClient.patch<UserPreferencesUpdateResponse>('/user-preferences/column-visibility', visibility);
|
||||
|
||||
if (!response.success) {
|
||||
throw new Error(response.error || 'Erreur lors de la mise à jour de la visibilité des colonnes');
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user