diff --git a/index.js b/index.js index 61d65f9d5b7dad441311388a7b13cadccac14ec0..cc0b86a3be32adcb0f8160e4d0af4a7fd74e9c10 100644 --- a/index.js +++ b/index.js @@ -317,6 +317,28 @@ async function checkConsentForLoadCurve( } } +/** + * Function checking if the history is loaded + */ +async function isHistoryLoaded(doctype) { + log('debug', doctype, 'Retrieve data') + const result = await cozyClient.data.findAll(doctype) + if (result && result.length > 0) { + const filtered = result.filter(function(el) { + const elDate = moment({ year : el.year, month : el.month, day : el.day}) + return ( + elDate.isBefore(startLoadDate) + ) + }) + if (filtered.length > 0) { + return false + } else { + return true + } + } + return false +} + /** * Launch process to handle load data */ @@ -548,29 +570,6 @@ async function buildDataFromKey(doctype, key, value) { } } -/** - * Function checking if the history is loaded - */ -async function isHistoryLoaded(doctype) { - log('debug', doctype, 'Retrieve data') - const result = await cozyClient.data.findAll(doctype) - if (result && result.length > 0) { - const filtered = result.filter(function(el) { - return ( - el.year <= startLoadDate.year && - el.month <= startLoadDate.month && - el.day <= startLoadDate.day-1 - ) - }) - if (filtered.length > 0) { - return false - } else { - return true - } - } - return false -} - /** * Function handling special case. * The temporary aggregated data need to be remove in order for the most recent one te be saved.