Skip to content

Commit

Permalink
fix: add logger
Browse files Browse the repository at this point in the history
  • Loading branch information
mdvanes committed May 13, 2024
1 parent 3119aa7 commit 96600af
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions apps/server/src/energyusage/energyusage.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ const getNormalizedEntries =

const getDayUsage = (
day: Date,
usePerDayTotals: GetDomoticzUsePerDayResponse["result"]
usePerDayTotals: GetDomoticzUsePerDayResponse["result"],
logger: Logger
): number | undefined => {
const yearMonthDay = day.toISOString().slice(0, 10);
try {
Expand All @@ -144,15 +145,15 @@ const getDayUsage = (
// console.log("dayUsage1", dayUsage, yearMonthDay, dayUsageDay, day);
return dayUsage;
} catch (err) {
console.log(`Can't get dayUsage for ${yearMonthDay}`);
logger.warn(`Can't get dayUsage for ${yearMonthDay}`);
return undefined;
}
};

const ELECTRIC_EXPORTS_ROOT_DIR = "./0_electric_exports";

const exportJsonToRow =
(usePerDayTotals: GetDomoticzUsePerDayResponse["result"]) =>
(usePerDayTotals: GetDomoticzUsePerDayResponse["result"], logger: Logger) =>
async (
fileInDir: string
): Promise<EnergyUsageGetElectricExportsResponse[0] | undefined> => {
Expand All @@ -170,7 +171,7 @@ const exportJsonToRow =
getNormalizedEntries(fileJson)
);

const dayUsage = getDayUsage(day, usePerDayTotals);
const dayUsage = getDayUsage(day, usePerDayTotals, logger);

const result: EnergyUsageGetElectricExportsResponse[0] = {
exportName: fileInDir,
Expand All @@ -185,7 +186,7 @@ const exportJsonToRow =

return result;
} catch (err) {
console.log(`Can't process ${fileInDir}`);
logger.warn(`Can't process ${fileInDir}`);
return undefined;
}
};
Expand Down Expand Up @@ -411,7 +412,7 @@ export class EnergyUsageController {
await Promise.all(
filteredFilesInDir.map<
Promise<EnergyUsageGetElectricExportsResponse[0]>
>(exportJsonToRow(usePerDayTotals))
>(exportJsonToRow(usePerDayTotals, this.logger))
);

return usagePerDay.filter(isDefined);
Expand Down

0 comments on commit 96600af

Please sign in to comment.