Phase2: Invoicecomputation/AdminpricingUI/Ainvoicemgnt
All checks were successful
Build and Push / build (push) Successful in 1m36s

This commit is contained in:
2026-05-24 14:48:40 +02:00
parent d41f0b6ec9
commit 11d7dbb06e

View File

@@ -341,15 +341,21 @@ async function collectThreemaUsage(
): Promise<{ inCount: number; outCount: number } | null> { ): Promise<{ inCount: number; outCount: number } | null> {
const packages = tenant.spec.packages ?? []; const packages = tenant.spec.packages ?? [];
if (!packages.includes("threema")) return null; if (!packages.includes("threema")) return null;
const usage = await getThreemaUsage( // threema-relay.getUsage takes Date params, not strings, and
tenant.metadata.name, // returns a discriminated RelayResult<UsageBreakdown> — the
periodStart, // `ok` discriminant must be checked before reading the totals.
periodEnd // Period end is exclusive in the relay's API; pass the next-day
).catch(() => null); // midnight UTC to capture the full last day of the period.
if (!usage) return null; const from = new Date(`${periodStart}T00:00:00Z`);
const to = new Date(`${periodEnd}T00:00:00Z`);
to.setUTCDate(to.getUTCDate() + 1);
const result = await getThreemaUsage(tenant.metadata.name, from, to).catch(
() => null
);
if (!result || !result.ok) return null;
return { return {
inCount: Number(usage.totals?.in ?? 0), inCount: Number(result.totals?.in ?? 0),
outCount: Number(usage.totals?.out ?? 0), outCount: Number(result.totals?.out ?? 0),
}; };
} }