Built motion from commit (unavailable).|2.5.4
[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 _0xf5f8=['mustache','util','path','ejs','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','error','name','send','index','rawAttributes','fieldName','model','map','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','filter','where','merge','VIRTUAL','options','VoiceDialReport','include','findAll','rows','show','keys','includeAll','find','catch','create','body','params','destroy','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment'];(function(_0x2d4661,_0x2da65c){var _0x42ed1e=function(_0x263c50){while(--_0x263c50){_0x2d4661['push'](_0x2d4661['shift']());}};_0x42ed1e(++_0x2da65c);}(_0xf5f8,0x1bb));var _0x8f5f=function(_0x5ba4da,_0x3cb35c){_0x5ba4da=_0x5ba4da-0x0;var _0x269e6b=_0xf5f8[_0x5ba4da];return _0x269e6b;};'use strict';var pdf=require(_0x8f5f('0x0'));var emlformat=require(_0x8f5f('0x1'));var rimraf=require(_0x8f5f('0x2'));var zipdir=require(_0x8f5f('0x3'));var jsonpatch=require(_0x8f5f('0x4'));var rp=require(_0x8f5f('0x5'));var moment=require(_0x8f5f('0x6'));var BPromise=require('bluebird');var Mustache=require(_0x8f5f('0x7'));var util=require(_0x8f5f('0x8'));var path=require(_0x8f5f('0x9'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x8f5f('0xa'));var fs=require('fs');var _=require(_0x8f5f('0xb'));var squel=require(_0x8f5f('0xc'));var crypto=require(_0x8f5f('0xd'));var jsforce=require(_0x8f5f('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x8f5f('0xf'));var querystring=require(_0x8f5f('0x10'));var Papa=require(_0x8f5f('0x11'));var Redis=require(_0x8f5f('0x12'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x8f5f('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x8f5f('0x14'))(_0x8f5f('0x15'));var utils=require(_0x8f5f('0x16'));var config=require(_0x8f5f('0x17'));var db=require(_0x8f5f('0x18'))['db'];function respondWithStatusCode(_0x121865,_0x57b983){_0x57b983=_0x57b983||0xcc;return function(_0x2991a4){if(_0x2991a4){return _0x121865[_0x8f5f('0x19')](_0x57b983);}return _0x121865['status'](_0x57b983)['end']();};}function respondWithResult(_0x172b52,_0x4ec807){_0x4ec807=_0x4ec807||0xc8;return function(_0x50fdc0){if(_0x50fdc0){return _0x172b52[_0x8f5f('0x1a')](_0x4ec807)[_0x8f5f('0x1b')](_0x50fdc0);}};}function respondWithFilteredResult(_0x2861f3,_0x325d3c){return function(_0x378933){if(_0x378933){var _0x2beb54=_0x378933[_0x8f5f('0x1c')],_0x470e83=_0x325d3c['offset'],_0x3077f9=_0x325d3c[_0x8f5f('0x1d')]+_0x325d3c[_0x8f5f('0x1e')],_0x1afcb9;if(_0x3077f9>=_0x2beb54){_0x3077f9=_0x2beb54;_0x1afcb9=0xc8;}else{_0x1afcb9=0xce;}_0x2861f3[_0x8f5f('0x1a')](_0x1afcb9);return _0x2861f3[_0x8f5f('0x1f')](_0x8f5f('0x20'),_0x470e83+'-'+_0x3077f9+'/'+_0x2beb54)[_0x8f5f('0x1b')](_0x378933);}return null;};}function patchUpdates(_0x4250d5){return function(_0x47581d){try{jsonpatch[_0x8f5f('0x21')](_0x47581d,_0x4250d5,!![]);}catch(_0x3ebc13){return BPromise[_0x8f5f('0x22')](_0x3ebc13);}return _0x47581d[_0x8f5f('0x23')]();};}function saveUpdates(_0x3f8dd6,_0x3e8c2d){return function(_0x1c97a8){if(_0x1c97a8){return _0x1c97a8[_0x8f5f('0x24')](_0x3f8dd6)['then'](function(_0x12ed25){return _0x12ed25;});}return null;};}function removeEntity(_0x5e5007,_0xc0f360){return function(_0x49ea67){if(_0x49ea67){return _0x49ea67['destroy']()[_0x8f5f('0x25')](function(){_0x5e5007[_0x8f5f('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2007e8,_0x56c6b5){return function(_0x426191){if(!_0x426191){_0x2007e8[_0x8f5f('0x19')](0x194);}return _0x426191;};}function handleError(_0xcf935f,_0x160736){_0x160736=_0x160736||0x1f4;return function(_0x29b34a){logger[_0x8f5f('0x26')](_0x29b34a['stack']);if(_0x29b34a[_0x8f5f('0x27')]){delete _0x29b34a[_0x8f5f('0x27')];}_0xcf935f['status'](_0x160736)[_0x8f5f('0x28')](_0x29b34a);};}exports[_0x8f5f('0x29')]=function(_0x512b9b,_0x230f79){var _0x464d83={},_0x2f9e06={},_0x1dfe9d={'count':0x0,'rows':[]};var _0x5356d7=_['map'](db['VoiceDialReport'][_0x8f5f('0x2a')],function(_0x49e817){return{'name':_0x49e817[_0x8f5f('0x2b')],'type':_0x49e817['type']['key']};});_0x2f9e06[_0x8f5f('0x2c')]=_[_0x8f5f('0x2d')](_0x5356d7,_0x8f5f('0x27'));_0x2f9e06['query']=_['keys'](_0x512b9b[_0x8f5f('0x2e')]);_0x2f9e06[_0x8f5f('0x2f')]=_[_0x8f5f('0x30')](_0x2f9e06[_0x8f5f('0x2c')],_0x2f9e06['query']);_0x464d83['attributes']=_[_0x8f5f('0x30')](_0x2f9e06[_0x8f5f('0x2c')],qs[_0x8f5f('0x31')](_0x512b9b[_0x8f5f('0x2e')][_0x8f5f('0x31')]));_0x464d83[_0x8f5f('0x32')]=_0x464d83[_0x8f5f('0x32')][_0x8f5f('0x33')]?_0x464d83[_0x8f5f('0x32')]:_0x2f9e06['model'];if(!_0x512b9b[_0x8f5f('0x2e')][_0x8f5f('0x34')](_0x8f5f('0x35'))){_0x464d83['limit']=qs[_0x8f5f('0x1e')](_0x512b9b[_0x8f5f('0x2e')][_0x8f5f('0x1e')]);_0x464d83[_0x8f5f('0x1d')]=qs[_0x8f5f('0x1d')](_0x512b9b['query']['offset']);}_0x464d83[_0x8f5f('0x36')]=qs[_0x8f5f('0x37')](_0x512b9b[_0x8f5f('0x2e')][_0x8f5f('0x37')]);_0x464d83['where']=qs['filters'](_['pick'](_0x512b9b[_0x8f5f('0x2e')],_0x2f9e06[_0x8f5f('0x2f')]),_0x5356d7);if(_0x512b9b[_0x8f5f('0x2e')][_0x8f5f('0x38')]){_0x464d83[_0x8f5f('0x39')]=_[_0x8f5f('0x3a')](_0x464d83['where'],{'$or':_[_0x8f5f('0x2d')](_0x5356d7,function(_0x5630ac){if(_0x5630ac['type']!==_0x8f5f('0x3b')){var _0x2f1506={};_0x2f1506[_0x5630ac[_0x8f5f('0x27')]]={'$like':'%'+_0x512b9b[_0x8f5f('0x2e')][_0x8f5f('0x38')]+'%'};return _0x2f1506;}})});}_0x464d83=_[_0x8f5f('0x3a')]({},_0x464d83,_0x512b9b[_0x8f5f('0x3c')]);var _0x472f65={'where':_0x464d83[_0x8f5f('0x39')]};return db[_0x8f5f('0x3d')][_0x8f5f('0x1c')](_0x472f65)[_0x8f5f('0x25')](function(_0x50c4d2){_0x1dfe9d['count']=_0x50c4d2;if(_0x512b9b['query']['includeAll']){_0x464d83[_0x8f5f('0x3e')]=[{'all':!![]}];}return db[_0x8f5f('0x3d')][_0x8f5f('0x3f')](_0x464d83);})['then'](function(_0x2f71fb){_0x1dfe9d[_0x8f5f('0x40')]=_0x2f71fb;return _0x1dfe9d;})[_0x8f5f('0x25')](respondWithFilteredResult(_0x230f79,_0x464d83))['catch'](handleError(_0x230f79,null));};exports[_0x8f5f('0x41')]=function(_0x2c059a,_0xe51254){var _0x462912={'raw':!![],'where':{'id':_0x2c059a['params']['id']}},_0x390fe8={};_0x390fe8[_0x8f5f('0x2c')]=_[_0x8f5f('0x42')](db[_0x8f5f('0x3d')][_0x8f5f('0x2a')]);_0x390fe8[_0x8f5f('0x2e')]=_[_0x8f5f('0x42')](_0x2c059a['query']);_0x390fe8['filters']=_['intersection'](_0x390fe8[_0x8f5f('0x2c')],_0x390fe8[_0x8f5f('0x2e')]);_0x462912['attributes']=_[_0x8f5f('0x30')](_0x390fe8[_0x8f5f('0x2c')],qs[_0x8f5f('0x31')](_0x2c059a[_0x8f5f('0x2e')][_0x8f5f('0x31')]));_0x462912[_0x8f5f('0x32')]=_0x462912[_0x8f5f('0x32')]['length']?_0x462912[_0x8f5f('0x32')]:_0x390fe8['model'];if(_0x2c059a[_0x8f5f('0x2e')][_0x8f5f('0x43')]){_0x462912[_0x8f5f('0x3e')]=[{'all':!![]}];}_0x462912=_[_0x8f5f('0x3a')]({},_0x462912,_0x2c059a[_0x8f5f('0x3c')]);return db['VoiceDialReport'][_0x8f5f('0x44')](_0x462912)['then'](handleEntityNotFound(_0xe51254,null))[_0x8f5f('0x25')](respondWithResult(_0xe51254,null))[_0x8f5f('0x45')](handleError(_0xe51254,null));};exports[_0x8f5f('0x46')]=function(_0x44b071,_0x15af41){return db[_0x8f5f('0x3d')][_0x8f5f('0x46')](_0x44b071[_0x8f5f('0x47')],{})[_0x8f5f('0x25')](respondWithResult(_0x15af41,0xc9))[_0x8f5f('0x45')](handleError(_0x15af41,null));};exports[_0x8f5f('0x24')]=function(_0x523806,_0x4ee2d2){if(_0x523806[_0x8f5f('0x47')]['id']){delete _0x523806['body']['id'];}return db['VoiceDialReport'][_0x8f5f('0x44')]({'where':{'id':_0x523806[_0x8f5f('0x48')]['id']}})[_0x8f5f('0x25')](handleEntityNotFound(_0x4ee2d2,null))[_0x8f5f('0x25')](saveUpdates(_0x523806[_0x8f5f('0x47')],null))['then'](respondWithResult(_0x4ee2d2,null))[_0x8f5f('0x45')](handleError(_0x4ee2d2,null));};exports[_0x8f5f('0x49')]=function(_0x2e264b,_0x55d788){return db[_0x8f5f('0x3d')]['find']({'where':{'id':_0x2e264b['params']['id']}})['then'](handleEntityNotFound(_0x55d788,null))['then'](removeEntity(_0x55d788,null))['catch'](handleError(_0x55d788,null));};exports['describe']=function(_0x13d72b,_0x47f2bd){return db[_0x8f5f('0x3d')][_0x8f5f('0x4a')]()[_0x8f5f('0x25')](respondWithResult(_0x47f2bd,null))[_0x8f5f('0x45')](handleError(_0x47f2bd,null));};