38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
|
import { defineStore } from "pinia";
|
||
|
import { http } from "@/serverCom";
|
||
|
import type { AxiosResponse } from "axios";
|
||
|
import type { CreateTemplateViewModel, UpdateTemplateViewModel } from "../../viewmodels/admin/template.models";
|
||
|
import type { TemplateUsageViewModel, UpdateTemplateUsageViewModel } from "../../viewmodels/admin/templateUsage.models";
|
||
|
|
||
|
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";
|
||
|
});
|
||
|
},
|
||
|
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,
|
||
|
});
|
||
|
this.fetchTemplateUsages();
|
||
|
return result;
|
||
|
},
|
||
|
},
|
||
|
});
|