import { defineStore } from "pinia"; import type { CreateAwardViewModel, UpdateAwardViewModel, AwardViewModel } from "@/viewmodels/admin/award.models"; import { http } from "@/serverCom"; import type { AxiosResponse } from "axios"; import type { TableMeta } from "../../viewmodels/admin/query.models"; import type { DynamicQueryStructure } from "../../types/dynamicQueries"; export const useQueryBuilderStore = defineStore("queryBuilder", { state: () => { return { tableMetas: [] as Array, loading: "loading" as "loading" | "fetched" | "failed", data: [] as Array<{ id: number; [key: string]: any }>, totalLength: 0 as number, loadingData: "failed" as "loading" | "fetched" | "failed", query: undefined as undefined | DynamicQueryStructure, isLoadedQuery: undefined as undefined | number, }; }, actions: { fetchTableMetas() { this.loading = "loading"; http .get("/admin/querybuilder/tables") .then((result) => { this.tableMetas = result.data; this.loading = "fetched"; }) .catch((err) => { this.loading = "failed"; }); }, sendQuery(offset = 0, count = 25) { if (this.query == undefined) return; this.loadingData = "loading"; http .post(`/admin/querybuilder/query?offset=${offset}&count=${count}`, { query: this.query, }) .then((result) => { this.data = result.data.rows; this.totalLength = result.data.total; this.loadingData = "fetched"; }) .catch((err) => { this.loadingData = "failed"; }); }, clearResults() { this.data = []; this.totalLength = 0; }, }, });