From 0574a4f90cd8faf8ec722f668710fe93d7d8109d Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Thu, 26 Jul 2018 07:17:17 +0200 Subject: [PATCH] TT#40507 tz and use_owner_tz query params for /api/conversations Change-Id: Ic1fcb2e158cc2a10341d52b88cb75c32d7a273c1 --- .../Panel/Controller/API/Conversations.pm | 20 ++++++++++--------- lib/NGCP/Panel/Role/API/Conversations.pm | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/NGCP/Panel/Controller/API/Conversations.pm b/lib/NGCP/Panel/Controller/API/Conversations.pm index 1e3b55cdce..80a3acb802 100644 --- a/lib/NGCP/Panel/Controller/API/Conversations.pm +++ b/lib/NGCP/Panel/Controller/API/Conversations.pm @@ -22,6 +22,14 @@ sub api_description { sub query_params { return [ + { + param => 'tz', + description => 'Format timestamp according to the optional time zone provided here, e.g. Europe/Berlin.', + }, + { + param => 'use_owner_tz', + description => 'Format timestamp according to the filtered customer\'s/subscribers\'s inherited time zone.', + }, { param => 'subscriber_id', description => 'Filter for conversation events of a specific subscriber. Either this or customer_id filter is mandatory if called by admin, reseller or subscriberadmin.', @@ -61,16 +69,10 @@ sub query_params { sub order_by_cols { my ($self, $c) = @_; my $cols = { - 'timestamp' => 'me.timestamp', - 'type' => 'me.type', + 'start_time' => 'timestamp', + 'timestamp' => 'timestamp', + 'type' => 'type', }; - my $params = $c->request->params; - if (defined $c->request->params->{type}) { - #fax_journal and othre type tables does not have 'timestamp' field ('time' instead in fax_journal). - #So in unwrapped query (e.g. when we ask fax_journal by querying type=fax), we need to refer to timestamp - alias of the "time" field, without table alias prefix "me." - $cols->{type} = 'type'; - $cols->{timestamp} = 'timestamp'; - } return $cols; } diff --git a/lib/NGCP/Panel/Role/API/Conversations.pm b/lib/NGCP/Panel/Role/API/Conversations.pm index e532190ae4..17a8bbea3a 100644 --- a/lib/NGCP/Panel/Role/API/Conversations.pm +++ b/lib/NGCP/Panel/Role/API/Conversations.pm @@ -245,7 +245,7 @@ sub get_mandatory_params { my $owner = $self->get_owner_cached($c); return unless $owner; my %mandatory_params = ( - $owner->{subscriber} + $owner->{subscriber} ? ( subscriber_id => $owner->{subscriber}->id ) : ( customer_id => $owner->{customer}->id ) ); @@ -428,7 +428,7 @@ sub _get_call_rs { }),NGCP::Panel::Utils::CallList::SUPPRESS_OUT,@suppression_aliases); my $in_rs = NGCP::Panel::Utils::CallList::call_list_suppressions_rs($c,$rs->search_rs({ destination_user_id => $uuid, - source_user_id => { '!=' => $uuid }, + source_user_id => { '!=' => $uuid }, }),NGCP::Panel::Utils::CallList::SUPPRESS_IN,@suppression_aliases); $self->_apply_direction(params => $params, @@ -563,7 +563,7 @@ sub _get_sms_rs { select => [ { '' => \'"sms"', -as => 'type' }, { '' => 'me.id', -as => 'id' }, - { '' => 'me.time', -as => 'timestamp' }, + { '' => \'unix_timestamp(me.time)', -as => 'timestamp' }, _get_select_list(\%sms_fields), ], as => ['type','id','timestamp',_get_as_list(\%sms_fields),], @@ -772,7 +772,7 @@ sub process_hal_resource { @{$resource}{qw/caller callee/} = @{$resource}{qw/own_cli other_cli/}; } else { @{$resource}{qw/caller callee/} = @{$resource}{qw/other_cli own_cli/}; - } + } $resource->{type} = $item->{type}; my $fee; if ($fee = $schema->resultset('billing_fees_history')->search_rs({ @@ -812,21 +812,19 @@ sub process_hal_resource { $resource->{call_id} = $item_mock_obj->call_id; }elsif('sms' eq $item->{type}){ $resource = $item_accessors_hash; - $resource->{start_time} = NGCP::Panel::Utils::DateTime::from_string($item_mock_obj->timestamp)->epoch; + #$resource->{start_time} = NGCP::Panel::Utils::DateTime::from_string($item_mock_obj->timestamp)->epoch; }elsif('xmpp' eq $item->{type}){ $resource = $item_accessors_hash; } $c->log->debug(Dumper('resource')); $c->log->debug(Dumper($resource)); - if($item_mock_obj->timestamp){ - $resource->{start_time} //= $item_mock_obj->timestamp; + $resource->{start_time} = undef; + if ($item_mock_obj->timestamp) { my $datetime_fmt = DateTime::Format::Strptime->new( pattern => '%F %T', ); - my $timestamp = NGCP::Panel::Utils::DateTime::epoch_local($resource->{start_time}); - #if($c->req->param('tz') && DateTime::TimeZone->is_valid_name($c->req->param('tz'))) { - # $timestamp->set_time_zone($c->req->param('tz')); - #} + my $timestamp = NGCP::Panel::Utils::API::Calllist::apply_owner_timezone($self,$c, + NGCP::Panel::Utils::DateTime::epoch_local($item_mock_obj->timestamp),$self->get_owner_cached($c)); $resource->{start_time} = $datetime_fmt->format_datetime($timestamp); $resource->{start_time} .= '.' . $timestamp->millisecond if $timestamp->millisecond > 0.0; }