forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-current-summaries.js
More file actions
38 lines (33 loc) · 961 Bytes
/
update-current-summaries.js
File metadata and controls
38 lines (33 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const updateCurrentSummaries = (
arrayEquals,
loadCurrentDates,
updateThirtyDays,
updateMonthSummary,
) => async ({ domain, domainId, dates }) => {
console.info(`\tUpdating thirty days, and current month data for: ${domain}`)
// Update thirty days month
await updateThirtyDays({ domain, domainId })
// Get current start dates in db
const dbStartDates = await loadCurrentDates()
const dateArrEqual = arrayEquals(dates, dbStartDates)
if (dateArrEqual) {
// Update Current Month
await updateMonthSummary({
dateToRemove: dates[dates.length - 1].startDate,
dateToAdd: dates[dates.length - 1].startDate,
domain,
domainId,
})
} else {
// Remove first month, and create new month
await updateMonthSummary({
dateToRemove: dbStartDates[0].startDate,
dateToAdd: dates[dates.length - 1].startDate,
domain,
domainId,
})
}
}
module.exports = {
updateCurrentSummaries,
}