MT#63066 /api/subscriberphonebook add filter by customer_id

* customer_id is now present in the response
* customer_id is supported as the query parameter

Change-Id: Ia529fa653b165f743c006cb99f6518ae686e517c
mr13.5
Kirill Solomko 4 months ago
parent aeea350706
commit a38cd246c4

@ -32,6 +32,19 @@ sub order_by_cols {
sub query_params {
return [
{
param => 'customer_id',
description => 'Filter for Phonebook entries belonging to a specific customer',
query => {
first => sub {
my $q = shift;
{
'subscriber.contract_id' => $q,
};
},
second => sub {},
},
},
{
param => 'subscriber_id',
description => 'Filter for Phonebook entries belonging to a specific subscriber',

@ -13,6 +13,16 @@ has_field 'id' => (
},
);
has_field 'customer_id' => (
type => 'PosInteger',
required => 0,
label => 'Phonebook entry customer id',
element_attr => {
rel => ['tooltip'],
title => ['Phonebook entry customer id'],
},
);
has_field 'subscriber_id' => (
type => 'PosInteger',
required => 0,

@ -28,21 +28,36 @@ sub _item_rs {
}
}
if ($c->user->roles eq 'reseller' || $c->user->roles eq 'ccare') {
if ($c->user->roles eq 'admin' || $c->user->roles eq 'ccareadmin') {
$item_rs = $item_rs->search({
},{
join => 'subscriber',
'+select' => [qw/subscriber.contract_id/],
'+as' => [qw/customer_id/],
});
} elsif ($c->user->roles eq 'reseller' || $c->user->roles eq 'ccare') {
$item_rs = $item_rs->search({
'contact.reseller_id' => $c->user->reseller_id,
},{
join => { subscriber => { contract => 'contact' } },
'+select' => [qw/subscriber.contract_id/],
'+as' => [qw/customer_id/],
});
} elsif ($c->user->roles eq 'subscriberadmin') {
$item_rs = $item_rs->search({
'subscriber.contract_id' => $c->user->account_id,
},{
join => 'subscriber',
'+select' => [qw/subscriber.contract_id/],
'+as' => [qw/customer_id/],
});
} elsif ($c->user->roles eq 'subscriber') {
$item_rs = $item_rs->search({
'subscriber_id' => $c->user->voip_subscriber->id,
},{
join => 'subscriber',
'+select' => [qw/subscriber.contract_id/],
'+as' => [qw/customer_id/],
});
}

Loading…
Cancel
Save