| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- // web/services/userSettingService.ts
- import { API_BASE_URL } from '../utils/constants';
- import { AppSettings } from '../types'; // Frontend AppSettings interface
- // Assuming backend returns all AppSettings fields, plus id, userId, createdAt, updatedAt
- interface UserSettingResponse extends AppSettings {
- id: string;
- userId: string;
- createdAt: Date;
- updatedAt: Date;
- }
- export const userSettingService = {
- async get(token: string): Promise<UserSettingResponse> {
- const response = await fetch(`${API_BASE_URL}/settings`, {
- method: 'GET',
- headers: {
- 'Content-Type': 'application/json',
- Authorization: `Bearer ${token}`,
- },
- });
- if (!response.ok) {
- const errorData = await response.json();
- throw new Error(errorData.message || 'Failed to fetch user settings');
- }
- return response.json();
- },
- async update(token: string, settings: Partial<AppSettings>): Promise<UserSettingResponse> {
- const response = await fetch(`${API_BASE_URL}/settings`, {
- method: 'PUT',
- headers: {
- 'Content-Type': 'application/json',
- Authorization: `Bearer ${token}`,
- },
- body: JSON.stringify(settings),
- });
- if (!response.ok) {
- const errorData = await response.json();
- throw new Error(errorData.message || 'Failed to update user settings');
- }
- return response.json();
- },
- };
|