diff options
author | Florian Dold <florian@dold.me> | 2024-11-08 20:22:34 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-11-08 20:22:34 +0100 |
commit | c1be508a35610f9678cb372208fe8bc9da563b1f (patch) | |
tree | dd501a5a419e2df07b0b2ebe41455e4f2cd005d8 | |
parent | 748536ad26e295bfe8c9ed2a36cbc18257c1f80a (diff) |
fix broken insert_aml_decision query
Check to avoid duplicates was broken
-rw-r--r-- | src/exchangedb/exchange_do_insert_aml_decision.sql | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/exchangedb/exchange_do_insert_aml_decision.sql b/src/exchangedb/exchange_do_insert_aml_decision.sql index 3a6c28c00..b84127071 100644 --- a/src/exchangedb/exchange_do_insert_aml_decision.sql +++ b/src/exchangedb/exchange_do_insert_aml_decision.sql @@ -44,7 +44,6 @@ BEGIN out_account_unknown=FALSE; out_legitimization_measure_serial_id=0; - -- Check officer is eligible to make decisions. PERFORM FROM aml_staff @@ -108,22 +107,17 @@ THEN INTO my_access_token; END IF; --- AML decision: mark all active measures finished! -UPDATE legitimization_measures - SET is_finished=TRUE - WHERE access_token=my_access_token - AND NOT is_finished; - -- Did KYC measures get prescribed? IF in_jmeasures IS NOT NULL THEN -- First check if a perfectly equivalent legi measure -- already exists, to avoid creating tons of duplicates. - PERFORM + SELECT legitimization_measure_serial_id + INTO out_legitimization_measure_serial_id FROM legitimization_measures - WHERE access_token=my_access_token - AND jmeasures=in_jmeasures - AND NOT is_finished; + WHERE access_token=my_access_token + AND jmeasures=in_jmeasures + AND NOT is_finished; IF NOT FOUND THEN @@ -143,10 +137,16 @@ THEN INTO out_legitimization_measure_serial_id; END IF; - -- end if for where we had in_jmeasures END IF; +-- AML decision: mark all other active measures finished! +UPDATE legitimization_measures + SET is_finished=TRUE + WHERE access_token=my_access_token + AND NOT is_finished + AND legitimization_measure_serial_id != out_legitimization_measure_serial_id; + UPDATE legitimization_outcomes SET is_active=FALSE WHERE h_payto=in_h_normalized_payto |