Phase2: Invoicecomputation/AdminpricingUI/Ainvoicemgnt
All checks were successful
Build and Push / build (push) Successful in 1m36s
All checks were successful
Build and Push / build (push) Successful in 1m36s
This commit is contained in:
@@ -341,15 +341,21 @@ async function collectThreemaUsage(
|
||||
): Promise<{ inCount: number; outCount: number } | null> {
|
||||
const packages = tenant.spec.packages ?? [];
|
||||
if (!packages.includes("threema")) return null;
|
||||
const usage = await getThreemaUsage(
|
||||
tenant.metadata.name,
|
||||
periodStart,
|
||||
periodEnd
|
||||
).catch(() => null);
|
||||
if (!usage) return null;
|
||||
// threema-relay.getUsage takes Date params, not strings, and
|
||||
// returns a discriminated RelayResult<UsageBreakdown> — the
|
||||
// `ok` discriminant must be checked before reading the totals.
|
||||
// Period end is exclusive in the relay's API; pass the next-day
|
||||
// midnight UTC to capture the full last day of the period.
|
||||
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 {
|
||||
inCount: Number(usage.totals?.in ?? 0),
|
||||
outCount: Number(usage.totals?.out ?? 0),
|
||||
inCount: Number(result.totals?.in ?? 0),
|
||||
outCount: Number(result.totals?.out ?? 0),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user