org-network / frontend /src /services /defaultsService.ts
5minbetter's picture
deploy: initial clean workspace without lfs history
33d9e63
Raw
History Blame Contribute Delete
1.31 kB
import { NetworkType, StrengthOption, Question } from '../types';
import { apiClient } from './apiClient';
export interface SystemDefaults {
NETWORK_TYPES: NetworkType[];
STRENGTH_OPTIONS: StrengthOption[];
QUESTIONS: Question[];
NOTICE_TEMPLATE: string;
}
export const defaultsService = {
// Get system defaults from backend API
async getDefaults(): Promise<SystemDefaults> {
try {
return await apiClient.get<SystemDefaults>('/ops/defaults');
} catch (e) {
console.error('Failed to fetch defaults from backend', e);
return {
NETWORK_TYPES: [],
STRENGTH_OPTIONS: [],
QUESTIONS: [],
NOTICE_TEMPLATE: '',
};
}
},
// Save new system defaults to backend API
async saveDefaults(updatedDefaults: SystemDefaults): Promise<void> {
try {
await apiClient.put<any>('/ops/defaults', updatedDefaults);
} catch (e) {
console.error('Failed to save defaults to backend', e);
throw e;
}
},
// Reset system defaults to factory static settings on backend API
async resetDefaults(): Promise<SystemDefaults> {
try {
return await apiClient.post<SystemDefaults>('/ops/defaults/reset');
} catch (e) {
console.error('Failed to reset defaults on backend', e);
throw e;
}
}
};