MT#6497 API use billing subscriber id on all places in cf_*_sets

that is:
- api/cfdestinationsets
- api/cftimesets
ipeshinskaya/InvoiceTemplate5
Gerhard Jungwirth 12 years ago
parent 0feca3ea94
commit 2fc4743183

@ -32,9 +32,11 @@ class_has 'query_params' => (
query => {
first => sub {
my $q = shift;
{ subscriber_id => $q };
return { 'voip_subscriber.id' => $q };
},
second => sub {
return { join => {subscriber => 'voip_subscriber'}};
},
second => sub {},
},
},
{
@ -177,13 +179,18 @@ sub POST :Allow {
last;
}
my $subscriber = $schema->resultset('provisioning_voip_subscribers')->find({
my $b_subscriber = $schema->resultset('voip_subscribers')->find({
id => $resource->{subscriber_id},
});
unless($subscriber) {
unless($b_subscriber) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'subscriber_id'.");
last;
}
my $subscriber = $b_subscriber->provisioning_voip_subscriber;
unless($subscriber) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid subscriber.");
last;
}
if (! exists $resource->{destinations} ) {
$resource->{destinations} = [];
}
@ -192,7 +199,7 @@ sub POST :Allow {
last;
}
try {
my $primary_nr_rs = $subscriber->voip_subscriber->primary_number;
my $primary_nr_rs = $b_subscriber->primary_number;
my $number;
if ($primary_nr_rs) {
$number = $primary_nr_rs->cc . ($primary_nr_rs->ac //'') . $primary_nr_rs->sn;
@ -203,7 +210,7 @@ sub POST :Allow {
$dset = $schema->resultset('voip_cf_destination_sets')->create({
name => $resource->{name},
subscriber_id => $resource->{subscriber_id},
subscriber_id => $subscriber->id,
});
for my $d ( @{$resource->{destinations}} ) {
delete $d->{destination_set_id};

@ -32,9 +32,11 @@ class_has 'query_params' => (
query => {
first => sub {
my $q = shift;
{ subscriber_id => $q };
return { 'voip_subscriber.id' => $q };
},
second => sub {
return { join => {subscriber => 'voip_subscriber'}};
},
second => sub {},
},
},
{
@ -176,14 +178,18 @@ sub POST :Allow {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Required: 'subscriber_id'");
last;
}
my $subscriber = $schema->resultset('provisioning_voip_subscribers')->find({
my $b_subscriber = $schema->resultset('voip_subscribers')->find({
id => $resource->{subscriber_id},
});
unless($subscriber) {
unless($b_subscriber) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'subscriber_id'.");
last;
}
my $subscriber = $b_subscriber->provisioning_voip_subscriber;
unless($subscriber) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid subscriber.");
last;
}
if (! exists $resource->{times} ) {
$resource->{times} = [];
}
@ -194,7 +200,7 @@ sub POST :Allow {
try {
$tset = $schema->resultset('voip_cf_time_sets')->create({
name => $resource->{name},
subscriber_id => $resource->{subscriber_id},
subscriber_id => $subscriber->id,
});
for my $t ( @{$resource->{times}} ) {
delete $t->{time_set_id};

@ -38,6 +38,7 @@ sub hal_from_item {
$resource{destinations} = \@destinations;
my $b_subs_id = $item->subscriber->voip_subscriber->id;
$resource{subscriber_id} = $b_subs_id;
my $hal = Data::HAL->new(
links => [
@ -113,14 +114,19 @@ sub update_item {
}
}
my $subscriber = $schema->resultset('provisioning_voip_subscribers')->find($resource->{subscriber_id});
unless ($subscriber) {
my $b_subscriber = $schema->resultset('voip_subscribers')->find($resource->{subscriber_id});
unless ($b_subscriber) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'subscriber_id'.");
return;
}
my $subscriber = $b_subscriber->provisioning_voip_subscriber;
unless($subscriber) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid subscriber.");
last;
}
try {
my $primary_nr_rs = $subscriber->voip_subscriber->primary_number;
my $primary_nr_rs = $b_subscriber->primary_number;
my $number;
if ($primary_nr_rs) {
$number = $primary_nr_rs->cc . ($primary_nr_rs->ac //'') . $primary_nr_rs->sn;
@ -131,7 +137,7 @@ sub update_item {
$item->update({
name => $resource->{name},
subscriber_id => $resource->{subscriber_id},
subscriber_id => $subscriber->id,
})->discard_changes;
$item->voip_cf_destinations->delete;
for my $d ( @{$resource->{destinations}} ) {

@ -78,7 +78,7 @@ sub item_rs {
$item_rs = $c->model('DB')->resultset('voip_subscribers')
->search(
{ status => { '!=' => 'terminated' } },
{ prefetch => 'provisioning_voip_subscriber',}
{ prefetch => 'provisioning_voip_subscriber',},
);
if($c->user->roles eq "reseller") {
$item_rs = $item_rs->search({

@ -34,6 +34,7 @@ sub hal_from_item {
$resource{times} = \@times;
my $b_subs_id = $item->subscriber->voip_subscriber->id;
$resource{subscriber_id} = $b_subs_id;
my $hal = Data::HAL->new(
links => [
@ -102,16 +103,21 @@ sub update_item {
return;
}
my $subscriber = $schema->resultset('provisioning_voip_subscribers')->find($resource->{subscriber_id});
unless ($subscriber) {
my $b_subscriber = $schema->resultset('voip_subscribers')->find($resource->{subscriber_id});
unless ($b_subscriber) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'subscriber_id'.");
return;
}
my $subscriber = $b_subscriber->provisioning_voip_subscriber;
unless($subscriber) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid subscriber.");
last;
}
try {
$item->update({
name => $resource->{name},
subscriber_id => $resource->{subscriber_id},
subscriber_id => $subscriber->id,
})->discard_changes;
$item->voip_cf_periods->delete;
for my $t ( @{$resource->{times}} ) {

@ -86,7 +86,7 @@ sub item_rs {
$item_rs = $c->model('DB')->resultset('voip_subscribers')
->search(
{ status => { '!=' => 'terminated' } },
{ prefetch => 'provisioning_voip_subscriber',}
{ prefetch => 'provisioning_voip_subscriber',},
);
if($c->user->roles eq "reseller") {
$item_rs = $item_rs->search({
@ -197,15 +197,11 @@ sub update_item {
domain => $domain,
uri => $d->{destination},
);
$dset->voip_cf_destinations->update_or_create({
%$d
});
$dset->voip_cf_destinations->update_or_create($d);
}
for my $t (@{ $resource->{$type}{times} }) {
delete $t->{time_set_id};
$tset->voip_cf_periods->update_or_create({
%$t
});
$tset->voip_cf_periods->update_or_create($t);
}
unless ( $dset && $dset->voip_cf_destinations->count ) {
$mapping->delete;

Loading…
Cancel
Save