feat: add script to clean up parsed ID data from corrupt parsed data

This commit is contained in:
Sérgio Salgado 2022-05-30 03:44:12 +01:00
parent 0b3f566806
commit b67fb577ca

View file

@ -0,0 +1,41 @@
#!/usr/bin/env node
const argv = require('minimist')(process.argv.slice(2))
const _ = require('lodash')
const db = require('../lib/db')
const txId = argv.tx
const customerId = argv.customer
if ((!txId && !customerId) || (txId && customerId)) {
console.log('Usage: lamassu-clean-parsed-id [--tx <txId> | --customer <customerId>]')
console.log('The command can only be run with EITHER --tx OR --customer, NOT BOTH')
process.exit(2)
}
if (!_.isNil(txId)) {
db.oneOrNone('SELECT * FROM (SELECT id, customer_id FROM cash_in_txs UNION SELECT id, customer_id FROM cash_out_txs) as txs WHERE txs.id = $1', [txId])
.then(res => {
return db.none('UPDATE customers SET id_card_data = null WHERE id = $1', [res.customer_id])
.then(() => {
console.log(`ID card data from customer ${res.customer_id} was cleared with success`)
process.exit(0)
})
})
.catch(() => {
console.log('A transaction with that ID was not found')
process.exit(0)
})
}
if (!_.isNil(customerId)) {
db.none('UPDATE customers SET id_card_data = null WHERE id = $1', [customerId])
.then(() => {
console.log(`ID card data from customer ${customerId} was cleared with success`)
process.exit(0)
})
.catch(() => {
console.log('A customer with that ID was not found')
process.exit(0)
})
}