Built motion from commit b5413ace.|2.6.9
[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 _0x2aff=['jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','status','json','offset','undefined','count','limit','set','Content-Range','apply','reject','update','then','destroy','end','sendStatus','stack','name','send','index','VoiceDialReport','rawAttributes','fieldName','type','key','map','query','keys','model','attributes','intersection','length','hasOwnProperty','sort','where','filters','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','fields','find','create','body','describe','eml-format','zip-dir','fast-json-patch','moment','util','sox','to-csv','ejs','fs-extra','lodash','crypto'];(function(_0xa6f6a6,_0x138b7a){var _0x71a78a=function(_0x3070d1){while(--_0x3070d1){_0xa6f6a6['push'](_0xa6f6a6['shift']());}};_0x71a78a(++_0x138b7a);}(_0x2aff,0x1f4));var _0xf2af=function(_0x1838a3,_0x57ed90){_0x1838a3=_0x1838a3-0x0;var _0x20c749=_0x2aff[_0x1838a3];return _0x20c749;};'use strict';var emlformat=require(_0xf2af('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xf2af('0x1'));var jsonpatch=require(_0xf2af('0x2'));var rp=require('request-promise');var moment=require(_0xf2af('0x3'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xf2af('0x4'));var path=require('path');var sox=require(_0xf2af('0x5'));var csv=require(_0xf2af('0x6'));var ejs=require(_0xf2af('0x7'));var fs=require('fs');var fs_extra=require(_0xf2af('0x8'));var _=require(_0xf2af('0x9'));var squel=require('squel');var crypto=require(_0xf2af('0xa'));var jsforce=require(_0xf2af('0xb'));var deskjs=require(_0xf2af('0xc'));var toCsv=require(_0xf2af('0x6'));var querystring=require('querystring');var Papa=require(_0xf2af('0xd'));var Redis=require(_0xf2af('0xe'));var authService=require(_0xf2af('0xf'));var qs=require(_0xf2af('0x10'));var as=require(_0xf2af('0x11'));var hardwareService=require(_0xf2af('0x12'));var logger=require('../../config/logger')(_0xf2af('0x13'));var utils=require(_0xf2af('0x14'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x4fdd0a,_0x5d9202){_0x5d9202=_0x5d9202||0xcc;return function(_0x12a14c){if(_0x12a14c){return _0x4fdd0a['sendStatus'](_0x5d9202);}return _0x4fdd0a[_0xf2af('0x15')](_0x5d9202)['end']();};}function respondWithResult(_0x227618,_0x23ac25){_0x23ac25=_0x23ac25||0xc8;return function(_0x337846){if(_0x337846){return _0x227618[_0xf2af('0x15')](_0x23ac25)[_0xf2af('0x16')](_0x337846);}};}function respondWithFilteredResult(_0x5560e5,_0x1afdfe){return function(_0x110171){if(_0x110171){var _0x5efe91=typeof _0x1afdfe[_0xf2af('0x17')]==='undefined'&&typeof _0x1afdfe['limit']===_0xf2af('0x18');var _0x1855af=_0x110171[_0xf2af('0x19')];var _0x52b8b6=_0x5efe91?0x0:_0x1afdfe[_0xf2af('0x17')];var _0x575b2a=_0x5efe91?_0x110171[_0xf2af('0x19')]:_0x1afdfe[_0xf2af('0x17')]+_0x1afdfe[_0xf2af('0x1a')];var _0x1b860f;if(_0x575b2a>=_0x1855af){_0x575b2a=_0x1855af;_0x1b860f=0xc8;}else{_0x1b860f=0xce;}_0x5560e5[_0xf2af('0x15')](_0x1b860f);return _0x5560e5[_0xf2af('0x1b')](_0xf2af('0x1c'),_0x52b8b6+'-'+_0x575b2a+'/'+_0x1855af)[_0xf2af('0x16')](_0x110171);}return null;};}function patchUpdates(_0x12ee44){return function(_0x1ad826){try{jsonpatch[_0xf2af('0x1d')](_0x1ad826,_0x12ee44,!![]);}catch(_0x329fdd){return BPromise[_0xf2af('0x1e')](_0x329fdd);}return _0x1ad826['save']();};}function saveUpdates(_0x4042e9,_0x5a344b){return function(_0x3fa7f3){if(_0x3fa7f3){return _0x3fa7f3[_0xf2af('0x1f')](_0x4042e9)[_0xf2af('0x20')](function(_0x28bf70){return _0x28bf70;});}return null;};}function removeEntity(_0x37a6f9,_0x4f9dc9){return function(_0x45d226){if(_0x45d226){return _0x45d226[_0xf2af('0x21')]()[_0xf2af('0x20')](function(){_0x37a6f9[_0xf2af('0x15')](0xcc)[_0xf2af('0x22')]();});}};}function handleEntityNotFound(_0x568596,_0x506068){return function(_0x3d394f){if(!_0x3d394f){_0x568596[_0xf2af('0x23')](0x194);}return _0x3d394f;};}function handleError(_0x54e00c,_0x382cab){_0x382cab=_0x382cab||0x1f4;return function(_0x53e967){logger['error'](_0x53e967[_0xf2af('0x24')]);if(_0x53e967[_0xf2af('0x25')]){delete _0x53e967['name'];}_0x54e00c['status'](_0x382cab)[_0xf2af('0x26')](_0x53e967);};}exports[_0xf2af('0x27')]=function(_0x2365ee,_0x53677c){var _0x3e6b8f={},_0x1c40cf={},_0x90630d={'count':0x0,'rows':[]};var _0x20761a=_['map'](db[_0xf2af('0x28')][_0xf2af('0x29')],function(_0x359054){return{'name':_0x359054[_0xf2af('0x2a')],'type':_0x359054[_0xf2af('0x2b')][_0xf2af('0x2c')]};});_0x1c40cf['model']=_[_0xf2af('0x2d')](_0x20761a,_0xf2af('0x25'));_0x1c40cf[_0xf2af('0x2e')]=_[_0xf2af('0x2f')](_0x2365ee[_0xf2af('0x2e')]);_0x1c40cf['filters']=_['intersection'](_0x1c40cf[_0xf2af('0x30')],_0x1c40cf[_0xf2af('0x2e')]);_0x3e6b8f[_0xf2af('0x31')]=_[_0xf2af('0x32')](_0x1c40cf[_0xf2af('0x30')],qs['fields'](_0x2365ee['query']['fields']));_0x3e6b8f[_0xf2af('0x31')]=_0x3e6b8f[_0xf2af('0x31')][_0xf2af('0x33')]?_0x3e6b8f['attributes']:_0x1c40cf[_0xf2af('0x30')];if(!_0x2365ee[_0xf2af('0x2e')][_0xf2af('0x34')]('nolimit')){_0x3e6b8f[_0xf2af('0x1a')]=qs[_0xf2af('0x1a')](_0x2365ee['query'][_0xf2af('0x1a')]);_0x3e6b8f[_0xf2af('0x17')]=qs['offset'](_0x2365ee[_0xf2af('0x2e')][_0xf2af('0x17')]);}_0x3e6b8f['order']=qs[_0xf2af('0x35')](_0x2365ee['query'][_0xf2af('0x35')]);_0x3e6b8f[_0xf2af('0x36')]=qs[_0xf2af('0x37')](_[_0xf2af('0x38')](_0x2365ee[_0xf2af('0x2e')],_0x1c40cf[_0xf2af('0x37')]),_0x20761a);if(_0x2365ee[_0xf2af('0x2e')][_0xf2af('0x39')]){_0x3e6b8f['where']=_[_0xf2af('0x3a')](_0x3e6b8f[_0xf2af('0x36')],{'$or':_[_0xf2af('0x2d')](_0x20761a,function(_0x2c69bc){if(_0x2c69bc[_0xf2af('0x2b')]!==_0xf2af('0x3b')){var _0x1bd548={};_0x1bd548[_0x2c69bc[_0xf2af('0x25')]]={'$like':'%'+_0x2365ee[_0xf2af('0x2e')][_0xf2af('0x39')]+'%'};return _0x1bd548;}})});}_0x3e6b8f=_[_0xf2af('0x3a')]({},_0x3e6b8f,_0x2365ee[_0xf2af('0x3c')]);var _0x2573e1={'where':_0x3e6b8f[_0xf2af('0x36')]};return db['VoiceDialReport'][_0xf2af('0x19')](_0x2573e1)[_0xf2af('0x20')](function(_0x50be4b){_0x90630d[_0xf2af('0x19')]=_0x50be4b;if(_0x2365ee['query'][_0xf2af('0x3d')]){_0x3e6b8f[_0xf2af('0x3e')]=[{'all':!![]}];}return db[_0xf2af('0x28')][_0xf2af('0x3f')](_0x3e6b8f);})[_0xf2af('0x20')](function(_0x26205e){_0x90630d[_0xf2af('0x40')]=_0x26205e;return _0x90630d;})[_0xf2af('0x20')](respondWithFilteredResult(_0x53677c,_0x3e6b8f))[_0xf2af('0x41')](handleError(_0x53677c,null));};exports[_0xf2af('0x42')]=function(_0x1c9a7b,_0x5839e9){var _0x54f122={'raw':!![],'where':{'id':_0x1c9a7b[_0xf2af('0x43')]['id']}},_0x332178={};_0x332178[_0xf2af('0x30')]=_[_0xf2af('0x2f')](db['VoiceDialReport'][_0xf2af('0x29')]);_0x332178['query']=_[_0xf2af('0x2f')](_0x1c9a7b[_0xf2af('0x2e')]);_0x332178[_0xf2af('0x37')]=_[_0xf2af('0x32')](_0x332178[_0xf2af('0x30')],_0x332178[_0xf2af('0x2e')]);_0x54f122[_0xf2af('0x31')]=_['intersection'](_0x332178[_0xf2af('0x30')],qs[_0xf2af('0x44')](_0x1c9a7b[_0xf2af('0x2e')]['fields']));_0x54f122['attributes']=_0x54f122[_0xf2af('0x31')][_0xf2af('0x33')]?_0x54f122['attributes']:_0x332178[_0xf2af('0x30')];if(_0x1c9a7b[_0xf2af('0x2e')]['includeAll']){_0x54f122[_0xf2af('0x3e')]=[{'all':!![]}];}_0x54f122=_['merge']({},_0x54f122,_0x1c9a7b['options']);return db['VoiceDialReport'][_0xf2af('0x45')](_0x54f122)['then'](handleEntityNotFound(_0x5839e9,null))['then'](respondWithResult(_0x5839e9,null))[_0xf2af('0x41')](handleError(_0x5839e9,null));};exports[_0xf2af('0x46')]=function(_0x1d0e6f,_0xbe1e95){return db[_0xf2af('0x28')][_0xf2af('0x46')](_0x1d0e6f[_0xf2af('0x47')],{})[_0xf2af('0x20')](respondWithResult(_0xbe1e95,0xc9))[_0xf2af('0x41')](handleError(_0xbe1e95,null));};exports[_0xf2af('0x1f')]=function(_0xd98d15,_0x18886a){if(_0xd98d15[_0xf2af('0x47')]['id']){delete _0xd98d15[_0xf2af('0x47')]['id'];}return db[_0xf2af('0x28')][_0xf2af('0x45')]({'where':{'id':_0xd98d15[_0xf2af('0x43')]['id']}})[_0xf2af('0x20')](handleEntityNotFound(_0x18886a,null))[_0xf2af('0x20')](saveUpdates(_0xd98d15[_0xf2af('0x47')],null))[_0xf2af('0x20')](respondWithResult(_0x18886a,null))[_0xf2af('0x41')](handleError(_0x18886a,null));};exports[_0xf2af('0x21')]=function(_0x18064d,_0x36309c){return db['VoiceDialReport']['find']({'where':{'id':_0x18064d['params']['id']}})['then'](handleEntityNotFound(_0x36309c,null))[_0xf2af('0x20')](removeEntity(_0x36309c,null))['catch'](handleError(_0x36309c,null));};exports[_0xf2af('0x48')]=function(_0x93e703,_0x2a779e){return db[_0xf2af('0x28')][_0xf2af('0x48')]()[_0xf2af('0x20')](respondWithResult(_0x2a779e,null))[_0xf2af('0x41')](handleError(_0x2a779e,null));};