fix(accounting): validate serial invoice templates
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 43s
Build and Push Docker Images / build-frontend (push) Successful in 1m13s
Build and Push Docker Images / build-website (push) Successful in 24s
Build and Push Docker Images / build-central-services-api (push) Successful in 22s
Build and Push Docker Images / build-central-services-admin (push) Successful in 22s
Build and Push Docker Images / build-docs (push) Successful in 22s

This commit is contained in:
2026-09-09 14:38:24 +02:00
parent ebbd1e0cd0
commit a50ff256ee

View File

@@ -37,7 +37,8 @@ export const executeManualGeneration = async (
if (!tenant) throw new Error(`Tenant mit ID ${tenantId} nicht gefunden.`);
// 2. Templates laden
const templates = await server.db
const uniqueTemplateIds = [...new Set(templateIds)]
const templates = (await server.db
.select()
.from(schema.createddocuments)
.where(
@@ -45,13 +46,13 @@ export const executeManualGeneration = async (
eq(schema.createddocuments.tenant, tenantId),
eq(schema.createddocuments.type, "serialInvoices"),
eq(schema.createddocuments.archived, false),
inArray(schema.createddocuments.id, templateIds)
inArray(schema.createddocuments.id, uniqueTemplateIds)
)
);
))
.filter((template) => Boolean((template.serialConfig as any)?.active));
if (templates.length === 0) {
console.warn("Keine passenden Vorlagen gefunden.");
throw new Error("Keine passenden Serienrechnungsvorlagen gefunden.");
if (templates.length !== uniqueTemplateIds.length) {
throw new Error("Mindestens eine Serienrechnungsvorlage wurde nicht gefunden, ist archiviert oder inaktiv.");
}
// 3. Folder & FileType IDs holen (Hilfsfunktionen unten)
@@ -67,7 +68,7 @@ export const executeManualGeneration = async (
executionDate: executionDayjs.toDate(),
status: "draft",
createdBy: executedBy,
summary: `${templateIds.length} Vorlagen verarbeitet`
summary: `${uniqueTemplateIds.length} Vorlagen verarbeitet`
})
.returning();