Built motion from commit (unavailable).|2.4.4
[motion2.git] / server / api / cdr / cdr.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x7e12=['intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filter','map','key','VIRTUAL','field','merge','options','include','findAll','rows','catch','show','params','includeAll','create','body','find','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','util','path','sox','to-csv','ejs','lodash','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../mysqldb','sendStatus','status','end','json','count','offset','limit','reject','update','then','destroy','stack','name','send','index','Cdr','rawAttributes','model','keys','query','filters'];(function(_0x246148,_0x1358ee){var _0x453d94=function(_0x59920e){while(--_0x59920e){_0x246148['push'](_0x246148['shift']());}};_0x453d94(++_0x1358ee);}(_0x7e12,0x1c5));var _0x27e1=function(_0x46f1a6,_0xc7a582){_0x46f1a6=_0x46f1a6-0x0;var _0x38429a=_0x7e12[_0x46f1a6];return _0x38429a;};'use strict';var pdf=require(_0x27e1('0x0'));var emlformat=require(_0x27e1('0x1'));var rimraf=require(_0x27e1('0x2'));var zipdir=require(_0x27e1('0x3'));var jsonpatch=require(_0x27e1('0x4'));var rp=require(_0x27e1('0x5'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x27e1('0x6'));var path=require(_0x27e1('0x7'));var sox=require(_0x27e1('0x8'));var csv=require(_0x27e1('0x9'));var ejs=require(_0x27e1('0xa'));var fs=require('fs');var _=require(_0x27e1('0xb'));var squel=require('squel');var crypto=require(_0x27e1('0xc'));var jsforce=require(_0x27e1('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x27e1('0x9'));var querystring=require(_0x27e1('0xe'));var Papa=require(_0x27e1('0xf'));var Redis=require(_0x27e1('0x10'));var authService=require(_0x27e1('0x11'));var qs=require(_0x27e1('0x12'));var hardwareService=require(_0x27e1('0x13'));var logger=require('../../config/logger')(_0x27e1('0x14'));var utils=require(_0x27e1('0x15'));var config=require('../../config/environment');var db=require(_0x27e1('0x16'))['db'];function respondWithStatusCode(_0x1abde3,_0x4d6417){_0x4d6417=_0x4d6417||0xcc;return function(_0x5a705a){if(_0x5a705a){return _0x1abde3[_0x27e1('0x17')](_0x4d6417);}return _0x1abde3[_0x27e1('0x18')](_0x4d6417)[_0x27e1('0x19')]();};}function respondWithResult(_0x151dd1,_0x36e1b0){_0x36e1b0=_0x36e1b0||0xc8;return function(_0x305387){if(_0x305387){return _0x151dd1['status'](_0x36e1b0)[_0x27e1('0x1a')](_0x305387);}};}function respondWithFilteredResult(_0x3785eb,_0x185602){return function(_0x38f454){if(_0x38f454){var _0x47023=_0x38f454[_0x27e1('0x1b')],_0x41d372=_0x185602[_0x27e1('0x1c')],_0x3d3341=_0x185602[_0x27e1('0x1c')]+_0x185602[_0x27e1('0x1d')],_0x56ad5f;if(_0x3d3341>=_0x47023){_0x3d3341=_0x47023;_0x56ad5f=0xc8;}else{_0x56ad5f=0xce;}_0x3785eb['status'](_0x56ad5f);return _0x3785eb['set']('Content-Range',_0x41d372+'-'+_0x3d3341+'/'+_0x47023)[_0x27e1('0x1a')](_0x38f454);}return null;};}function patchUpdates(_0x535cf3){return function(_0xd8220a){try{jsonpatch['apply'](_0xd8220a,_0x535cf3,!![]);}catch(_0x23b4c8){return BPromise[_0x27e1('0x1e')](_0x23b4c8);}return _0xd8220a['save']();};}function saveUpdates(_0x1c7e6e,_0x3f433a){return function(_0x434046){if(_0x434046){return _0x434046[_0x27e1('0x1f')](_0x1c7e6e)[_0x27e1('0x20')](function(_0x19f3dd){return _0x19f3dd;});}return null;};}function removeEntity(_0x3457d4,_0xe3e3a6){return function(_0x3b4305){if(_0x3b4305){return _0x3b4305[_0x27e1('0x21')]()[_0x27e1('0x20')](function(){_0x3457d4['status'](0xcc)[_0x27e1('0x19')]();});}};}function handleEntityNotFound(_0x404be3,_0x2d095d){return function(_0x1554fd){if(!_0x1554fd){_0x404be3['sendStatus'](0x194);}return _0x1554fd;};}function handleError(_0x37f360,_0x3edc07){_0x3edc07=_0x3edc07||0x1f4;return function(_0x483d84){logger['error'](_0x483d84[_0x27e1('0x22')]);if(_0x483d84[_0x27e1('0x23')]){delete _0x483d84[_0x27e1('0x23')];}_0x37f360['status'](_0x3edc07)[_0x27e1('0x24')](_0x483d84);};}exports[_0x27e1('0x25')]=function(_0x286ff3,_0x52a1e9){var _0x46aad9={},_0x2e49dd={},_0x1107c9={'count':0x0,'rows':[]};var _0x296042=db[_0x27e1('0x26')][_0x27e1('0x27')];_0x2e49dd[_0x27e1('0x28')]=_[_0x27e1('0x29')](_0x296042);_0x2e49dd[_0x27e1('0x2a')]=_[_0x27e1('0x29')](_0x286ff3[_0x27e1('0x2a')]);_0x2e49dd[_0x27e1('0x2b')]=_[_0x27e1('0x2c')](_0x2e49dd[_0x27e1('0x28')],_0x2e49dd[_0x27e1('0x2a')]);_0x46aad9[_0x27e1('0x2d')]=_[_0x27e1('0x2c')](_0x2e49dd[_0x27e1('0x28')],qs[_0x27e1('0x2e')](_0x286ff3['query'][_0x27e1('0x2e')]));_0x46aad9[_0x27e1('0x2d')]=_0x46aad9[_0x27e1('0x2d')][_0x27e1('0x2f')]?_0x46aad9[_0x27e1('0x2d')]:_0x2e49dd[_0x27e1('0x28')];if(!_0x286ff3[_0x27e1('0x2a')][_0x27e1('0x30')](_0x27e1('0x31'))){_0x46aad9[_0x27e1('0x1d')]=qs[_0x27e1('0x1d')](_0x286ff3[_0x27e1('0x2a')][_0x27e1('0x1d')]);_0x46aad9[_0x27e1('0x1c')]=qs[_0x27e1('0x1c')](_0x286ff3[_0x27e1('0x2a')][_0x27e1('0x1c')]);}_0x46aad9[_0x27e1('0x32')]=qs['sort'](_0x286ff3[_0x27e1('0x2a')][_0x27e1('0x33')]);_0x46aad9[_0x27e1('0x34')]=qs['filters'](_['pick'](_0x286ff3['query'],_0x2e49dd[_0x27e1('0x2b')]));if(_0x286ff3['query'][_0x27e1('0x35')]){_0x46aad9[_0x27e1('0x34')]=_['merge'](_0x46aad9[_0x27e1('0x34')],{'$or':_[_0x27e1('0x36')](_0x296042,function(_0x2d8e61){if(_0x2d8e61['type'][_0x27e1('0x37')]!==_0x27e1('0x38')){var _0x3b4e69={};_0x3b4e69[_0x2d8e61[_0x27e1('0x39')]]={'$like':'%'+_0x286ff3[_0x27e1('0x2a')]['filter']+'%'};return _0x3b4e69;}})});}_0x46aad9=_[_0x27e1('0x3a')]({},_0x46aad9,_0x286ff3[_0x27e1('0x3b')]);var _0x44b761={'where':_0x46aad9[_0x27e1('0x34')]};return db['Cdr'][_0x27e1('0x1b')](_0x44b761)[_0x27e1('0x20')](function(_0x46334a){_0x1107c9[_0x27e1('0x1b')]=_0x46334a;if(_0x286ff3[_0x27e1('0x2a')]['includeAll']){_0x46aad9[_0x27e1('0x3c')]=[{'all':!![]}];}return db[_0x27e1('0x26')][_0x27e1('0x3d')](_0x46aad9);})[_0x27e1('0x20')](function(_0xf90a44){_0x1107c9[_0x27e1('0x3e')]=_0xf90a44;return _0x1107c9;})[_0x27e1('0x20')](respondWithFilteredResult(_0x52a1e9,_0x46aad9))[_0x27e1('0x3f')](handleError(_0x52a1e9,null));};exports[_0x27e1('0x40')]=function(_0x44531e,_0x5e485b){var _0x463e5b={'raw':!![],'where':{'id':_0x44531e[_0x27e1('0x41')]['id']}},_0x32896c={};_0x32896c[_0x27e1('0x28')]=_[_0x27e1('0x29')](db[_0x27e1('0x26')][_0x27e1('0x27')]);_0x32896c['query']=_['keys'](_0x44531e['query']);_0x32896c[_0x27e1('0x2b')]=_['intersection'](_0x32896c[_0x27e1('0x28')],_0x32896c[_0x27e1('0x2a')]);_0x463e5b[_0x27e1('0x2d')]=_[_0x27e1('0x2c')](_0x32896c[_0x27e1('0x28')],qs[_0x27e1('0x2e')](_0x44531e[_0x27e1('0x2a')][_0x27e1('0x2e')]));_0x463e5b[_0x27e1('0x2d')]=_0x463e5b[_0x27e1('0x2d')][_0x27e1('0x2f')]?_0x463e5b[_0x27e1('0x2d')]:_0x32896c[_0x27e1('0x28')];if(_0x44531e['query'][_0x27e1('0x42')]){_0x463e5b[_0x27e1('0x3c')]=[{'all':!![]}];}_0x463e5b=_[_0x27e1('0x3a')]({},_0x463e5b,_0x44531e[_0x27e1('0x3b')]);return db[_0x27e1('0x26')]['find'](_0x463e5b)[_0x27e1('0x20')](handleEntityNotFound(_0x5e485b,null))['then'](respondWithResult(_0x5e485b,null))[_0x27e1('0x3f')](handleError(_0x5e485b,null));};exports[_0x27e1('0x43')]=function(_0x3a7357,_0x55c0bc){return db[_0x27e1('0x26')][_0x27e1('0x43')](_0x3a7357[_0x27e1('0x44')],{})['then'](respondWithResult(_0x55c0bc,0xc9))[_0x27e1('0x3f')](handleError(_0x55c0bc,null));};exports[_0x27e1('0x1f')]=function(_0x20beee,_0x1f23b2){if(_0x20beee[_0x27e1('0x44')]['id']){delete _0x20beee[_0x27e1('0x44')]['id'];}return db[_0x27e1('0x26')][_0x27e1('0x45')]({'where':{'id':_0x20beee[_0x27e1('0x41')]['id']}})[_0x27e1('0x20')](handleEntityNotFound(_0x1f23b2,null))['then'](saveUpdates(_0x20beee['body'],null))[_0x27e1('0x20')](respondWithResult(_0x1f23b2,null))[_0x27e1('0x3f')](handleError(_0x1f23b2,null));};exports['destroy']=function(_0xf2ca27,_0x131620){return db['Cdr']['find']({'where':{'id':_0xf2ca27[_0x27e1('0x41')]['id']}})[_0x27e1('0x20')](handleEntityNotFound(_0x131620,null))[_0x27e1('0x20')](removeEntity(_0x131620,null))['catch'](handleError(_0x131620,null));};exports['describe']=function(_0x1d4bce,_0x2a8a84){return db['Cdr'][_0x27e1('0x46')]()[_0x27e1('0x20')](respondWithResult(_0x2a8a84,null))[_0x27e1('0x3f')](handleError(_0x2a8a84,null));};