fix: lifetime optional in validation + type — app no longer sends it

validateConsumption required lifetime, but the app stopped sending it
(backend now derives it). asObject(undefined) threw 'body is required',
rejecting every chunk. Now lifetime is optional in both the validator
and the DailyConsumption type.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
TCFDONMEZ
2026-10-09 23:49:57 +03:00
co-authored by Claude
parent 06265bacc9
commit ed5e38bdb8
3 changed files with 18 additions and 13 deletions
+2 -1
View File
@@ -22,7 +22,8 @@ export interface DailyConsumption {
date: string;
recordedAt: Date;
day: Totals;
lifetime: Totals;
/** Optional — the backend derives lifetime as the sum of all days' totals. */
lifetime?: Totals;
sohPercent?: number;
createdAt: Date;
updatedAt: Date;
+4 -1
View File
@@ -21,12 +21,15 @@ export function validateConsumption(body: unknown): ConsumptionInput {
const date = record.date;
if (typeof date !== "string" || !ISO_DATE.test(date)) throw new ValidationError("date is invalid");
const sohPercent = record.sohPercent;
const lifetime = record.lifetime;
return {
installationId: validateUuid(record.installationId, "installationId"),
date,
recordedAt: validateDate(record.recordedAt, "recordedAt"),
day: validateTotals(record.day, "day"),
lifetime: validateTotals(record.lifetime, "lifetime"),
// Lifetime is optional — the backend derives it from day totals, and the app no longer
// sends it. Legacy documents may still carry one; new chunks do not.
...(lifetime === undefined ? {} : { lifetime: validateTotals(lifetime, "lifetime") }),
...(sohPercent === undefined ? {} : { sohPercent: bounded(sohPercent, 0, 100, "sohPercent") }),
};
}