From 3f225d2d5828887a64029a4b537db48c86243606 Mon Sep 17 00:00:00 2001 From: oat_dev Date: Thu, 11 Jul 2024 11:38:45 +0700 Subject: [PATCH] =?UTF-8?q?store=20log=20=E0=B8=81=E0=B8=B1=E0=B8=9A=20typ?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../03_logs/interface/response/Main.ts | 15 +++- src/modules/03_logs/stores/main.ts | 69 ++++++++++++++++++- 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/src/modules/03_logs/interface/response/Main.ts b/src/modules/03_logs/interface/response/Main.ts index da7e9293..eccb7813 100644 --- a/src/modules/03_logs/interface/response/Main.ts +++ b/src/modules/03_logs/interface/response/Main.ts @@ -11,4 +11,17 @@ interface ResRound { startDate: Date; } -export type { ResRound }; +interface ResLog { + endTimeStamp: Date; + endpoint: string; + host: string; + logType: string; + method: string; + processTime: number; + responseCode: number; + startTimeStamp: Date; + systemName: string; + tId: string; +} + +export type { ResRound, ResLog }; diff --git a/src/modules/03_logs/stores/main.ts b/src/modules/03_logs/stores/main.ts index b96ea3e0..4c27779c 100644 --- a/src/modules/03_logs/stores/main.ts +++ b/src/modules/03_logs/stores/main.ts @@ -1,5 +1,72 @@ import { defineStore } from "pinia"; +import http from "@/plugins/http"; +import config from "@/app.config"; +import { useQuasar } from "quasar"; + +import { useCounterMixin } from "@/stores/mixin"; + +import type { ResLog } from "@/modules/03_logs/interface/response/Main"; +const $q = useQuasar(); +import { ref } from "vue"; + +const mixin = useCounterMixin(); +const { + dialogRemove, + messageError, + showLoader, + hideLoader, + success, + dialogConfirm, +} = mixin; export const useDataStore = defineStore("storeData", () => { - return {}; + const size = ref(30); + const logData = ref([]); + const systemName = ref(""); + const searchAfter = ref(); + async function fetchLog( + opts?: { + size?: number; + search?: string; + searchAfter?: number; + systemName?: string; + }, + isBottom?: boolean + ) { + const params = new URLSearchParams(); + + for (const [k, v] of Object.entries(opts || {})) { + v !== undefined && params.append(k, v.toString()); + } + + const query = params.toString(); + showLoader(); + await http + .get(config.API.log + `${(params && "?".concat(query)) || ""}`) + .then((res) => { + const data = res.data; + if (isBottom) { + const test = data.map((v: any) => v._source); + logData.value.push(...test); + } else { + logData.value = data.map((v: any) => v._source); + } + + const lastDataSort = data[data.length - 1].sort; + if (lastDataSort) { + searchAfter.value = lastDataSort[0]; + } + }) + .finally(() => { + hideLoader(); + }); + } + + return { + size, + logData, + searchAfter, + systemName, + fetchLog, + }; });