c07d02ec0040e44f103881bb0a19e9ec570008c3
[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 _0xe85a=['reject','save','update','then','destroy','end','error','name','send','render','merge','contact','agent','interaction','account','index','map','Cdr','rawAttributes','fieldName','type','key','model','query','intersection','attributes','fields','length','nolimit','order','sort','filters','pick','filter','where','VIRTUAL','options','include','rows','catch','show','params','keys','includeAll','find','create','body','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','apply'];(function(_0x2f77d6,_0x535111){var _0x2f61ac=function(_0x44585a){while(--_0x44585a){_0x2f77d6['push'](_0x2f77d6['shift']());}};_0x2f61ac(++_0x535111);}(_0xe85a,0x125));var _0xae85=function(_0x1de133,_0xa17ce9){_0x1de133=_0x1de133-0x0;var _0x43658b=_0xe85a[_0x1de133];return _0x43658b;};'use strict';var emlformat=require(_0xae85('0x0'));var rimraf=require(_0xae85('0x1'));var zipdir=require(_0xae85('0x2'));var jsonpatch=require(_0xae85('0x3'));var rp=require('request-promise');var moment=require(_0xae85('0x4'));var BPromise=require(_0xae85('0x5'));var Mustache=require(_0xae85('0x6'));var util=require('util');var path=require(_0xae85('0x7'));var sox=require('sox');var csv=require(_0xae85('0x8'));var ejs=require(_0xae85('0x9'));var fs=require('fs');var fs_extra=require(_0xae85('0xa'));var _=require(_0xae85('0xb'));var squel=require(_0xae85('0xc'));var crypto=require(_0xae85('0xd'));var jsforce=require(_0xae85('0xe'));var deskjs=require(_0xae85('0xf'));var toCsv=require(_0xae85('0x8'));var querystring=require(_0xae85('0x10'));var Papa=require(_0xae85('0x11'));var Redis=require('ioredis');var authService=require(_0xae85('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0xae85('0x13'));var hardwareService=require(_0xae85('0x14'));var logger=require(_0xae85('0x15'))(_0xae85('0x16'));var utils=require(_0xae85('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0xae85('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x56037c,_0x5efe98){_0x5efe98=_0x5efe98||0xcc;return function(_0x4d88ca){if(_0x4d88ca){return _0x56037c[_0xae85('0x19')](_0x5efe98);}return _0x56037c['status'](_0x5efe98)['end']();};}function respondWithResult(_0x29fafb,_0x193432){_0x193432=_0x193432||0xc8;return function(_0x4f4f95){if(_0x4f4f95){return _0x29fafb[_0xae85('0x1a')](_0x193432)[_0xae85('0x1b')](_0x4f4f95);}};}function respondWithFilteredResult(_0x4a1861,_0x58176c){return function(_0x4232eb){if(_0x4232eb){var _0x14b74b=typeof _0x58176c[_0xae85('0x1c')]===_0xae85('0x1d')&&typeof _0x58176c[_0xae85('0x1e')]===_0xae85('0x1d');var _0x59e4a1=_0x4232eb['count'];var _0x35ea24=_0x14b74b?0x0:_0x58176c['offset'];var _0x51a551=_0x14b74b?_0x4232eb[_0xae85('0x1f')]:_0x58176c[_0xae85('0x1c')]+_0x58176c['limit'];var _0x9b1a9c;if(_0x51a551>=_0x59e4a1){_0x51a551=_0x59e4a1;_0x9b1a9c=0xc8;}else{_0x9b1a9c=0xce;}_0x4a1861[_0xae85('0x1a')](_0x9b1a9c);return _0x4a1861[_0xae85('0x20')](_0xae85('0x21'),_0x35ea24+'-'+_0x51a551+'/'+_0x59e4a1)[_0xae85('0x1b')](_0x4232eb);}return null;};}function patchUpdates(_0x134400){return function(_0x1e8448){try{jsonpatch[_0xae85('0x22')](_0x1e8448,_0x134400,!![]);}catch(_0x52abd0){return BPromise[_0xae85('0x23')](_0x52abd0);}return _0x1e8448[_0xae85('0x24')]();};}function saveUpdates(_0x5afdc7,_0x2c7bed){return function(_0x28e92d){if(_0x28e92d){return _0x28e92d[_0xae85('0x25')](_0x5afdc7)[_0xae85('0x26')](function(_0x42025b){return _0x42025b;});}return null;};}function removeEntity(_0xf0f95,_0x86e8de){return function(_0x491faf){if(_0x491faf){return _0x491faf[_0xae85('0x27')]()[_0xae85('0x26')](function(){_0xf0f95['status'](0xcc)[_0xae85('0x28')]();});}};}function handleEntityNotFound(_0x3fecef,_0x5e295e){return function(_0x294b27){if(!_0x294b27){_0x3fecef['sendStatus'](0x194);}return _0x294b27;};}function handleError(_0x10c78e,_0x47a8be){_0x47a8be=_0x47a8be||0x1f4;return function(_0x5f21dc){logger[_0xae85('0x29')](_0x5f21dc['stack']);if(_0x5f21dc[_0xae85('0x2a')]){delete _0x5f21dc[_0xae85('0x2a')];}_0x10c78e[_0xae85('0x1a')](_0x47a8be)[_0xae85('0x2b')](_0x5f21dc);};}function getMustacheRender(_0x380290,_0x152a54){return Mustache[_0xae85('0x2c')](_0x380290,_[_0xae85('0x2d')](_0x152a54['body'],{'contact':_0x152a54[_0xae85('0x2e')],'message':_0x152a54['message'],'agent':_0x152a54[_0xae85('0x2f')],'interaction':_0x152a54[_0xae85('0x30')],'account':_0x152a54[_0xae85('0x31')]}))||'';}exports[_0xae85('0x32')]=function(_0x2f2f86,_0x55c46c){var _0x1c0145={},_0x3bb7ad={},_0x42354b={'count':0x0,'rows':[]};var _0x13fdd9=_[_0xae85('0x33')](db[_0xae85('0x34')][_0xae85('0x35')],function(_0x47635a){return{'name':_0x47635a[_0xae85('0x36')],'type':_0x47635a[_0xae85('0x37')][_0xae85('0x38')]};});_0x3bb7ad[_0xae85('0x39')]=_[_0xae85('0x33')](_0x13fdd9,'name');_0x3bb7ad[_0xae85('0x3a')]=_['keys'](_0x2f2f86[_0xae85('0x3a')]);_0x3bb7ad['filters']=_[_0xae85('0x3b')](_0x3bb7ad[_0xae85('0x39')],_0x3bb7ad[_0xae85('0x3a')]);_0x1c0145[_0xae85('0x3c')]=_[_0xae85('0x3b')](_0x3bb7ad[_0xae85('0x39')],qs[_0xae85('0x3d')](_0x2f2f86['query']['fields']));_0x1c0145[_0xae85('0x3c')]=_0x1c0145['attributes'][_0xae85('0x3e')]?_0x1c0145['attributes']:_0x3bb7ad[_0xae85('0x39')];if(!_0x2f2f86['query']['hasOwnProperty'](_0xae85('0x3f'))){_0x1c0145[_0xae85('0x1e')]=qs[_0xae85('0x1e')](_0x2f2f86[_0xae85('0x3a')]['limit']);_0x1c0145[_0xae85('0x1c')]=qs[_0xae85('0x1c')](_0x2f2f86[_0xae85('0x3a')][_0xae85('0x1c')]);}_0x1c0145[_0xae85('0x40')]=qs[_0xae85('0x41')](_0x2f2f86[_0xae85('0x3a')][_0xae85('0x41')]);_0x1c0145['where']=qs[_0xae85('0x42')](_[_0xae85('0x43')](_0x2f2f86[_0xae85('0x3a')],_0x3bb7ad[_0xae85('0x42')]),_0x13fdd9);if(_0x2f2f86['query'][_0xae85('0x44')]){_0x1c0145[_0xae85('0x45')]=_[_0xae85('0x2d')](_0x1c0145[_0xae85('0x45')],{'$or':_[_0xae85('0x33')](_0x13fdd9,function(_0x459b7a){if(_0x459b7a['type']!==_0xae85('0x46')){var _0x3e6d3f={};_0x3e6d3f[_0x459b7a[_0xae85('0x2a')]]={'$like':'%'+_0x2f2f86[_0xae85('0x3a')][_0xae85('0x44')]+'%'};return _0x3e6d3f;}})});}_0x1c0145=_[_0xae85('0x2d')]({},_0x1c0145,_0x2f2f86[_0xae85('0x47')]);var _0x37e791={'where':_0x1c0145[_0xae85('0x45')]};return db['Cdr'][_0xae85('0x1f')](_0x37e791)[_0xae85('0x26')](function(_0x8a7f26){_0x42354b[_0xae85('0x1f')]=_0x8a7f26;if(_0x2f2f86[_0xae85('0x3a')]['includeAll']){_0x1c0145[_0xae85('0x48')]=[{'all':!![]}];}return db[_0xae85('0x34')]['findAll'](_0x1c0145);})['then'](function(_0x5a8c04){_0x42354b[_0xae85('0x49')]=_0x5a8c04;return _0x42354b;})[_0xae85('0x26')](respondWithFilteredResult(_0x55c46c,_0x1c0145))[_0xae85('0x4a')](handleError(_0x55c46c,null));};exports[_0xae85('0x4b')]=function(_0x22ceb3,_0x25628d){var _0x4003c2={'raw':!![],'where':{'id':_0x22ceb3[_0xae85('0x4c')]['id']}},_0x5c7634={};_0x5c7634[_0xae85('0x39')]=_[_0xae85('0x4d')](db[_0xae85('0x34')][_0xae85('0x35')]);_0x5c7634[_0xae85('0x3a')]=_[_0xae85('0x4d')](_0x22ceb3['query']);_0x5c7634[_0xae85('0x42')]=_[_0xae85('0x3b')](_0x5c7634[_0xae85('0x39')],_0x5c7634[_0xae85('0x3a')]);_0x4003c2['attributes']=_['intersection'](_0x5c7634[_0xae85('0x39')],qs[_0xae85('0x3d')](_0x22ceb3[_0xae85('0x3a')][_0xae85('0x3d')]));_0x4003c2['attributes']=_0x4003c2[_0xae85('0x3c')][_0xae85('0x3e')]?_0x4003c2[_0xae85('0x3c')]:_0x5c7634[_0xae85('0x39')];if(_0x22ceb3[_0xae85('0x3a')][_0xae85('0x4e')]){_0x4003c2['include']=[{'all':!![]}];}_0x4003c2=_[_0xae85('0x2d')]({},_0x4003c2,_0x22ceb3[_0xae85('0x47')]);return db[_0xae85('0x34')][_0xae85('0x4f')](_0x4003c2)[_0xae85('0x26')](handleEntityNotFound(_0x25628d,null))['then'](respondWithResult(_0x25628d,null))[_0xae85('0x4a')](handleError(_0x25628d,null));};exports[_0xae85('0x50')]=function(_0x44c746,_0x2cc799){return db[_0xae85('0x34')][_0xae85('0x50')](_0x44c746[_0xae85('0x51')],{})[_0xae85('0x26')](respondWithResult(_0x2cc799,0xc9))[_0xae85('0x4a')](handleError(_0x2cc799,null));};exports[_0xae85('0x25')]=function(_0xa9c9d4,_0x1a183b){if(_0xa9c9d4['body']['id']){delete _0xa9c9d4['body']['id'];}return db[_0xae85('0x34')][_0xae85('0x4f')]({'where':{'id':_0xa9c9d4[_0xae85('0x4c')]['id']}})[_0xae85('0x26')](handleEntityNotFound(_0x1a183b,null))[_0xae85('0x26')](saveUpdates(_0xa9c9d4[_0xae85('0x51')],null))['then'](respondWithResult(_0x1a183b,null))[_0xae85('0x4a')](handleError(_0x1a183b,null));};exports['destroy']=function(_0x4864f3,_0x53f55f){return db['Cdr'][_0xae85('0x4f')]({'where':{'id':_0x4864f3[_0xae85('0x4c')]['id']}})[_0xae85('0x26')](handleEntityNotFound(_0x53f55f,null))[_0xae85('0x26')](removeEntity(_0x53f55f,null))[_0xae85('0x4a')](handleError(_0x53f55f,null));};exports['describe']=function(_0x3b829f,_0x7f2d0){return db[_0xae85('0x34')]['describe']()[_0xae85('0x26')](respondWithResult(_0x7f2d0,null))['catch'](handleError(_0x7f2d0,null));};