Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support fillter call cdr by sip_callid #16

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ const createCdrQuerySP = ({page, page_size, trunk, direction, answered, filter,
if (trunk) sql += 'AND trunk = $trunk ';
if (direction) sql += 'AND direction = $direction ';
if (['true', 'false'].includes(answered)) sql += 'AND answered = $answered ';
if (filter) sql += `AND ("from" =~ /.*${filter}.*/ OR "to" =~ /.*${filter}.*/ OR call_sid = $filter) `;
if (filter) sql += `AND ("from" =~ /.*${filter}.*/ OR "to" =~ /.*${filter}.*/ OR
call_sid = $filter OR sip_callid = $filter) `;
if (days) sql += 'AND time > $timestamp ';
else {
if (start) sql += 'AND time >= $start ';
Expand All @@ -217,7 +218,8 @@ const createCdrCountQuerySP = ({trunk, direction, answered, filter, days, start,
if (trunk) sql += 'AND trunk = $trunk ';
if (direction) sql += 'AND direction = $direction ';
if (['true', 'false'].includes(answered)) sql += 'AND answered = $answered ';
if (filter) sql += `AND ("from" =~ /.*${filter}.*/ OR "to" =~ /.*${filter}.*/ OR call_sid = $filter) `;
if (filter) sql += `AND ("from" =~ /.*${filter}.*/ OR "to" =~ /.*${filter}.*/ OR
call_sid = $filter OR sip_callid = $filter)`;
if (days) sql += 'AND time > $timestamp ';
else {
if (start) sql += 'AND time >= $start ';
Expand All @@ -232,7 +234,8 @@ const createCdrQuery = ({page, page_size, trunk, direction, answered, filter, da
if (trunk) sql += 'AND trunk = $trunk ';
if (direction) sql += 'AND direction = $direction ';
if (['true', 'false'].includes(answered)) sql += 'AND answered = $answered ';
if (filter) sql += `AND ("from" =~ /.*${filter}.*/ OR "to" =~ /.*${filter}.*/ OR call_sid = $filter) `;
if (filter) sql += `AND ("from" =~ /.*${filter}.*/ OR "to" =~ /.*${filter}.*/ OR
call_sid = $filter OR sip_callid = $filter) `;
if (days) sql += 'AND time > $timestamp ';
else {
if (start) sql += 'AND time >= $start ';
Expand All @@ -248,7 +251,8 @@ const createCdrCountQuery = ({trunk, direction, answered, filter, days, start, e
if (trunk) sql += 'AND trunk = $trunk ';
if (direction) sql += 'AND direction = $direction ';
if (['true', 'false'].includes(answered)) sql += 'AND answered = $answered ';
if (filter) sql += `AND ("from" =~ /.*${filter}.*/ OR "to" =~ /.*${filter}.*/ OR call_sid = $filter) `;
if (filter) sql += `AND ("from" =~ /.*${filter}.*/ OR "to" =~ /.*${filter}.*/ OR
call_sid = $filter OR sip_callid = $filter) `;
if (days) sql += 'AND time > $timestamp ';
else {
if (start) sql += 'AND time >= $start ';
Expand Down
3 changes: 3 additions & 0 deletions test/unit-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ test('write timeseries data', async(t) => {
result = await queryCdrsSP({service_provider_sid: 'zzzzz', filter: 'you2', page: 1, page_size:25});
t.ok(result.data.length === 1, 'queried cdrs by service provider sid and ot')

result = await queryCdrsSP({service_provider_sid: 'zzzzz', filter: 'foo@127.0.0.1', page: 1, page_size:25});
t.ok(result.data.length === 2, 'queried cdrs by service provider sid and sip_callid')

result = await writeAlerts([
{
alert_type: AlertType.WEBHOOK_STATUS_FAILURE,
Expand Down