9a4b10718e536bd609a5d150fa3b63026478104d
[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 _0xf2ca=['../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','set','Content-Range','apply','reject','then','error','stack','name','send','index','map','Cdr','rawAttributes','type','key','model','query','intersection','attributes','fields','length','hasOwnProperty','order','sort','filters','pick','filter','merge','where','VIRTUAL','options','count','includeAll','include','findAll','rows','catch','params','keys','find','create','body','update','destroy','describe','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','crypto','jsforce','papaparse','../../components/auth/service','../../components/parsers/qs'];(function(_0x2128e5,_0x26ab8c){var _0x5e52b6=function(_0x111f4e){while(--_0x111f4e){_0x2128e5['push'](_0x2128e5['shift']());}};_0x5e52b6(++_0x26ab8c);}(_0xf2ca,0x16a));var _0xaf2c=function(_0x36acb3,_0x204e94){_0x36acb3=_0x36acb3-0x0;var _0x13976c=_0xf2ca[_0x36acb3];return _0x13976c;};'use strict';var emlformat=require(_0xaf2c('0x0'));var rimraf=require(_0xaf2c('0x1'));var zipdir=require(_0xaf2c('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xaf2c('0x3'));var moment=require(_0xaf2c('0x4'));var BPromise=require(_0xaf2c('0x5'));var Mustache=require(_0xaf2c('0x6'));var util=require(_0xaf2c('0x7'));var path=require(_0xaf2c('0x8'));var sox=require('sox');var csv=require(_0xaf2c('0x9'));var ejs=require(_0xaf2c('0xa'));var fs=require('fs');var fs_extra=require(_0xaf2c('0xb'));var _=require(_0xaf2c('0xc'));var squel=require('squel');var crypto=require(_0xaf2c('0xd'));var jsforce=require(_0xaf2c('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xaf2c('0x9'));var querystring=require('querystring');var Papa=require(_0xaf2c('0xf'));var Redis=require('ioredis');var authService=require(_0xaf2c('0x10'));var qs=require(_0xaf2c('0x11'));var as=require(_0xaf2c('0x12'));var hardwareService=require(_0xaf2c('0x13'));var logger=require('../../config/logger')('api');var utils=require(_0xaf2c('0x14'));var config=require(_0xaf2c('0x15'));var licenseUtil=require(_0xaf2c('0x16'));var db=require(_0xaf2c('0x17'))['db'];function respondWithStatusCode(_0x285dac,_0x59a59b){_0x59a59b=_0x59a59b||0xcc;return function(_0x590126){if(_0x590126){return _0x285dac[_0xaf2c('0x18')](_0x59a59b);}return _0x285dac[_0xaf2c('0x19')](_0x59a59b)[_0xaf2c('0x1a')]();};}function respondWithResult(_0x18a8a5,_0x293ca6){_0x293ca6=_0x293ca6||0xc8;return function(_0x152c73){if(_0x152c73){return _0x18a8a5[_0xaf2c('0x19')](_0x293ca6)[_0xaf2c('0x1b')](_0x152c73);}};}function respondWithFilteredResult(_0x2119c8,_0x1d0633){return function(_0x6ac8e){if(_0x6ac8e){var _0x2b4d13=typeof _0x1d0633[_0xaf2c('0x1c')]===_0xaf2c('0x1d')&&typeof _0x1d0633[_0xaf2c('0x1e')]==='undefined';var _0x3ca650=_0x6ac8e['count'];var _0x278a28=_0x2b4d13?0x0:_0x1d0633[_0xaf2c('0x1c')];var _0x1d544a=_0x2b4d13?_0x6ac8e['count']:_0x1d0633[_0xaf2c('0x1c')]+_0x1d0633[_0xaf2c('0x1e')];var _0x1fec4c;if(_0x1d544a>=_0x3ca650){_0x1d544a=_0x3ca650;_0x1fec4c=0xc8;}else{_0x1fec4c=0xce;}_0x2119c8[_0xaf2c('0x19')](_0x1fec4c);return _0x2119c8[_0xaf2c('0x1f')](_0xaf2c('0x20'),_0x278a28+'-'+_0x1d544a+'/'+_0x3ca650)['json'](_0x6ac8e);}return null;};}function patchUpdates(_0x35e712){return function(_0x164bcb){try{jsonpatch[_0xaf2c('0x21')](_0x164bcb,_0x35e712,!![]);}catch(_0x3bfd3f){return BPromise[_0xaf2c('0x22')](_0x3bfd3f);}return _0x164bcb['save']();};}function saveUpdates(_0x396646,_0xbf6f62){return function(_0x18153c){if(_0x18153c){return _0x18153c['update'](_0x396646)['then'](function(_0x29cbdf){return _0x29cbdf;});}return null;};}function removeEntity(_0x303546,_0x1cafad){return function(_0x99f78d){if(_0x99f78d){return _0x99f78d['destroy']()[_0xaf2c('0x23')](function(){_0x303546[_0xaf2c('0x19')](0xcc)[_0xaf2c('0x1a')]();});}};}function handleEntityNotFound(_0x3c1ae6,_0xe929b5){return function(_0xff396f){if(!_0xff396f){_0x3c1ae6[_0xaf2c('0x18')](0x194);}return _0xff396f;};}function handleError(_0x4a8dd8,_0x29f8b0){_0x29f8b0=_0x29f8b0||0x1f4;return function(_0x2051be){logger[_0xaf2c('0x24')](_0x2051be[_0xaf2c('0x25')]);if(_0x2051be['name']){delete _0x2051be[_0xaf2c('0x26')];}_0x4a8dd8['status'](_0x29f8b0)[_0xaf2c('0x27')](_0x2051be);};}exports[_0xaf2c('0x28')]=function(_0x15466b,_0x5d685a){var _0x2747bb={},_0x2ea490={},_0x3baee2={'count':0x0,'rows':[]};var _0x4a96d2=_[_0xaf2c('0x29')](db[_0xaf2c('0x2a')][_0xaf2c('0x2b')],function(_0x19364e){return{'name':_0x19364e['fieldName'],'type':_0x19364e[_0xaf2c('0x2c')][_0xaf2c('0x2d')]};});_0x2ea490[_0xaf2c('0x2e')]=_['map'](_0x4a96d2,'name');_0x2ea490[_0xaf2c('0x2f')]=_['keys'](_0x15466b[_0xaf2c('0x2f')]);_0x2ea490['filters']=_[_0xaf2c('0x30')](_0x2ea490[_0xaf2c('0x2e')],_0x2ea490['query']);_0x2747bb[_0xaf2c('0x31')]=_[_0xaf2c('0x30')](_0x2ea490['model'],qs[_0xaf2c('0x32')](_0x15466b[_0xaf2c('0x2f')][_0xaf2c('0x32')]));_0x2747bb[_0xaf2c('0x31')]=_0x2747bb[_0xaf2c('0x31')][_0xaf2c('0x33')]?_0x2747bb['attributes']:_0x2ea490[_0xaf2c('0x2e')];if(!_0x15466b['query'][_0xaf2c('0x34')]('nolimit')){_0x2747bb[_0xaf2c('0x1e')]=qs['limit'](_0x15466b[_0xaf2c('0x2f')]['limit']);_0x2747bb[_0xaf2c('0x1c')]=qs['offset'](_0x15466b[_0xaf2c('0x2f')][_0xaf2c('0x1c')]);}_0x2747bb[_0xaf2c('0x35')]=qs[_0xaf2c('0x36')](_0x15466b[_0xaf2c('0x2f')]['sort']);_0x2747bb['where']=qs[_0xaf2c('0x37')](_[_0xaf2c('0x38')](_0x15466b[_0xaf2c('0x2f')],_0x2ea490[_0xaf2c('0x37')]),_0x4a96d2);if(_0x15466b[_0xaf2c('0x2f')][_0xaf2c('0x39')]){_0x2747bb['where']=_[_0xaf2c('0x3a')](_0x2747bb[_0xaf2c('0x3b')],{'$or':_['map'](_0x4a96d2,function(_0x36081a){if(_0x36081a[_0xaf2c('0x2c')]!==_0xaf2c('0x3c')){var _0x71c597={};_0x71c597[_0x36081a[_0xaf2c('0x26')]]={'$like':'%'+_0x15466b[_0xaf2c('0x2f')][_0xaf2c('0x39')]+'%'};return _0x71c597;}})});}_0x2747bb=_[_0xaf2c('0x3a')]({},_0x2747bb,_0x15466b[_0xaf2c('0x3d')]);var _0x106eb9={'where':_0x2747bb[_0xaf2c('0x3b')]};return db[_0xaf2c('0x2a')][_0xaf2c('0x3e')](_0x106eb9)['then'](function(_0x54a953){_0x3baee2['count']=_0x54a953;if(_0x15466b[_0xaf2c('0x2f')][_0xaf2c('0x3f')]){_0x2747bb[_0xaf2c('0x40')]=[{'all':!![]}];}return db[_0xaf2c('0x2a')][_0xaf2c('0x41')](_0x2747bb);})[_0xaf2c('0x23')](function(_0x51c441){_0x3baee2[_0xaf2c('0x42')]=_0x51c441;return _0x3baee2;})[_0xaf2c('0x23')](respondWithFilteredResult(_0x5d685a,_0x2747bb))[_0xaf2c('0x43')](handleError(_0x5d685a,null));};exports['show']=function(_0x493266,_0x4ac61a){var _0x4f8440={'raw':!![],'where':{'id':_0x493266[_0xaf2c('0x44')]['id']}},_0x181787={};_0x181787[_0xaf2c('0x2e')]=_[_0xaf2c('0x45')](db['Cdr'][_0xaf2c('0x2b')]);_0x181787['query']=_[_0xaf2c('0x45')](_0x493266[_0xaf2c('0x2f')]);_0x181787['filters']=_[_0xaf2c('0x30')](_0x181787['model'],_0x181787[_0xaf2c('0x2f')]);_0x4f8440[_0xaf2c('0x31')]=_[_0xaf2c('0x30')](_0x181787[_0xaf2c('0x2e')],qs[_0xaf2c('0x32')](_0x493266[_0xaf2c('0x2f')][_0xaf2c('0x32')]));_0x4f8440[_0xaf2c('0x31')]=_0x4f8440[_0xaf2c('0x31')]['length']?_0x4f8440['attributes']:_0x181787[_0xaf2c('0x2e')];if(_0x493266['query']['includeAll']){_0x4f8440['include']=[{'all':!![]}];}_0x4f8440=_[_0xaf2c('0x3a')]({},_0x4f8440,_0x493266[_0xaf2c('0x3d')]);return db[_0xaf2c('0x2a')][_0xaf2c('0x46')](_0x4f8440)['then'](handleEntityNotFound(_0x4ac61a,null))[_0xaf2c('0x23')](respondWithResult(_0x4ac61a,null))['catch'](handleError(_0x4ac61a,null));};exports[_0xaf2c('0x47')]=function(_0x5ae138,_0x166c26){return db[_0xaf2c('0x2a')][_0xaf2c('0x47')](_0x5ae138[_0xaf2c('0x48')],{})[_0xaf2c('0x23')](respondWithResult(_0x166c26,0xc9))['catch'](handleError(_0x166c26,null));};exports[_0xaf2c('0x49')]=function(_0x26afee,_0x4b3ca4){if(_0x26afee['body']['id']){delete _0x26afee[_0xaf2c('0x48')]['id'];}return db['Cdr'][_0xaf2c('0x46')]({'where':{'id':_0x26afee[_0xaf2c('0x44')]['id']}})[_0xaf2c('0x23')](handleEntityNotFound(_0x4b3ca4,null))[_0xaf2c('0x23')](saveUpdates(_0x26afee[_0xaf2c('0x48')],null))[_0xaf2c('0x23')](respondWithResult(_0x4b3ca4,null))[_0xaf2c('0x43')](handleError(_0x4b3ca4,null));};exports[_0xaf2c('0x4a')]=function(_0x31ccfe,_0x1e72b0){return db[_0xaf2c('0x2a')]['find']({'where':{'id':_0x31ccfe[_0xaf2c('0x44')]['id']}})[_0xaf2c('0x23')](handleEntityNotFound(_0x1e72b0,null))['then'](removeEntity(_0x1e72b0,null))['catch'](handleError(_0x1e72b0,null));};exports['describe']=function(_0x7ddca0,_0x1f6907){return db['Cdr'][_0xaf2c('0x4b')]()[_0xaf2c('0x23')](respondWithResult(_0x1f6907,null))[_0xaf2c('0x43')](handleError(_0x1f6907,null));};