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:
@@ -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;
|
||||
|
||||
@@ -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") }),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user