Built motion from commit 10af8726.|2.6.34
[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 _0xf494=['create','body','params','describe','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','apply','save','update','then','error','stack','name','index','rawAttributes','fieldName','key','model','map','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','sort','where','pick','filter','merge','type','VIRTUAL','options','Cdr','includeAll','include','findAll','rows','catch','length','find'];(function(_0x2c7380,_0x442fea){var _0x440bea=function(_0x4c9429){while(--_0x4c9429){_0x2c7380['push'](_0x2c7380['shift']());}};_0x440bea(++_0x442fea);}(_0xf494,0x1c6));var _0x4f49=function(_0x2e8a2b,_0x4cfc63){_0x2e8a2b=_0x2e8a2b-0x0;var _0x4bb929=_0xf494[_0x2e8a2b];return _0x4bb929;};'use strict';var emlformat=require(_0x4f49('0x0'));var rimraf=require(_0x4f49('0x1'));var zipdir=require(_0x4f49('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x4f49('0x3'));var moment=require(_0x4f49('0x4'));var BPromise=require(_0x4f49('0x5'));var Mustache=require(_0x4f49('0x6'));var util=require(_0x4f49('0x7'));var path=require(_0x4f49('0x8'));var sox=require(_0x4f49('0x9'));var csv=require(_0x4f49('0xa'));var ejs=require(_0x4f49('0xb'));var fs=require('fs');var fs_extra=require(_0x4f49('0xc'));var _=require(_0x4f49('0xd'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x4f49('0xe'));var deskjs=require(_0x4f49('0xf'));var toCsv=require(_0x4f49('0xa'));var querystring=require(_0x4f49('0x10'));var Papa=require(_0x4f49('0x11'));var Redis=require(_0x4f49('0x12'));var authService=require(_0x4f49('0x13'));var qs=require(_0x4f49('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x4f49('0x15'));var logger=require(_0x4f49('0x16'))('api');var utils=require(_0x4f49('0x17'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x4f49('0x18'))['db'];function respondWithStatusCode(_0x12527d,_0x4bf89f){_0x4bf89f=_0x4bf89f||0xcc;return function(_0x1e1c37){if(_0x1e1c37){return _0x12527d[_0x4f49('0x19')](_0x4bf89f);}return _0x12527d[_0x4f49('0x1a')](_0x4bf89f)[_0x4f49('0x1b')]();};}function respondWithResult(_0x1a0f1e,_0x2f0131){_0x2f0131=_0x2f0131||0xc8;return function(_0xfdb477){if(_0xfdb477){return _0x1a0f1e['status'](_0x2f0131)[_0x4f49('0x1c')](_0xfdb477);}};}function respondWithFilteredResult(_0x1f2d0d,_0x415e83){return function(_0x5878f4){if(_0x5878f4){var _0x5bdfaf=typeof _0x415e83[_0x4f49('0x1d')]===_0x4f49('0x1e')&&typeof _0x415e83[_0x4f49('0x1f')]==='undefined';var _0x1dccfd=_0x5878f4[_0x4f49('0x20')];var _0x4e85df=_0x5bdfaf?0x0:_0x415e83['offset'];var _0x5bb23b=_0x5bdfaf?_0x5878f4['count']:_0x415e83['offset']+_0x415e83[_0x4f49('0x1f')];var _0x1834f4;if(_0x5bb23b>=_0x1dccfd){_0x5bb23b=_0x1dccfd;_0x1834f4=0xc8;}else{_0x1834f4=0xce;}_0x1f2d0d[_0x4f49('0x1a')](_0x1834f4);return _0x1f2d0d[_0x4f49('0x21')]('Content-Range',_0x4e85df+'-'+_0x5bb23b+'/'+_0x1dccfd)[_0x4f49('0x1c')](_0x5878f4);}return null;};}function patchUpdates(_0x2aed27){return function(_0x197a49){try{jsonpatch[_0x4f49('0x22')](_0x197a49,_0x2aed27,!![]);}catch(_0xea82f8){return BPromise['reject'](_0xea82f8);}return _0x197a49[_0x4f49('0x23')]();};}function saveUpdates(_0x357446,_0x3ae590){return function(_0x53b57d){if(_0x53b57d){return _0x53b57d[_0x4f49('0x24')](_0x357446)[_0x4f49('0x25')](function(_0x32ca7b){return _0x32ca7b;});}return null;};}function removeEntity(_0x43c458,_0x9d30aa){return function(_0x36187b){if(_0x36187b){return _0x36187b['destroy']()['then'](function(){_0x43c458[_0x4f49('0x1a')](0xcc)[_0x4f49('0x1b')]();});}};}function handleEntityNotFound(_0x4fedbb,_0x408552){return function(_0x2c1519){if(!_0x2c1519){_0x4fedbb[_0x4f49('0x19')](0x194);}return _0x2c1519;};}function handleError(_0x525950,_0xc54070){_0xc54070=_0xc54070||0x1f4;return function(_0x2eed1c){logger[_0x4f49('0x26')](_0x2eed1c[_0x4f49('0x27')]);if(_0x2eed1c[_0x4f49('0x28')]){delete _0x2eed1c[_0x4f49('0x28')];}_0x525950['status'](_0xc54070)['send'](_0x2eed1c);};}exports[_0x4f49('0x29')]=function(_0x2c00ee,_0x605c91){var _0x560050={},_0x3cbfbd={},_0x206203={'count':0x0,'rows':[]};var _0x43d8e3=_['map'](db['Cdr'][_0x4f49('0x2a')],function(_0x27d004){return{'name':_0x27d004[_0x4f49('0x2b')],'type':_0x27d004['type'][_0x4f49('0x2c')]};});_0x3cbfbd[_0x4f49('0x2d')]=_[_0x4f49('0x2e')](_0x43d8e3,_0x4f49('0x28'));_0x3cbfbd[_0x4f49('0x2f')]=_[_0x4f49('0x30')](_0x2c00ee[_0x4f49('0x2f')]);_0x3cbfbd[_0x4f49('0x31')]=_[_0x4f49('0x32')](_0x3cbfbd[_0x4f49('0x2d')],_0x3cbfbd[_0x4f49('0x2f')]);_0x560050[_0x4f49('0x33')]=_[_0x4f49('0x32')](_0x3cbfbd[_0x4f49('0x2d')],qs[_0x4f49('0x34')](_0x2c00ee[_0x4f49('0x2f')][_0x4f49('0x34')]));_0x560050[_0x4f49('0x33')]=_0x560050[_0x4f49('0x33')]['length']?_0x560050[_0x4f49('0x33')]:_0x3cbfbd[_0x4f49('0x2d')];if(!_0x2c00ee[_0x4f49('0x2f')][_0x4f49('0x35')](_0x4f49('0x36'))){_0x560050[_0x4f49('0x1f')]=qs[_0x4f49('0x1f')](_0x2c00ee[_0x4f49('0x2f')][_0x4f49('0x1f')]);_0x560050[_0x4f49('0x1d')]=qs[_0x4f49('0x1d')](_0x2c00ee[_0x4f49('0x2f')][_0x4f49('0x1d')]);}_0x560050['order']=qs[_0x4f49('0x37')](_0x2c00ee[_0x4f49('0x2f')][_0x4f49('0x37')]);_0x560050[_0x4f49('0x38')]=qs[_0x4f49('0x31')](_[_0x4f49('0x39')](_0x2c00ee[_0x4f49('0x2f')],_0x3cbfbd[_0x4f49('0x31')]),_0x43d8e3);if(_0x2c00ee[_0x4f49('0x2f')][_0x4f49('0x3a')]){_0x560050[_0x4f49('0x38')]=_[_0x4f49('0x3b')](_0x560050[_0x4f49('0x38')],{'$or':_[_0x4f49('0x2e')](_0x43d8e3,function(_0x4e3f72){if(_0x4e3f72[_0x4f49('0x3c')]!==_0x4f49('0x3d')){var _0x543605={};_0x543605[_0x4e3f72[_0x4f49('0x28')]]={'$like':'%'+_0x2c00ee[_0x4f49('0x2f')]['filter']+'%'};return _0x543605;}})});}_0x560050=_[_0x4f49('0x3b')]({},_0x560050,_0x2c00ee[_0x4f49('0x3e')]);var _0x2548ad={'where':_0x560050[_0x4f49('0x38')]};return db[_0x4f49('0x3f')][_0x4f49('0x20')](_0x2548ad)[_0x4f49('0x25')](function(_0x5d464e){_0x206203['count']=_0x5d464e;if(_0x2c00ee['query'][_0x4f49('0x40')]){_0x560050[_0x4f49('0x41')]=[{'all':!![]}];}return db[_0x4f49('0x3f')][_0x4f49('0x42')](_0x560050);})[_0x4f49('0x25')](function(_0x1ecf6c){_0x206203[_0x4f49('0x43')]=_0x1ecf6c;return _0x206203;})[_0x4f49('0x25')](respondWithFilteredResult(_0x605c91,_0x560050))[_0x4f49('0x44')](handleError(_0x605c91,null));};exports['show']=function(_0x5238a3,_0x412395){var _0x432b5d={'raw':!![],'where':{'id':_0x5238a3['params']['id']}},_0x159642={};_0x159642[_0x4f49('0x2d')]=_['keys'](db['Cdr'][_0x4f49('0x2a')]);_0x159642[_0x4f49('0x2f')]=_[_0x4f49('0x30')](_0x5238a3['query']);_0x159642[_0x4f49('0x31')]=_[_0x4f49('0x32')](_0x159642['model'],_0x159642[_0x4f49('0x2f')]);_0x432b5d['attributes']=_[_0x4f49('0x32')](_0x159642[_0x4f49('0x2d')],qs[_0x4f49('0x34')](_0x5238a3['query'][_0x4f49('0x34')]));_0x432b5d[_0x4f49('0x33')]=_0x432b5d[_0x4f49('0x33')][_0x4f49('0x45')]?_0x432b5d[_0x4f49('0x33')]:_0x159642[_0x4f49('0x2d')];if(_0x5238a3[_0x4f49('0x2f')][_0x4f49('0x40')]){_0x432b5d[_0x4f49('0x41')]=[{'all':!![]}];}_0x432b5d=_[_0x4f49('0x3b')]({},_0x432b5d,_0x5238a3['options']);return db[_0x4f49('0x3f')][_0x4f49('0x46')](_0x432b5d)['then'](handleEntityNotFound(_0x412395,null))[_0x4f49('0x25')](respondWithResult(_0x412395,null))['catch'](handleError(_0x412395,null));};exports[_0x4f49('0x47')]=function(_0x41c580,_0x2d3dcd){return db[_0x4f49('0x3f')]['create'](_0x41c580[_0x4f49('0x48')],{})[_0x4f49('0x25')](respondWithResult(_0x2d3dcd,0xc9))[_0x4f49('0x44')](handleError(_0x2d3dcd,null));};exports[_0x4f49('0x24')]=function(_0x3ec266,_0x72ea05){if(_0x3ec266[_0x4f49('0x48')]['id']){delete _0x3ec266[_0x4f49('0x48')]['id'];}return db[_0x4f49('0x3f')][_0x4f49('0x46')]({'where':{'id':_0x3ec266[_0x4f49('0x49')]['id']}})[_0x4f49('0x25')](handleEntityNotFound(_0x72ea05,null))[_0x4f49('0x25')](saveUpdates(_0x3ec266[_0x4f49('0x48')],null))[_0x4f49('0x25')](respondWithResult(_0x72ea05,null))[_0x4f49('0x44')](handleError(_0x72ea05,null));};exports['destroy']=function(_0x4eadc2,_0xce5121){return db[_0x4f49('0x3f')][_0x4f49('0x46')]({'where':{'id':_0x4eadc2[_0x4f49('0x49')]['id']}})[_0x4f49('0x25')](handleEntityNotFound(_0xce5121,null))[_0x4f49('0x25')](removeEntity(_0xce5121,null))[_0x4f49('0x44')](handleError(_0xce5121,null));};exports['describe']=function(_0x6637f4,_0x4ff0a2){return db[_0x4f49('0x3f')][_0x4f49('0x4a')]()[_0x4f49('0x25')](respondWithResult(_0x4ff0a2,null))[_0x4f49('0x44')](handleError(_0x4ff0a2,null));};