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

85 lines
1.6 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(() => {
2024-07-10 17:51:13 +07:00
hideLoader();
});
}
async function deleteBackUp(filename: string) {
showLoader();
await http
.delete(config.API.backup + "/delete", {
data: { filename: filename },
})
.then(async (res) => {
fetchListBackup();
})
.finally(() => {
2024-07-10 17:43:10 +07:00
hideLoader();
});
}
async function restore(filename: string) {
showLoader();
await http
2024-07-10 17:51:13 +07:00
.post(config.API.restore, {
filename: filename,
})
2024-07-10 17:43:10 +07:00
.then((res) => {
fetchListBackup();
})
.finally(() => {
hideLoader();
});
}
return {
dataBackUp,
fetchListBackup,
createBackUp,
restore,
2024-07-10 17:51:13 +07:00
deleteBackUp,
2024-07-10 17:43:10 +07:00
};
});