import { defineStore } from "pinia"; import { http } from "@/serverCom"; import type { AxiosResponse } from "axios"; import type { CreateTemplateViewModel, UpdateTemplateViewModel, } from "@/viewmodels/admin/configuration/template.models"; import type { TemplateUsageViewModel, UpdateTemplateUsageViewModel, } from "@/viewmodels/admin/configuration/templateUsage.models"; import type { PermissionModule } from "@/types/permissionTypes"; export const useTemplateUsageStore = defineStore("templateUsage", { state: () => { return { templateUsages: [] as Array, loading: "loading" as "loading" | "fetched" | "failed", }; }, actions: { fetchTemplateUsages() { this.loading = "loading"; http .get("/admin/templateusage") .then((result) => { this.templateUsages = result.data; this.loading = "fetched"; }) .catch((err) => { this.loading = "failed"; }); }, async previewTemplateUsage(scope: PermissionModule): Promise> { return await http.get(`/admin/templateusage/${scope}`, { responseType: "blob", }); }, async updateTemplateUsage(templateUsage: UpdateTemplateUsageViewModel): Promise> { const result = await http.patch(`/admin/templateusage/${templateUsage.scope}`, { headerId: templateUsage.headerId, bodyId: templateUsage.bodyId, footerId: templateUsage.footerId, headerHeight: templateUsage.headerHeight, footerHeight: templateUsage.footerHeight, }); this.fetchTemplateUsages(); return result; }, }, });