Built motion from commit b5a10faa.|2.6.13
[motion2.git] / server / api / voiceDialReport / voiceDialReport.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 _0x4f60=['update','then','destroy','sendStatus','stack','name','send','VoiceDialReport','rawAttributes','fieldName','type','key','model','map','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','merge','where','VIRTUAL','options','count','include','findAll','rows','catch','show','find','create','body','params','describe','eml-format','rimraf','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','offset','limit','undefined','set','apply','reject'];(function(_0x40a045,_0x516f0e){var _0x1a687c=function(_0x48c9fe){while(--_0x48c9fe){_0x40a045['push'](_0x40a045['shift']());}};_0x1a687c(++_0x516f0e);}(_0x4f60,0xc8));var _0x04f6=function(_0xd74157,_0x4f4b99){_0xd74157=_0xd74157-0x0;var _0x508020=_0x4f60[_0xd74157];return _0x508020;};'use strict';var emlformat=require(_0x04f6('0x0'));var rimraf=require(_0x04f6('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x04f6('0x2'));var moment=require(_0x04f6('0x3'));var BPromise=require(_0x04f6('0x4'));var Mustache=require(_0x04f6('0x5'));var util=require('util');var path=require(_0x04f6('0x6'));var sox=require(_0x04f6('0x7'));var csv=require(_0x04f6('0x8'));var ejs=require(_0x04f6('0x9'));var fs=require('fs');var fs_extra=require(_0x04f6('0xa'));var _=require(_0x04f6('0xb'));var squel=require(_0x04f6('0xc'));var crypto=require(_0x04f6('0xd'));var jsforce=require(_0x04f6('0xe'));var deskjs=require(_0x04f6('0xf'));var toCsv=require('to-csv');var querystring=require(_0x04f6('0x10'));var Papa=require(_0x04f6('0x11'));var Redis=require('ioredis');var authService=require(_0x04f6('0x12'));var qs=require(_0x04f6('0x13'));var as=require(_0x04f6('0x14'));var hardwareService=require(_0x04f6('0x15'));var logger=require(_0x04f6('0x16'))(_0x04f6('0x17'));var utils=require(_0x04f6('0x18'));var config=require(_0x04f6('0x19'));var licenseUtil=require(_0x04f6('0x1a'));var db=require(_0x04f6('0x1b'))['db'];function respondWithStatusCode(_0x2527ff,_0x41cdba){_0x41cdba=_0x41cdba||0xcc;return function(_0x4e6485){if(_0x4e6485){return _0x2527ff['sendStatus'](_0x41cdba);}return _0x2527ff[_0x04f6('0x1c')](_0x41cdba)[_0x04f6('0x1d')]();};}function respondWithResult(_0x55be62,_0x52b5c7){_0x52b5c7=_0x52b5c7||0xc8;return function(_0x56f81b){if(_0x56f81b){return _0x55be62['status'](_0x52b5c7)[_0x04f6('0x1e')](_0x56f81b);}};}function respondWithFilteredResult(_0x458055,_0x303440){return function(_0x2b6630){if(_0x2b6630){var _0x552446=typeof _0x303440[_0x04f6('0x1f')]==='undefined'&&typeof _0x303440[_0x04f6('0x20')]===_0x04f6('0x21');var _0x476440=_0x2b6630['count'];var _0x2e4797=_0x552446?0x0:_0x303440['offset'];var _0x1abd6e=_0x552446?_0x2b6630['count']:_0x303440[_0x04f6('0x1f')]+_0x303440[_0x04f6('0x20')];var _0x10c9ec;if(_0x1abd6e>=_0x476440){_0x1abd6e=_0x476440;_0x10c9ec=0xc8;}else{_0x10c9ec=0xce;}_0x458055[_0x04f6('0x1c')](_0x10c9ec);return _0x458055[_0x04f6('0x22')]('Content-Range',_0x2e4797+'-'+_0x1abd6e+'/'+_0x476440)[_0x04f6('0x1e')](_0x2b6630);}return null;};}function patchUpdates(_0x3a8fe0){return function(_0xed9986){try{jsonpatch[_0x04f6('0x23')](_0xed9986,_0x3a8fe0,!![]);}catch(_0x382df6){return BPromise[_0x04f6('0x24')](_0x382df6);}return _0xed9986['save']();};}function saveUpdates(_0x288c0c,_0x416909){return function(_0x5027f5){if(_0x5027f5){return _0x5027f5[_0x04f6('0x25')](_0x288c0c)[_0x04f6('0x26')](function(_0x4e226a){return _0x4e226a;});}return null;};}function removeEntity(_0x5e8972,_0xa5c974){return function(_0x5b39de){if(_0x5b39de){return _0x5b39de[_0x04f6('0x27')]()['then'](function(){_0x5e8972['status'](0xcc)[_0x04f6('0x1d')]();});}};}function handleEntityNotFound(_0x5e7093,_0x54e4ad){return function(_0x3f87b0){if(!_0x3f87b0){_0x5e7093[_0x04f6('0x28')](0x194);}return _0x3f87b0;};}function handleError(_0x3978f1,_0x3de7b7){_0x3de7b7=_0x3de7b7||0x1f4;return function(_0x559978){logger['error'](_0x559978[_0x04f6('0x29')]);if(_0x559978[_0x04f6('0x2a')]){delete _0x559978[_0x04f6('0x2a')];}_0x3978f1[_0x04f6('0x1c')](_0x3de7b7)[_0x04f6('0x2b')](_0x559978);};}exports['index']=function(_0x3a89a1,_0x4281a2){var _0x34236c={},_0x82b528={},_0x12ae64={'count':0x0,'rows':[]};var _0x281b5e=_['map'](db[_0x04f6('0x2c')][_0x04f6('0x2d')],function(_0x2f258c){return{'name':_0x2f258c[_0x04f6('0x2e')],'type':_0x2f258c[_0x04f6('0x2f')][_0x04f6('0x30')]};});_0x82b528[_0x04f6('0x31')]=_[_0x04f6('0x32')](_0x281b5e,_0x04f6('0x2a'));_0x82b528[_0x04f6('0x33')]=_[_0x04f6('0x34')](_0x3a89a1[_0x04f6('0x33')]);_0x82b528[_0x04f6('0x35')]=_['intersection'](_0x82b528[_0x04f6('0x31')],_0x82b528[_0x04f6('0x33')]);_0x34236c[_0x04f6('0x36')]=_[_0x04f6('0x37')](_0x82b528[_0x04f6('0x31')],qs[_0x04f6('0x38')](_0x3a89a1[_0x04f6('0x33')][_0x04f6('0x38')]));_0x34236c['attributes']=_0x34236c[_0x04f6('0x36')][_0x04f6('0x39')]?_0x34236c[_0x04f6('0x36')]:_0x82b528['model'];if(!_0x3a89a1['query'][_0x04f6('0x3a')](_0x04f6('0x3b'))){_0x34236c[_0x04f6('0x20')]=qs[_0x04f6('0x20')](_0x3a89a1[_0x04f6('0x33')]['limit']);_0x34236c[_0x04f6('0x1f')]=qs[_0x04f6('0x1f')](_0x3a89a1[_0x04f6('0x33')][_0x04f6('0x1f')]);}_0x34236c[_0x04f6('0x3c')]=qs['sort'](_0x3a89a1[_0x04f6('0x33')][_0x04f6('0x3d')]);_0x34236c['where']=qs[_0x04f6('0x35')](_[_0x04f6('0x3e')](_0x3a89a1[_0x04f6('0x33')],_0x82b528[_0x04f6('0x35')]),_0x281b5e);if(_0x3a89a1[_0x04f6('0x33')][_0x04f6('0x3f')]){_0x34236c['where']=_[_0x04f6('0x40')](_0x34236c[_0x04f6('0x41')],{'$or':_[_0x04f6('0x32')](_0x281b5e,function(_0xe96ab5){if(_0xe96ab5[_0x04f6('0x2f')]!==_0x04f6('0x42')){var _0x4f28bf={};_0x4f28bf[_0xe96ab5[_0x04f6('0x2a')]]={'$like':'%'+_0x3a89a1[_0x04f6('0x33')][_0x04f6('0x3f')]+'%'};return _0x4f28bf;}})});}_0x34236c=_[_0x04f6('0x40')]({},_0x34236c,_0x3a89a1[_0x04f6('0x43')]);var _0x36badd={'where':_0x34236c[_0x04f6('0x41')]};return db[_0x04f6('0x2c')][_0x04f6('0x44')](_0x36badd)[_0x04f6('0x26')](function(_0x8aed5a){_0x12ae64[_0x04f6('0x44')]=_0x8aed5a;if(_0x3a89a1['query']['includeAll']){_0x34236c[_0x04f6('0x45')]=[{'all':!![]}];}return db[_0x04f6('0x2c')][_0x04f6('0x46')](_0x34236c);})[_0x04f6('0x26')](function(_0x5e5d56){_0x12ae64[_0x04f6('0x47')]=_0x5e5d56;return _0x12ae64;})[_0x04f6('0x26')](respondWithFilteredResult(_0x4281a2,_0x34236c))[_0x04f6('0x48')](handleError(_0x4281a2,null));};exports[_0x04f6('0x49')]=function(_0x978bf3,_0x55056b){var _0x5cbf9f={'raw':!![],'where':{'id':_0x978bf3['params']['id']}},_0x2bc658={};_0x2bc658[_0x04f6('0x31')]=_[_0x04f6('0x34')](db[_0x04f6('0x2c')][_0x04f6('0x2d')]);_0x2bc658[_0x04f6('0x33')]=_['keys'](_0x978bf3['query']);_0x2bc658[_0x04f6('0x35')]=_[_0x04f6('0x37')](_0x2bc658[_0x04f6('0x31')],_0x2bc658[_0x04f6('0x33')]);_0x5cbf9f['attributes']=_[_0x04f6('0x37')](_0x2bc658[_0x04f6('0x31')],qs[_0x04f6('0x38')](_0x978bf3[_0x04f6('0x33')]['fields']));_0x5cbf9f['attributes']=_0x5cbf9f['attributes'][_0x04f6('0x39')]?_0x5cbf9f['attributes']:_0x2bc658['model'];if(_0x978bf3[_0x04f6('0x33')]['includeAll']){_0x5cbf9f['include']=[{'all':!![]}];}_0x5cbf9f=_['merge']({},_0x5cbf9f,_0x978bf3[_0x04f6('0x43')]);return db[_0x04f6('0x2c')][_0x04f6('0x4a')](_0x5cbf9f)[_0x04f6('0x26')](handleEntityNotFound(_0x55056b,null))[_0x04f6('0x26')](respondWithResult(_0x55056b,null))[_0x04f6('0x48')](handleError(_0x55056b,null));};exports[_0x04f6('0x4b')]=function(_0x52646b,_0x79e78f){return db[_0x04f6('0x2c')][_0x04f6('0x4b')](_0x52646b['body'],{})[_0x04f6('0x26')](respondWithResult(_0x79e78f,0xc9))['catch'](handleError(_0x79e78f,null));};exports[_0x04f6('0x25')]=function(_0x6cefb0,_0x42de93){if(_0x6cefb0['body']['id']){delete _0x6cefb0[_0x04f6('0x4c')]['id'];}return db[_0x04f6('0x2c')][_0x04f6('0x4a')]({'where':{'id':_0x6cefb0[_0x04f6('0x4d')]['id']}})['then'](handleEntityNotFound(_0x42de93,null))[_0x04f6('0x26')](saveUpdates(_0x6cefb0[_0x04f6('0x4c')],null))[_0x04f6('0x26')](respondWithResult(_0x42de93,null))[_0x04f6('0x48')](handleError(_0x42de93,null));};exports[_0x04f6('0x27')]=function(_0x48440a,_0x4826b7){return db[_0x04f6('0x2c')]['find']({'where':{'id':_0x48440a['params']['id']}})[_0x04f6('0x26')](handleEntityNotFound(_0x4826b7,null))[_0x04f6('0x26')](removeEntity(_0x4826b7,null))['catch'](handleError(_0x4826b7,null));};exports[_0x04f6('0x4e')]=function(_0x298f16,_0x59c710){return db[_0x04f6('0x2c')][_0x04f6('0x4e')]()[_0x04f6('0x26')](respondWithResult(_0x59c710,null))[_0x04f6('0x48')](handleError(_0x59c710,null));};