hrms-admin/src/modules/04_system/stores/main.ts

69 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-07-10 17:43:10 +07:00
import { defineStore } from "pinia";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import type { DataBackup } from "@/modules/04_system/interface/response/Main";
import { ref } from "vue";
const mixin = useCounterMixin();
const {
dialogRemove,
messageError,
showLoader,
hideLoader,
success,
dialogConfirm,
} = mixin;
export const useDataStore = defineStore("storeData", () => {
const dataBackUp = ref<DataBackup[]>([]);
async function fetchListBackup() {
showLoader();
await http
.get(config.API.backup)
.then((res) => {
dataBackUp.value = res.data;
})
.finally(() => {
hideLoader();
});
}
async function createBackUp() {
showLoader();
await http
.post(config.API.backup + "/create")
.then(async (res) => {
fetchListBackup();
})
.finally(() => {
console.log("aye");
hideLoader();
});
}
async function restore(filename: string) {
showLoader();
await http
.post(config.API.restore + "?filename=" + filename + "")
.then((res) => {
fetchListBackup();
})
.finally(() => {
hideLoader();
});
}
return {
dataBackUp,
fetchListBackup,
createBackUp,
restore,
};
});