File size: 1,308 Bytes
33d9e63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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;
    }
  }
};