fix: check template usages being present after backup
This commit is contained in:
parent
df231d6462
commit
7b27c7d49a
3 changed files with 35 additions and 3 deletions
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue