ff-admin/src/stores/admin/configuration/templateUsage.ts

52 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-12-23 14:00:32 +01:00
import { defineStore } from "pinia";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
2025-02-15 11:08:09 +01:00
import type {
CreateTemplateViewModel,
UpdateTemplateViewModel,
} from "@/viewmodels/admin/configuration/template.models";
import type {
TemplateUsageViewModel,
UpdateTemplateUsageViewModel,
} from "@/viewmodels/admin/configuration/templateUsage.models";
2024-12-26 12:34:36 +01:00
import type { PermissionModule } from "@/types/permissionTypes";
2024-12-23 14:00:32 +01:00
export const useTemplateUsageStore = defineStore("templateUsage", {
state: () => {
return {
templateUsages: [] as Array<TemplateUsageViewModel>,
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";
});
},
2024-12-24 13:53:00 +01:00
async previewTemplateUsage(scope: PermissionModule): Promise<AxiosResponse<any, any>> {
return await http.get(`/admin/templateusage/${scope}`, {
responseType: "blob",
});
},
2024-12-23 14:00:32 +01:00
async updateTemplateUsage(templateUsage: UpdateTemplateUsageViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/templateusage/${templateUsage.scope}`, {
headerId: templateUsage.headerId,
bodyId: templateUsage.bodyId,
footerId: templateUsage.footerId,
2025-01-01 13:21:35 +01:00
headerHeight: templateUsage.headerHeight,
footerHeight: templateUsage.footerHeight,
2024-12-23 14:00:32 +01:00
});
this.fetchTemplateUsages();
return result;
},
},
});