mirror of
https://github.com/stonith404/pingvin-share.git
synced 2025-01-29 01:28:59 -05:00
24 lines
674 B
TypeScript
24 lines
674 B
TypeScript
|
import Config from "../types/config.type";
|
||
|
import api from "./api.service";
|
||
|
|
||
|
const getAll = async (): Promise<Config[]> => {
|
||
|
return (await api.get("/configs")).data;
|
||
|
};
|
||
|
|
||
|
const get = (key: string, configVariables: Config[]): any => {
|
||
|
const configVariable = configVariables.filter(
|
||
|
(variable) => variable.key == key
|
||
|
)[0];
|
||
|
|
||
|
if (!configVariable) throw new Error(`Config variable ${key} not found`);
|
||
|
|
||
|
if (configVariable.type == "number") return parseInt(configVariable.value);
|
||
|
if (configVariable.type == "boolean") return configVariable.value == "true";
|
||
|
if (configVariable.type == "string") return configVariable.value;
|
||
|
};
|
||
|
|
||
|
export default {
|
||
|
getAll,
|
||
|
get,
|
||
|
};
|