fix: check template usages being present after backup

This commit is contained in:
Julian Krauser 2025-03-28 22:28:07 +01:00
parent df231d6462
commit 7b27c7d49a
3 changed files with 35 additions and 3 deletions

View file

@ -6,6 +6,7 @@ import InternalException from "../exceptions/internalException";
import UserService from "../service/management/userService";
import { BACKUP_COPIES, BACKUP_INTERVAL } from "../env.defaults";
import DatabaseActionException from "../exceptions/databaseActionException";
import { availableTemplates } from "../type/templateTypes";
export type BackupSection =
| "member"
@ -743,11 +744,30 @@ export default abstract class BackupHelper {
.values(data?.["template"] ?? [])
.orIgnore()
.execute();
let templates = await this.transactionManager.getRepository("template").find();
let dataWithMappedId = (data?.["template_usage"] ?? [])
.filter((d) => availableTemplates.includes(d.scope))
.map((d) => ({
...d,
headerHeightId: templates.find((template) => template.template == d.headerHeight.template)?.id ?? null,
footerHeightId: templates.find((template) => template.template == d.footerHeight.template)?.id ?? null,
headerId: templates.find((template) => template.template == d.header.template)?.id ?? null,
bodyId: templates.find((template) => template.template == d.body.template)?.id ?? null,
footerId: templates.find((template) => template.template == d.footer.template)?.id ?? null,
}));
availableTemplates.forEach((at) => {
if (!dataWithMappedId.some((d) => d.scope == at)) {
dataWithMappedId.push({
scope: at,
});
}
});
await this.transactionManager
.createQueryBuilder()
.insert()
.into("template_usage")
.values(data?.["template_usage"] ?? [])
.values(dataWithMappedId)
.orIgnore()
.execute();
}

View file

@ -3,6 +3,7 @@ import { PermissionModule } from "../type/permissionTypes";
import TemplateUsageService from "../service/configuration/templateUsageService";
import Handlebars, { template } from "handlebars";
import { FileSystemHelper } from "./fileSystemHelper";
import { TemplateFormat } from "../type/templateTypes";
export abstract class TemplateHelper {
static getTemplateFromFile(template: string) {
@ -40,7 +41,7 @@ export abstract class TemplateHelper {
bodyData = {},
footerData = {},
}: {
module: `${PermissionModule}` | `${PermissionModule}.${string}`;
module: TemplateFormat;
title?: string;
headerData?: any;
bodyData?: any;
@ -88,7 +89,7 @@ export abstract class TemplateHelper {
footerData = {},
customTemplate,
}: {
module: `${PermissionModule}` | `${PermissionModule}.${string}`;
module: TemplateFormat;
title?: string;
headerData?: any;
bodyData?: any;

11
src/type/templateTypes.ts Normal file
View file

@ -0,0 +1,11 @@
import { PermissionModule } from "./permissionTypes";
export type TemplateFormat = `${PermissionModule}` | `${PermissionModule}.${string}`;
export const availableTemplates: Array<TemplateFormat> = [
"member",
"listprint",
"listprint.member",
"newsletter",
"protocol",
];