diff --git a/package.json b/package.json index a14bada..5645e0b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@digital-alchemy/grocy", "repository": "https://github.com/Digital-Alchemy-TS/grocy", "homepage": "https://docs.digital-alchemy.app/Grocy", - "version": "0.3.4", + "version": "0.3.5", "scripts": { "build": "tsc", "lint": "eslint src", diff --git a/src/extensions/chores.extension.ts b/src/extensions/chores.extension.ts index 4b5a14b..02e3525 100644 --- a/src/extensions/chores.extension.ts +++ b/src/extensions/chores.extension.ts @@ -73,7 +73,7 @@ export function Chores({ grocy, logger }: TServiceParams) { async recalculateAssignments() { logger.trace("recalculateAssignments"); - return await this.grocy({ + return await grocy.fetch({ url: `/chores/executions/calculate-next-assignments`, }); }, diff --git a/src/extensions/system.extension.ts b/src/extensions/system.extension.ts index f1192bd..76947f1 100644 --- a/src/extensions/system.extension.ts +++ b/src/extensions/system.extension.ts @@ -3,24 +3,32 @@ import dayjs, { Dayjs } from "dayjs"; import { GROCY_DATABASE_UPDATED } from "../helpers"; -export function System({ lifecycle, grocy, logger }: TServiceParams) { +export function System({ + lifecycle, + grocy, + logger, + event, + config, +}: TServiceParams) { + let LAST_CHANGED_TIME: Dayjs; + lifecycle.onBootstrap(async () => { try { - this.LAST_CHANGED_TIME = await this.getSystemDbChangedTime(); + LAST_CHANGED_TIME = await grocy.system.getSystemDbChangedTime(); } catch { - this.logger.fatal("Cannot contact grocy"); + logger.fatal("Cannot contact grocy"); } setInterval(async () => { try { - const last = await this.getSystemDbChangedTime(); - if (last.isAfter(this.LAST_CHANGED_TIME)) { - this.LAST_CHANGED_TIME = last; - this.event.emit(GROCY_DATABASE_UPDATED); + const last = await grocy.system.getSystemDbChangedTime(); + if (last.isAfter(LAST_CHANGED_TIME)) { + LAST_CHANGED_TIME = last; + event.emit(GROCY_DATABASE_UPDATED); } } catch (error) { - this.logger.error({ error }, "Grocy database time poll failed"); + logger.error({ error }, "Grocy database time poll failed"); } - }, this.pollInterval); + }, config.grocy.POLL_INTERVAL); }); return {