Built motion from commit f25620e4.|2.6.30
[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 _0x106f=['path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','json','offset','limit','undefined','count','status','set','Content-Range','apply','save','update','then','destroy','end','name','send','index','map','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','fields','length','nolimit','sort','where','filters','pick','filter','merge','options','includeAll','include','Cdr','findAll','params','create','body','catch','find','describe','eml-format','rimraf','fast-json-patch','request-promise','bluebird','util'];(function(_0x468481,_0x3d8b88){var _0x363252=function(_0x32e2a9){while(--_0x32e2a9){_0x468481['push'](_0x468481['shift']());}};_0x363252(++_0x3d8b88);}(_0x106f,0x162));var _0xf106=function(_0x2276fa,_0x5dc6c8){_0x2276fa=_0x2276fa-0x0;var _0x76562a=_0x106f[_0x2276fa];return _0x76562a;};'use strict';var emlformat=require(_0xf106('0x0'));var rimraf=require(_0xf106('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf106('0x2'));var rp=require(_0xf106('0x3'));var moment=require('moment');var BPromise=require(_0xf106('0x4'));var Mustache=require('mustache');var util=require(_0xf106('0x5'));var path=require(_0xf106('0x6'));var sox=require(_0xf106('0x7'));var csv=require(_0xf106('0x8'));var ejs=require(_0xf106('0x9'));var fs=require('fs');var fs_extra=require(_0xf106('0xa'));var _=require(_0xf106('0xb'));var squel=require('squel');var crypto=require(_0xf106('0xc'));var jsforce=require(_0xf106('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xf106('0xe'));var qs=require(_0xf106('0xf'));var as=require(_0xf106('0x10'));var hardwareService=require(_0xf106('0x11'));var logger=require(_0xf106('0x12'))(_0xf106('0x13'));var utils=require(_0xf106('0x14'));var config=require(_0xf106('0x15'));var licenseUtil=require(_0xf106('0x16'));var db=require(_0xf106('0x17'))['db'];function respondWithStatusCode(_0x31eebf,_0x5e9da8){_0x5e9da8=_0x5e9da8||0xcc;return function(_0x2bd234){if(_0x2bd234){return _0x31eebf[_0xf106('0x18')](_0x5e9da8);}return _0x31eebf['status'](_0x5e9da8)['end']();};}function respondWithResult(_0x322351,_0x2cdbf6){_0x2cdbf6=_0x2cdbf6||0xc8;return function(_0x292a0d){if(_0x292a0d){return _0x322351['status'](_0x2cdbf6)[_0xf106('0x19')](_0x292a0d);}};}function respondWithFilteredResult(_0x26186f,_0xf05683){return function(_0x48bfdd){if(_0x48bfdd){var _0x1e17e6=typeof _0xf05683[_0xf106('0x1a')]==='undefined'&&typeof _0xf05683[_0xf106('0x1b')]===_0xf106('0x1c');var _0x62352=_0x48bfdd['count'];var _0x5d02c0=_0x1e17e6?0x0:_0xf05683[_0xf106('0x1a')];var _0x726d7c=_0x1e17e6?_0x48bfdd[_0xf106('0x1d')]:_0xf05683['offset']+_0xf05683[_0xf106('0x1b')];var _0x1a6816;if(_0x726d7c>=_0x62352){_0x726d7c=_0x62352;_0x1a6816=0xc8;}else{_0x1a6816=0xce;}_0x26186f[_0xf106('0x1e')](_0x1a6816);return _0x26186f[_0xf106('0x1f')](_0xf106('0x20'),_0x5d02c0+'-'+_0x726d7c+'/'+_0x62352)[_0xf106('0x19')](_0x48bfdd);}return null;};}function patchUpdates(_0x29ae70){return function(_0x232a54){try{jsonpatch[_0xf106('0x21')](_0x232a54,_0x29ae70,!![]);}catch(_0x4a9564){return BPromise['reject'](_0x4a9564);}return _0x232a54[_0xf106('0x22')]();};}function saveUpdates(_0x59abbc,_0x32ab30){return function(_0x3c729e){if(_0x3c729e){return _0x3c729e[_0xf106('0x23')](_0x59abbc)[_0xf106('0x24')](function(_0x450451){return _0x450451;});}return null;};}function removeEntity(_0x4f673f,_0x58febd){return function(_0x178890){if(_0x178890){return _0x178890[_0xf106('0x25')]()[_0xf106('0x24')](function(){_0x4f673f[_0xf106('0x1e')](0xcc)[_0xf106('0x26')]();});}};}function handleEntityNotFound(_0xf7de89,_0x9f99bb){return function(_0x118726){if(!_0x118726){_0xf7de89[_0xf106('0x18')](0x194);}return _0x118726;};}function handleError(_0x14b15e,_0x468fce){_0x468fce=_0x468fce||0x1f4;return function(_0x225c15){logger['error'](_0x225c15['stack']);if(_0x225c15['name']){delete _0x225c15[_0xf106('0x27')];}_0x14b15e[_0xf106('0x1e')](_0x468fce)[_0xf106('0x28')](_0x225c15);};}exports[_0xf106('0x29')]=function(_0x4265b3,_0x13b5d7){var _0x4f90d1={},_0x1394e8={},_0x269bff={'count':0x0,'rows':[]};var _0x1f8323=_[_0xf106('0x2a')](db['Cdr'][_0xf106('0x2b')],function(_0x444bde){return{'name':_0x444bde[_0xf106('0x2c')],'type':_0x444bde[_0xf106('0x2d')][_0xf106('0x2e')]};});_0x1394e8[_0xf106('0x2f')]=_['map'](_0x1f8323,_0xf106('0x27'));_0x1394e8[_0xf106('0x30')]=_[_0xf106('0x31')](_0x4265b3[_0xf106('0x30')]);_0x1394e8['filters']=_[_0xf106('0x32')](_0x1394e8[_0xf106('0x2f')],_0x1394e8['query']);_0x4f90d1[_0xf106('0x33')]=_[_0xf106('0x32')](_0x1394e8[_0xf106('0x2f')],qs[_0xf106('0x34')](_0x4265b3[_0xf106('0x30')][_0xf106('0x34')]));_0x4f90d1[_0xf106('0x33')]=_0x4f90d1[_0xf106('0x33')][_0xf106('0x35')]?_0x4f90d1[_0xf106('0x33')]:_0x1394e8[_0xf106('0x2f')];if(!_0x4265b3['query']['hasOwnProperty'](_0xf106('0x36'))){_0x4f90d1[_0xf106('0x1b')]=qs[_0xf106('0x1b')](_0x4265b3['query'][_0xf106('0x1b')]);_0x4f90d1[_0xf106('0x1a')]=qs[_0xf106('0x1a')](_0x4265b3[_0xf106('0x30')][_0xf106('0x1a')]);}_0x4f90d1['order']=qs[_0xf106('0x37')](_0x4265b3['query'][_0xf106('0x37')]);_0x4f90d1[_0xf106('0x38')]=qs[_0xf106('0x39')](_[_0xf106('0x3a')](_0x4265b3['query'],_0x1394e8[_0xf106('0x39')]),_0x1f8323);if(_0x4265b3[_0xf106('0x30')][_0xf106('0x3b')]){_0x4f90d1['where']=_['merge'](_0x4f90d1['where'],{'$or':_['map'](_0x1f8323,function(_0x58dba7){if(_0x58dba7[_0xf106('0x2d')]!=='VIRTUAL'){var _0x4beb79={};_0x4beb79[_0x58dba7[_0xf106('0x27')]]={'$like':'%'+_0x4265b3['query']['filter']+'%'};return _0x4beb79;}})});}_0x4f90d1=_[_0xf106('0x3c')]({},_0x4f90d1,_0x4265b3[_0xf106('0x3d')]);var _0x2d4c90={'where':_0x4f90d1[_0xf106('0x38')]};return db['Cdr'][_0xf106('0x1d')](_0x2d4c90)[_0xf106('0x24')](function(_0x583a72){_0x269bff[_0xf106('0x1d')]=_0x583a72;if(_0x4265b3[_0xf106('0x30')][_0xf106('0x3e')]){_0x4f90d1[_0xf106('0x3f')]=[{'all':!![]}];}return db[_0xf106('0x40')][_0xf106('0x41')](_0x4f90d1);})[_0xf106('0x24')](function(_0x57d61e){_0x269bff['rows']=_0x57d61e;return _0x269bff;})[_0xf106('0x24')](respondWithFilteredResult(_0x13b5d7,_0x4f90d1))['catch'](handleError(_0x13b5d7,null));};exports['show']=function(_0x37bb28,_0x390eee){var _0x5e6cb8={'raw':!![],'where':{'id':_0x37bb28[_0xf106('0x42')]['id']}},_0x47f4d3={};_0x47f4d3['model']=_[_0xf106('0x31')](db[_0xf106('0x40')][_0xf106('0x2b')]);_0x47f4d3[_0xf106('0x30')]=_[_0xf106('0x31')](_0x37bb28[_0xf106('0x30')]);_0x47f4d3[_0xf106('0x39')]=_[_0xf106('0x32')](_0x47f4d3[_0xf106('0x2f')],_0x47f4d3[_0xf106('0x30')]);_0x5e6cb8[_0xf106('0x33')]=_[_0xf106('0x32')](_0x47f4d3[_0xf106('0x2f')],qs[_0xf106('0x34')](_0x37bb28[_0xf106('0x30')][_0xf106('0x34')]));_0x5e6cb8[_0xf106('0x33')]=_0x5e6cb8[_0xf106('0x33')]['length']?_0x5e6cb8[_0xf106('0x33')]:_0x47f4d3[_0xf106('0x2f')];if(_0x37bb28[_0xf106('0x30')][_0xf106('0x3e')]){_0x5e6cb8[_0xf106('0x3f')]=[{'all':!![]}];}_0x5e6cb8=_['merge']({},_0x5e6cb8,_0x37bb28['options']);return db['Cdr']['find'](_0x5e6cb8)[_0xf106('0x24')](handleEntityNotFound(_0x390eee,null))['then'](respondWithResult(_0x390eee,null))['catch'](handleError(_0x390eee,null));};exports[_0xf106('0x43')]=function(_0x1a686d,_0xd50443){return db[_0xf106('0x40')]['create'](_0x1a686d[_0xf106('0x44')],{})[_0xf106('0x24')](respondWithResult(_0xd50443,0xc9))[_0xf106('0x45')](handleError(_0xd50443,null));};exports[_0xf106('0x23')]=function(_0x1bf065,_0x519192){if(_0x1bf065['body']['id']){delete _0x1bf065[_0xf106('0x44')]['id'];}return db[_0xf106('0x40')][_0xf106('0x46')]({'where':{'id':_0x1bf065['params']['id']}})[_0xf106('0x24')](handleEntityNotFound(_0x519192,null))[_0xf106('0x24')](saveUpdates(_0x1bf065[_0xf106('0x44')],null))[_0xf106('0x24')](respondWithResult(_0x519192,null))['catch'](handleError(_0x519192,null));};exports[_0xf106('0x25')]=function(_0x5b80a8,_0x50798d){return db[_0xf106('0x40')][_0xf106('0x46')]({'where':{'id':_0x5b80a8['params']['id']}})[_0xf106('0x24')](handleEntityNotFound(_0x50798d,null))[_0xf106('0x24')](removeEntity(_0x50798d,null))[_0xf106('0x45')](handleError(_0x50798d,null));};exports[_0xf106('0x47')]=function(_0x14375d,_0x391e3d){return db['Cdr']['describe']()[_0xf106('0x24')](respondWithResult(_0x391e3d,null))['catch'](handleError(_0x391e3d,null));};