Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / api / voiceChanSpy / voiceChanSpy.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 _0x8b2b=['length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','options','includeAll','include','findAll','rows','catch','params','find','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','ChanSpies','UserProfileSection','autoAssociation','UserProfileResource','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','destroy','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','ejs','fs-extra','lodash','squel','desk.js','to-csv','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','end','status','json','offset','undefined','limit','count','set','Content-Range','reject','save','update','then','get','sendStatus','error','stack','name','send','map','VoiceChanSpy','rawAttributes','fieldName','type','model','query','keys','filters','intersection','fields','attributes'];(function(_0x491775,_0x405e35){var _0x595a96=function(_0x1803bb){while(--_0x1803bb){_0x491775['push'](_0x491775['shift']());}};_0x595a96(++_0x405e35);}(_0x8b2b,0x1c0));var _0xb8b2=function(_0x45b93d,_0x5e401f){_0x45b93d=_0x45b93d-0x0;var _0x2fa15b=_0x8b2b[_0x45b93d];return _0x2fa15b;};'use strict';var emlformat=require(_0xb8b2('0x0'));var rimraf=require(_0xb8b2('0x1'));var zipdir=require(_0xb8b2('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xb8b2('0x3'));var moment=require(_0xb8b2('0x4'));var BPromise=require(_0xb8b2('0x5'));var Mustache=require(_0xb8b2('0x6'));var util=require(_0xb8b2('0x7'));var path=require(_0xb8b2('0x8'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xb8b2('0x9'));var fs=require('fs');var fs_extra=require(_0xb8b2('0xa'));var _=require(_0xb8b2('0xb'));var squel=require(_0xb8b2('0xc'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xb8b2('0xd'));var toCsv=require(_0xb8b2('0xe'));var querystring=require(_0xb8b2('0xf'));var Papa=require(_0xb8b2('0x10'));var Redis=require(_0xb8b2('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xb8b2('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xb8b2('0x13'))(_0xb8b2('0x14'));var utils=require(_0xb8b2('0x15'));var config=require(_0xb8b2('0x16'));var licenseUtil=require(_0xb8b2('0x17'));var db=require(_0xb8b2('0x18'))['db'];function respondWithStatusCode(_0x584d41,_0x3440bf){_0x3440bf=_0x3440bf||0xcc;return function(_0x5bd724){if(_0x5bd724){return _0x584d41['sendStatus'](_0x3440bf);}return _0x584d41['status'](_0x3440bf)[_0xb8b2('0x19')]();};}function respondWithResult(_0xdc1d1d,_0x48b9df){_0x48b9df=_0x48b9df||0xc8;return function(_0x175885){if(_0x175885){return _0xdc1d1d[_0xb8b2('0x1a')](_0x48b9df)[_0xb8b2('0x1b')](_0x175885);}};}function respondWithFilteredResult(_0x142fb0,_0x46a592){return function(_0x5b614d){if(_0x5b614d){var _0x4b5a28=typeof _0x46a592[_0xb8b2('0x1c')]===_0xb8b2('0x1d')&&typeof _0x46a592[_0xb8b2('0x1e')]===_0xb8b2('0x1d');var _0xf04672=_0x5b614d['count'];var _0x47b94f=_0x4b5a28?0x0:_0x46a592[_0xb8b2('0x1c')];var _0x153b69=_0x4b5a28?_0x5b614d[_0xb8b2('0x1f')]:_0x46a592[_0xb8b2('0x1c')]+_0x46a592['limit'];var _0x23af66;if(_0x153b69>=_0xf04672){_0x153b69=_0xf04672;_0x23af66=0xc8;}else{_0x23af66=0xce;}_0x142fb0[_0xb8b2('0x1a')](_0x23af66);return _0x142fb0[_0xb8b2('0x20')](_0xb8b2('0x21'),_0x47b94f+'-'+_0x153b69+'/'+_0xf04672)[_0xb8b2('0x1b')](_0x5b614d);}return null;};}function patchUpdates(_0x1cbc65){return function(_0x34ca46){try{jsonpatch['apply'](_0x34ca46,_0x1cbc65,!![]);}catch(_0x382bbf){return BPromise[_0xb8b2('0x22')](_0x382bbf);}return _0x34ca46[_0xb8b2('0x23')]();};}function saveUpdates(_0x162d41,_0x316d3c){return function(_0x5a0a43){if(_0x5a0a43){return _0x5a0a43[_0xb8b2('0x24')](_0x162d41)['then'](function(_0xe3b28){return _0xe3b28;});}return null;};}function removeEntity(_0x8239a7,_0x2b40f8){return function(_0x20082f){if(_0x20082f){return _0x20082f['destroy']()[_0xb8b2('0x25')](function(){var _0x2502ae=_0x20082f[_0xb8b2('0x26')]({'plain':!![]});var _0x5a2afe='ChanSpies';return db['UserProfileResource']['destroy']({'where':{'type':_0x5a2afe,'resourceId':_0x2502ae['id']}})[_0xb8b2('0x25')](function(){return _0x20082f;});})[_0xb8b2('0x25')](function(){_0x8239a7[_0xb8b2('0x1a')](0xcc)[_0xb8b2('0x19')]();});}};}function handleEntityNotFound(_0x14ba5c,_0x2026db){return function(_0x3f3424){if(!_0x3f3424){_0x14ba5c[_0xb8b2('0x27')](0x194);}return _0x3f3424;};}function handleError(_0xf5f561,_0x2bf940){_0x2bf940=_0x2bf940||0x1f4;return function(_0x2a236d){logger[_0xb8b2('0x28')](_0x2a236d[_0xb8b2('0x29')]);if(_0x2a236d[_0xb8b2('0x2a')]){delete _0x2a236d[_0xb8b2('0x2a')];}_0xf5f561[_0xb8b2('0x1a')](_0x2bf940)[_0xb8b2('0x2b')](_0x2a236d);};}exports['index']=function(_0x37ea31,_0x1899d9){var _0x42b97f={},_0x394359={},_0x21b008={'count':0x0,'rows':[]};var _0x493c16=_[_0xb8b2('0x2c')](db[_0xb8b2('0x2d')][_0xb8b2('0x2e')],function(_0x52d2e9){return{'name':_0x52d2e9[_0xb8b2('0x2f')],'type':_0x52d2e9[_0xb8b2('0x30')]['key']};});_0x394359[_0xb8b2('0x31')]=_[_0xb8b2('0x2c')](_0x493c16,_0xb8b2('0x2a'));_0x394359[_0xb8b2('0x32')]=_[_0xb8b2('0x33')](_0x37ea31[_0xb8b2('0x32')]);_0x394359[_0xb8b2('0x34')]=_[_0xb8b2('0x35')](_0x394359[_0xb8b2('0x31')],_0x394359[_0xb8b2('0x32')]);_0x42b97f['attributes']=_[_0xb8b2('0x35')](_0x394359[_0xb8b2('0x31')],qs['fields'](_0x37ea31[_0xb8b2('0x32')][_0xb8b2('0x36')]));_0x42b97f[_0xb8b2('0x37')]=_0x42b97f[_0xb8b2('0x37')][_0xb8b2('0x38')]?_0x42b97f[_0xb8b2('0x37')]:_0x394359[_0xb8b2('0x31')];if(!_0x37ea31[_0xb8b2('0x32')][_0xb8b2('0x39')](_0xb8b2('0x3a'))){_0x42b97f[_0xb8b2('0x1e')]=qs[_0xb8b2('0x1e')](_0x37ea31[_0xb8b2('0x32')][_0xb8b2('0x1e')]);_0x42b97f[_0xb8b2('0x1c')]=qs[_0xb8b2('0x1c')](_0x37ea31[_0xb8b2('0x32')][_0xb8b2('0x1c')]);}_0x42b97f[_0xb8b2('0x3b')]=qs[_0xb8b2('0x3c')](_0x37ea31[_0xb8b2('0x32')][_0xb8b2('0x3c')]);_0x42b97f[_0xb8b2('0x3d')]=qs[_0xb8b2('0x34')](_[_0xb8b2('0x3e')](_0x37ea31[_0xb8b2('0x32')],_0x394359[_0xb8b2('0x34')]),_0x493c16);if(_0x37ea31['query']['filter']){_0x42b97f[_0xb8b2('0x3d')]=_['merge'](_0x42b97f[_0xb8b2('0x3d')],{'$or':_[_0xb8b2('0x2c')](_0x493c16,function(_0x30c686){if(_0x30c686[_0xb8b2('0x30')]!=='VIRTUAL'){var _0x517473={};_0x517473[_0x30c686[_0xb8b2('0x2a')]]={'$like':'%'+_0x37ea31[_0xb8b2('0x32')][_0xb8b2('0x3f')]+'%'};return _0x517473;}})});}_0x42b97f=_[_0xb8b2('0x40')]({},_0x42b97f,_0x37ea31[_0xb8b2('0x41')]);var _0x4fa963={'where':_0x42b97f[_0xb8b2('0x3d')]};return db[_0xb8b2('0x2d')][_0xb8b2('0x1f')](_0x4fa963)[_0xb8b2('0x25')](function(_0x283eb5){_0x21b008['count']=_0x283eb5;if(_0x37ea31[_0xb8b2('0x32')][_0xb8b2('0x42')]){_0x42b97f[_0xb8b2('0x43')]=[{'all':!![]}];}return db[_0xb8b2('0x2d')][_0xb8b2('0x44')](_0x42b97f);})[_0xb8b2('0x25')](function(_0x37370a){_0x21b008[_0xb8b2('0x45')]=_0x37370a;return _0x21b008;})[_0xb8b2('0x25')](respondWithFilteredResult(_0x1899d9,_0x42b97f))[_0xb8b2('0x46')](handleError(_0x1899d9,null));};exports['show']=function(_0x486d4b,_0x419e3e){var _0x51756b={'raw':![],'where':{'id':_0x486d4b[_0xb8b2('0x47')]['id']}},_0x4651e2={};_0x4651e2[_0xb8b2('0x31')]=_[_0xb8b2('0x33')](db[_0xb8b2('0x2d')]['rawAttributes']);_0x4651e2[_0xb8b2('0x32')]=_[_0xb8b2('0x33')](_0x486d4b[_0xb8b2('0x32')]);_0x4651e2[_0xb8b2('0x34')]=_[_0xb8b2('0x35')](_0x4651e2[_0xb8b2('0x31')],_0x4651e2[_0xb8b2('0x32')]);_0x51756b[_0xb8b2('0x37')]=_[_0xb8b2('0x35')](_0x4651e2[_0xb8b2('0x31')],qs[_0xb8b2('0x36')](_0x486d4b['query'][_0xb8b2('0x36')]));_0x51756b[_0xb8b2('0x37')]=_0x51756b[_0xb8b2('0x37')][_0xb8b2('0x38')]?_0x51756b[_0xb8b2('0x37')]:_0x4651e2[_0xb8b2('0x31')];if(_0x486d4b[_0xb8b2('0x32')][_0xb8b2('0x42')]){_0x51756b[_0xb8b2('0x43')]=[{'all':!![]}];}_0x51756b=_[_0xb8b2('0x40')]({},_0x51756b,_0x486d4b[_0xb8b2('0x41')]);return db[_0xb8b2('0x2d')][_0xb8b2('0x48')](_0x51756b)['then'](handleEntityNotFound(_0x419e3e,null))[_0xb8b2('0x25')](respondWithResult(_0x419e3e,null))[_0xb8b2('0x46')](handleError(_0x419e3e,null));};exports['create']=function(_0x35b691,_0x2b9c9a){return db[_0xb8b2('0x2d')]['create'](_0x35b691[_0xb8b2('0x49')],{})[_0xb8b2('0x25')](function(_0x1f106a){var _0x2d0ed5=_0x35b691[_0xb8b2('0x4a')][_0xb8b2('0x26')]({'plain':!![]});if(!_0x2d0ed5)throw new Error(_0xb8b2('0x4b'));if(_0x2d0ed5[_0xb8b2('0x4c')]===_0xb8b2('0x4a')){var _0x3397b0=_0x1f106a[_0xb8b2('0x26')]({'plain':!![]});var _0x4434b3=_0xb8b2('0x4d');return db[_0xb8b2('0x4e')][_0xb8b2('0x48')]({'where':{'name':_0x4434b3,'userProfileId':_0x2d0ed5['userProfileId']},'raw':!![]})['then'](function(_0x46ab13){if(_0x46ab13&&_0x46ab13[_0xb8b2('0x4f')]===0x0){return db[_0xb8b2('0x50')][_0xb8b2('0x51')]({'name':_0x3397b0[_0xb8b2('0x2a')],'resourceId':_0x3397b0['id'],'type':_0x46ab13[_0xb8b2('0x2a')],'sectionId':_0x46ab13['id']},{})['then'](function(){return _0x1f106a;});}else{return _0x1f106a;}})[_0xb8b2('0x46')](function(_0x3a07b5){logger[_0xb8b2('0x28')](_0xb8b2('0x52'),_0x3a07b5);throw _0x3a07b5;});}return _0x1f106a;})[_0xb8b2('0x25')](respondWithResult(_0x2b9c9a,0xc9))[_0xb8b2('0x46')](handleError(_0x2b9c9a,null));};exports[_0xb8b2('0x24')]=function(_0x25ad26,_0x567892){if(_0x25ad26[_0xb8b2('0x49')]['id']){delete _0x25ad26['body']['id'];}return db[_0xb8b2('0x2d')][_0xb8b2('0x48')]({'where':{'id':_0x25ad26[_0xb8b2('0x47')]['id']}})[_0xb8b2('0x25')](handleEntityNotFound(_0x567892,null))[_0xb8b2('0x25')](saveUpdates(_0x25ad26[_0xb8b2('0x49')],null))[_0xb8b2('0x25')](respondWithResult(_0x567892,null))['catch'](handleError(_0x567892,null));};exports[_0xb8b2('0x53')]=function(_0xf450d7,_0x1ad5d4){return db[_0xb8b2('0x2d')][_0xb8b2('0x48')]({'where':{'id':_0xf450d7['params']['id']}})[_0xb8b2('0x25')](handleEntityNotFound(_0x1ad5d4,null))['then'](removeEntity(_0x1ad5d4,null))['catch'](handleError(_0x1ad5d4,null));};