Skip to content

Commit

Permalink
✨ Get everything
Browse files Browse the repository at this point in the history
  • Loading branch information
xeloader committed Nov 13, 2020
1 parent bac8c35 commit 1c8ffbe
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,27 @@ const arrToCSV = (items = []) => {
return csvStr
}

getAllBills().then(async (customers) => {
const flattened = customers.map(flatten)
const csv = arrToCSV(flattened)
const getEverything = async () => {
const [
bills,
customers
] = await Promise.all([
getAllBills(),
getAllCustomers()
])
return {
bills,
customers
}
}

const fileName = `billogram-bills-${new Date().toISOString()}.csv`
saveToFile(csv, fileName)
}).catch((err) => {
console.log('error', err)
})
getEverything()
.then((everything) => {
const timestamp = new Date().toISOString()
const getFileName = (category) => `${timestamp}-${category}.csv`
const keys = Object.keys(everything)
const flatData = keys.map((key) => everything[key].map(flatten))
const csvs = keys.map((_, i) => arrToCSV(flatData[i]))
keys.forEach((key, i) => saveToFile(csvs[i], getFileName(key)))
console.log('SUCCESS, export is available in the export/ folder.')
})

0 comments on commit 1c8ffbe

Please sign in to comment.