refactor Setting
This commit is contained in:
+20
-15
@@ -1,7 +1,5 @@
|
||||
import { TemplateBizType } from "../types";
|
||||
import Toolkit from "../utils/Toolkit";
|
||||
import { axios } from "./BaseAPI";
|
||||
import Text from "../utils/Text";
|
||||
import {Setting, TemplateBizType} from "../types";
|
||||
import {axios} from "./BaseAPI";
|
||||
|
||||
const getCaptchaAPI = () => axios.defaults.baseURL + "/captcha";
|
||||
|
||||
@@ -11,21 +9,28 @@ async function getTemplate(bizType: TemplateBizType, code: string): Promise<stri
|
||||
return axios.get(`/template?bizType=${bizType}&bizCode=${code}`);
|
||||
}
|
||||
|
||||
async function getSetting(key: string, args?: { [key: string]: any }): Promise<string> {
|
||||
return axios.get(`/setting/${key}?${Text.urlArgs(args)}`);
|
||||
}
|
||||
|
||||
async function listSetting(keyMap: Map<string, object | undefined>): Promise<Map<string, string>> {
|
||||
const result = await axios.post("/setting/map", Toolkit.toObject(keyMap));
|
||||
const map = new Map<string, string>();
|
||||
Object.entries(result).forEach(([key, value]) => map.set(key, value as string));
|
||||
return map;
|
||||
async function settingMap(map: Record<string, string[]>): Promise<Map<string, Map<string, Setting>>> {
|
||||
const raw = await axios.post("/setting/map", map);
|
||||
const moduleMap = new Map<string, Map<string, Setting>>();
|
||||
if (!raw || typeof raw !== "object") {
|
||||
return moduleMap;
|
||||
}
|
||||
for (const [module, settingRawMap] of Object.entries(raw as Record<string, unknown>)) {
|
||||
if (!settingRawMap || typeof settingRawMap !== "object") {
|
||||
continue;
|
||||
}
|
||||
const settingMap = new Map<string, Setting>();
|
||||
for (const [key, setting] of Object.entries(settingRawMap as Record<string, Setting>)) {
|
||||
settingMap.set(key, setting);
|
||||
}
|
||||
moduleMap.set(module, settingMap);
|
||||
}
|
||||
return moduleMap;
|
||||
}
|
||||
|
||||
export default {
|
||||
getCaptchaAPI,
|
||||
getAttachmentReadAPI,
|
||||
getTemplate,
|
||||
getSetting,
|
||||
listSetting
|
||||
settingMap
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user