feat: add profit field to transactions

This commit is contained in:
Sérgio Salgado 2022-02-25 18:46:40 +00:00
parent 4339e58e6a
commit 64a4860df0
3 changed files with 15 additions and 10 deletions

View file

@ -49,6 +49,7 @@ const typeDef = gql`
batchTime: Date
batchError: String
walletScore: Int
profit: String
}
type Filter {

View file

@ -24,6 +24,13 @@ function addNames (txs) {
})
}
function addProfits (txs) {
return _.map(it => {
const profit = getProfit(it).toString()
return _.set('profit', profit, it)
}, txs)
}
const camelize = _.mapKeys(_.camelCase)
function batch (
@ -42,7 +49,7 @@ function batch (
excludeTestingCustomers = false,
simplified = false
) {
const packager = _.flow(_.flatten, _.orderBy(_.property('created'), ['desc']), _.map(camelize), addNames)
const packager = _.flow(_.flatten, _.orderBy(_.property('created'), ['desc']), _.map(camelize), addProfits, addNames)
const cashInSql = `SELECT 'cashIn' AS tx_class, txs.*,
c.phone AS customer_phone,