From 0ed92e5fa45fa74a79ffe771b4c618391d39f3b8 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 9 Dec 2011 15:51:49 -0500 Subject: [PATCH] Alert addresses for patron registration : API Middle-layer API call for matching addresses to alert addresses open-ils.actor.address_alert.test(auth, orgid, fields) Signed-off-by: Bill Erickson Signed-off-by: Thomas Berezansky --- .../src/perlmods/lib/OpenILS/Application/Actor.pm | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index 03a20aab6b..c54debf431 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -4363,5 +4363,50 @@ sub get_barcodes { return $db_result; } } +__PACKAGE__->register_method( + method => 'address_alert_test', + api_name => 'open-ils.actor.address_alert.test', + signature => { + desc => "Tests a set of address fields to determine if they match with an address_alert", + params => [ + {desc => 'Authentication token', type => 'string'}, + {desc => 'Org Unit', type => 'number'}, + {desc => 'Fields', type => 'hash'}, + ], + return => {desc => 'List of matching address_alerts'} + } +); + +sub address_alert_test { + my ($self, $client, $auth, $org_unit, $fields) = @_; + return [] unless $fields and grep {$_} values %$fields; + + my $e = new_editor(authtoken => $auth); + return $e->event unless $e->checkauth; + return $e->event unless $e->allowed('CREATE_USER', $org_unit); + $org_unit ||= $e->requestor->ws_ou; + + my $alerts = $e->json_query({ + from => [ + 'actor.address_alert_matches', + $org_unit, + $$fields{street1}, + $$fields{street2}, + $$fields{city}, + $$fields{county}, + $$fields{state}, + $$fields{country}, + $$fields{post_code}, + $$fields{mailing_address}, + $$fields{billing_address} + ] + }); + + # map the json_query hashes to real objects + return [ + map {$e->retrieve_actor_address_alert($_)} + (map {$_->{id}} @$alerts) + ]; +} 1; -- 2.11.0