From f28d426b176385be726eec536686e3c2544d0caa Mon Sep 17 00:00:00 2001 From: Net <93821485+somnetsak123@users.noreply.github.com> Date: Wed, 10 Jul 2024 17:43:10 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=95=E0=B9=88=E0=B8=AD=20api=20=20backUp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/04_system/stores/main.ts | 68 ++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/modules/04_system/stores/main.ts diff --git a/src/modules/04_system/stores/main.ts b/src/modules/04_system/stores/main.ts new file mode 100644 index 00000000..5e7287af --- /dev/null +++ b/src/modules/04_system/stores/main.ts @@ -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([]); + + 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, + }; +});