ต่อ api backUp

This commit is contained in:
Net 2024-07-10 17:43:10 +07:00
parent 3ad75ba890
commit f28d426b17

View file

@ -0,0 +1,68 @@
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,
};
});