From b67fb577cae8cb52423643bd7a3f4b7480c65141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Mon, 30 May 2022 03:44:12 +0100 Subject: [PATCH] feat: add script to clean up parsed ID data from corrupt parsed data --- bin/lamassu-clean-parsed-id | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 bin/lamassu-clean-parsed-id diff --git a/bin/lamassu-clean-parsed-id b/bin/lamassu-clean-parsed-id new file mode 100644 index 00000000..ab3d3e58 --- /dev/null +++ b/bin/lamassu-clean-parsed-id @@ -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 | --customer ]') + 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) + }) +} \ No newline at end of file