From db1f6da27c94ee54cd531caf80211384fc72e610 Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Tue, 10 Jun 2014 12:48:59 +0200 Subject: [PATCH] MT#7377 API: check uniqueness of pbx_extension. Otherwise we get a duplicate entry error when creating the corresponding primary number. --- lib/NGCP/Panel/Role/API/Subscribers.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/NGCP/Panel/Role/API/Subscribers.pm b/lib/NGCP/Panel/Role/API/Subscribers.pm index 53afa1f548..fa47c819e4 100644 --- a/lib/NGCP/Panel/Role/API/Subscribers.pm +++ b/lib/NGCP/Panel/Role/API/Subscribers.pm @@ -306,6 +306,18 @@ sub prepare_resource { $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "A pbx_extension is required if customer is PBX and pilot subscriber exists."); return; } + + my $ext_rs = $pilot->contract->voip_subscribers->search({ + 'provisioning_voip_subscriber.pbx_extension' => $resource->{pbx_extension}, + },{ + join => 'provisioning_voip_subscriber', + }); + if($ext_rs->first) { + $c->log->error("trying to add pbx_extension to contract id " . $pilot->contract_id . ", which is already in use by subscriber id " . $ext_rs->first->id); + $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "The pbx_extension already exists for this customer."); + return; + } + $resource->{e164}->{cc} = $pilot->primary_number->cc; $resource->{e164}->{ac} = $pilot->primary_number->ac // ''; $resource->{e164}->{sn} = $pilot->primary_number->sn . $resource->{pbx_extension};