2022-06-17 19:25:24 +02:00
|
|
|
import type { RawSettingValue } from "@/data/Setting/RawSettingValue";
|
2022-06-17 18:08:04 +02:00
|
|
|
import type { SettingDescrition } from "@/data/Setting/SettingDescription";
|
2022-06-17 19:25:24 +02:00
|
|
|
import { useEventQueuStore } from "@/stores/eventQueu";
|
2022-06-17 18:08:04 +02:00
|
|
|
import { useUserStore } from "@/stores/user";
|
|
|
|
import axios from "axios";
|
|
|
|
|
2022-06-17 19:25:24 +02:00
|
|
|
function getSettingDescrition() {
|
2022-06-17 18:08:04 +02:00
|
|
|
return new Promise<SettingDescrition[]>((resole, reject) => {
|
|
|
|
const userStore = useUserStore();
|
|
|
|
|
|
|
|
axios
|
|
|
|
.get<SettingDescrition[]>("/setting/description", {
|
|
|
|
headers: {
|
|
|
|
authorization: `Bearer ${userStore.token}`,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then((value) => {
|
|
|
|
resole(value.data);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2022-06-17 19:25:24 +02:00
|
|
|
|
|
|
|
function getSettingValues(guildId: string): Promise<RawSettingValue[]> {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const userStore = useUserStore();
|
|
|
|
axios
|
|
|
|
.get<RawSettingValue[]>(`/setting/${guildId}/values`, {
|
|
|
|
headers: {
|
|
|
|
authorization: `Bearer ${userStore.token}`,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then((value) => {
|
|
|
|
resolve(value.data);
|
|
|
|
})
|
|
|
|
.catch((reason) => {
|
|
|
|
console.error(`Fail to get settings !`);
|
|
|
|
console.log(reason);
|
|
|
|
const eventQueuStore = useEventQueuStore();
|
|
|
|
eventQueuStore.push({
|
|
|
|
uuid: undefined,
|
|
|
|
type: "error",
|
|
|
|
text: "Fail to retrive current settings!",
|
|
|
|
});
|
|
|
|
reject(reason);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export { getSettingDescrition, getSettingValues };
|