From 8307b4f715bf8c76b0b6c74ef93555335b05fba8 Mon Sep 17 00:00:00 2001 From: Tiago Rodrigues Date: Mon, 25 Nov 2024 12:10:04 +0000 Subject: [PATCH] add start date --- config.js | 7 ++++++- edenredService.js | 6 ++++-- index.js | 4 ---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/config.js b/config.js index f77e30f..b7ebff1 100644 --- a/config.js +++ b/config.js @@ -16,6 +16,7 @@ const EDENRED_ACCOUNT = process.env.EDENRED_ACCOUNT || ""; const ACTUAL_ACCOUNT = process.env.ACTUAL_ACCOUNT || ""; const CRON_EXPRESSION = process.env.CRON_EXPRESSION || ""; const ACTUAL_SYNC_ID = process.env.ACTUAL_SYNC_ID || ""; +const IMPORT_FROM = process.env.IMPORT_FROM || ""; function getAppConfigFromEnv() { @@ -43,6 +44,9 @@ function getAppConfigFromEnv() { EDENRED_ACCOUNT_MAPPING[edenred] = actualSplit; ACTUAL_ACCOUNT_MAPPING[actualSplit] = edenred; } + if (IMPORT_FROM == "") { + IMPORT_FROM = "1970-01-01" + } const appConfig = { APP_PORT, APP_URL, @@ -54,7 +58,8 @@ function getAppConfigFromEnv() { ACTUAL_SERVER_URL, ACTUAL_SERVER_PASSWORD, ACTUAL_SYNC_ID, - CRON_EXPRESSION + CRON_EXPRESSION, + IMPORT_FROM } // Assert that all required environment variables are set diff --git a/edenredService.js b/edenredService.js index 8feb57d..87356ec 100644 --- a/edenredService.js +++ b/edenredService.js @@ -1,3 +1,4 @@ +const { config } = require("dotenv"); const { getAppConfigFromEnv } = require("./config"); const crypto = require('crypto'); @@ -39,7 +40,8 @@ const getAllTransactions = async (token, accountId) => { }, }) .then((response) => response.json()) - .then((json) => json.data.movementList) + .then((json) => + json.data.movementList) .catch((err) => { console.error("error occured", err); }); @@ -55,7 +57,7 @@ async function getTransactions(accountId) { transactionID = crypto.createHash('sha256').update(transaction.transactionName+transaction.transactionDate+transaction.amount).digest('hex'); date = transaction.transactionDate.split("T")[0] - if (date < '2024-06-21') { + if (date < appConfig.IMPORT_FROM) { return; } parsedTransactions.push({ diff --git a/index.js b/index.js index 821891b..65f7d30 100644 --- a/index.js +++ b/index.js @@ -29,10 +29,6 @@ const cli = meow( alias: "a", type: "string", }, - since: { - alias: "s", - type: "string", - }, }, } );