48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { apiFetch } from './client';
|
|
import { API_ENDPOINTS } from './config';
|
|
|
|
export interface SettingResponse {
|
|
setting_id: string;
|
|
setting_key: string;
|
|
setting_value: unknown;
|
|
description: string | null;
|
|
is_public: boolean;
|
|
updated_at: string;
|
|
}
|
|
|
|
export interface SettingCreate {
|
|
setting_key: string;
|
|
setting_value: unknown;
|
|
description?: string;
|
|
is_public?: boolean;
|
|
}
|
|
|
|
export interface SettingUpdate {
|
|
setting_value: unknown;
|
|
description?: string;
|
|
is_public?: boolean;
|
|
}
|
|
|
|
export const settingsService = {
|
|
async getPublic(): Promise<SettingResponse[]> {
|
|
return apiFetch<SettingResponse[]>(API_ENDPOINTS.SETTINGS_PUBLIC);
|
|
},
|
|
|
|
async getByKey(key: string): Promise<SettingResponse> {
|
|
return apiFetch<SettingResponse>(API_ENDPOINTS.SETTINGS_BY_KEY(key));
|
|
},
|
|
|
|
async create(data: SettingCreate): Promise<SettingResponse> {
|
|
return apiFetch<SettingResponse>(API_ENDPOINTS.SETTINGS_CREATE, {
|
|
method: 'POST',
|
|
body: JSON.stringify(data),
|
|
});
|
|
},
|
|
|
|
async update(key: string, data: SettingUpdate): Promise<SettingResponse> {
|
|
return apiFetch<SettingResponse>(API_ENDPOINTS.SETTINGS_UPDATE(key), {
|
|
method: 'PUT',
|
|
body: JSON.stringify(data),
|
|
});
|
|
},
|
|
};
|