bd7891b9aa301c1ef4bed3f0f356d01a941cd0af
[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 _0xbc55=['end','error','stack','name','render','merge','contact','message','agent','interaction','account','index','rawAttributes','fieldName','type','key','model','query','keys','filters','fields','attributes','length','hasOwnProperty','nolimit','where','filter','map','VIRTUAL','VoiceChanSpy','include','findAll','catch','params','intersection','includeAll','options','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','undefined','offset','count','limit','set','Content-Range','reject','update','then','get','ChanSpies','UserProfileResource','destroy'];(function(_0x4c70c4,_0x963969){var _0x437865=function(_0x54e323){while(--_0x54e323){_0x4c70c4['push'](_0x4c70c4['shift']());}};_0x437865(++_0x963969);}(_0xbc55,0x89));var _0x5bc5=function(_0x114fcb,_0x28b9e6){_0x114fcb=_0x114fcb-0x0;var _0x5962d5=_0xbc55[_0x114fcb];return _0x5962d5;};'use strict';var emlformat=require(_0x5bc5('0x0'));var rimraf=require(_0x5bc5('0x1'));var zipdir=require(_0x5bc5('0x2'));var jsonpatch=require(_0x5bc5('0x3'));var rp=require(_0x5bc5('0x4'));var moment=require(_0x5bc5('0x5'));var BPromise=require(_0x5bc5('0x6'));var Mustache=require(_0x5bc5('0x7'));var util=require('util');var path=require(_0x5bc5('0x8'));var sox=require(_0x5bc5('0x9'));var csv=require('to-csv');var ejs=require(_0x5bc5('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x5bc5('0xb'));var squel=require(_0x5bc5('0xc'));var crypto=require(_0x5bc5('0xd'));var jsforce=require(_0x5bc5('0xe'));var deskjs=require(_0x5bc5('0xf'));var toCsv=require(_0x5bc5('0x10'));var querystring=require(_0x5bc5('0x11'));var Papa=require(_0x5bc5('0x12'));var Redis=require('ioredis');var authService=require(_0x5bc5('0x13'));var qs=require(_0x5bc5('0x14'));var as=require(_0x5bc5('0x15'));var hardwareService=require(_0x5bc5('0x16'));var logger=require('../../config/logger')('api');var utils=require(_0x5bc5('0x17'));var config=require(_0x5bc5('0x18'));var licenseUtil=require(_0x5bc5('0x19'));var db=require(_0x5bc5('0x1a'))['db'];function respondWithStatusCode(_0x1a5377,_0x6e3680){_0x6e3680=_0x6e3680||0xcc;return function(_0x15e4ee){if(_0x15e4ee){return _0x1a5377[_0x5bc5('0x1b')](_0x6e3680);}return _0x1a5377['status'](_0x6e3680)['end']();};}function respondWithResult(_0x8adb80,_0x230b56){_0x230b56=_0x230b56||0xc8;return function(_0x270693){if(_0x270693){return _0x8adb80[_0x5bc5('0x1c')](_0x230b56)[_0x5bc5('0x1d')](_0x270693);}};}function respondWithFilteredResult(_0x179b1d,_0x52860f){return function(_0x13a18a){if(_0x13a18a){var _0x255be8=typeof _0x52860f['offset']===_0x5bc5('0x1e')&&typeof _0x52860f['limit']===_0x5bc5('0x1e');var _0x292d9a=_0x13a18a['count'];var _0x133e47=_0x255be8?0x0:_0x52860f[_0x5bc5('0x1f')];var _0x1aeda0=_0x255be8?_0x13a18a[_0x5bc5('0x20')]:_0x52860f[_0x5bc5('0x1f')]+_0x52860f[_0x5bc5('0x21')];var _0x329c55;if(_0x1aeda0>=_0x292d9a){_0x1aeda0=_0x292d9a;_0x329c55=0xc8;}else{_0x329c55=0xce;}_0x179b1d[_0x5bc5('0x1c')](_0x329c55);return _0x179b1d[_0x5bc5('0x22')](_0x5bc5('0x23'),_0x133e47+'-'+_0x1aeda0+'/'+_0x292d9a)['json'](_0x13a18a);}return null;};}function patchUpdates(_0x161078){return function(_0x32a9f2){try{jsonpatch['apply'](_0x32a9f2,_0x161078,!![]);}catch(_0x520d97){return BPromise[_0x5bc5('0x24')](_0x520d97);}return _0x32a9f2['save']();};}function saveUpdates(_0x39a78b,_0x5b4094){return function(_0x2f599e){if(_0x2f599e){return _0x2f599e[_0x5bc5('0x25')](_0x39a78b)[_0x5bc5('0x26')](function(_0x1a3507){return _0x1a3507;});}return null;};}function removeEntity(_0x3baa15,_0x4da99b){return function(_0x46f2f1){if(_0x46f2f1){return _0x46f2f1['destroy']()['then'](function(){var _0x415973=_0x46f2f1[_0x5bc5('0x27')]({'plain':!![]});var _0x43c1c5=_0x5bc5('0x28');return db[_0x5bc5('0x29')][_0x5bc5('0x2a')]({'where':{'type':_0x43c1c5,'resourceId':_0x415973['id']}})[_0x5bc5('0x26')](function(){return _0x46f2f1;});})[_0x5bc5('0x26')](function(){_0x3baa15[_0x5bc5('0x1c')](0xcc)[_0x5bc5('0x2b')]();});}};}function handleEntityNotFound(_0x2e0c77,_0x428436){return function(_0x27e11c){if(!_0x27e11c){_0x2e0c77[_0x5bc5('0x1b')](0x194);}return _0x27e11c;};}function handleError(_0x465ff5,_0x5018ae){_0x5018ae=_0x5018ae||0x1f4;return function(_0x317b64){logger[_0x5bc5('0x2c')](_0x317b64[_0x5bc5('0x2d')]);if(_0x317b64[_0x5bc5('0x2e')]){delete _0x317b64['name'];}_0x465ff5[_0x5bc5('0x1c')](_0x5018ae)['send'](_0x317b64);};}function getMustacheRender(_0x12688f,_0x21c154){return Mustache[_0x5bc5('0x2f')](_0x12688f,_[_0x5bc5('0x30')](_0x21c154['body'],{'contact':_0x21c154[_0x5bc5('0x31')],'message':_0x21c154[_0x5bc5('0x32')],'agent':_0x21c154[_0x5bc5('0x33')],'interaction':_0x21c154[_0x5bc5('0x34')],'account':_0x21c154[_0x5bc5('0x35')]}))||'';}exports[_0x5bc5('0x36')]=function(_0x4c54a3,_0x4dd49e){var _0x2c8a0b={},_0x489c0e={},_0x36572e={'count':0x0,'rows':[]};var _0x4c771c=_['map'](db['VoiceChanSpy'][_0x5bc5('0x37')],function(_0x390aaf){return{'name':_0x390aaf[_0x5bc5('0x38')],'type':_0x390aaf[_0x5bc5('0x39')][_0x5bc5('0x3a')]};});_0x489c0e[_0x5bc5('0x3b')]=_['map'](_0x4c771c,_0x5bc5('0x2e'));_0x489c0e[_0x5bc5('0x3c')]=_[_0x5bc5('0x3d')](_0x4c54a3[_0x5bc5('0x3c')]);_0x489c0e[_0x5bc5('0x3e')]=_['intersection'](_0x489c0e[_0x5bc5('0x3b')],_0x489c0e[_0x5bc5('0x3c')]);_0x2c8a0b['attributes']=_['intersection'](_0x489c0e[_0x5bc5('0x3b')],qs[_0x5bc5('0x3f')](_0x4c54a3[_0x5bc5('0x3c')][_0x5bc5('0x3f')]));_0x2c8a0b[_0x5bc5('0x40')]=_0x2c8a0b[_0x5bc5('0x40')][_0x5bc5('0x41')]?_0x2c8a0b[_0x5bc5('0x40')]:_0x489c0e[_0x5bc5('0x3b')];if(!_0x4c54a3[_0x5bc5('0x3c')][_0x5bc5('0x42')](_0x5bc5('0x43'))){_0x2c8a0b['limit']=qs[_0x5bc5('0x21')](_0x4c54a3[_0x5bc5('0x3c')][_0x5bc5('0x21')]);_0x2c8a0b['offset']=qs[_0x5bc5('0x1f')](_0x4c54a3[_0x5bc5('0x3c')]['offset']);}_0x2c8a0b['order']=qs['sort'](_0x4c54a3[_0x5bc5('0x3c')]['sort']);_0x2c8a0b[_0x5bc5('0x44')]=qs[_0x5bc5('0x3e')](_['pick'](_0x4c54a3[_0x5bc5('0x3c')],_0x489c0e[_0x5bc5('0x3e')]),_0x4c771c);if(_0x4c54a3[_0x5bc5('0x3c')][_0x5bc5('0x45')]){_0x2c8a0b['where']=_[_0x5bc5('0x30')](_0x2c8a0b[_0x5bc5('0x44')],{'$or':_[_0x5bc5('0x46')](_0x4c771c,function(_0x1065b2){if(_0x1065b2[_0x5bc5('0x39')]!==_0x5bc5('0x47')){var _0x29d13f={};_0x29d13f[_0x1065b2[_0x5bc5('0x2e')]]={'$like':'%'+_0x4c54a3[_0x5bc5('0x3c')]['filter']+'%'};return _0x29d13f;}})});}_0x2c8a0b=_['merge']({},_0x2c8a0b,_0x4c54a3['options']);var _0x4bcd1d={'where':_0x2c8a0b[_0x5bc5('0x44')]};return db[_0x5bc5('0x48')][_0x5bc5('0x20')](_0x4bcd1d)[_0x5bc5('0x26')](function(_0x410adf){_0x36572e[_0x5bc5('0x20')]=_0x410adf;if(_0x4c54a3[_0x5bc5('0x3c')]['includeAll']){_0x2c8a0b[_0x5bc5('0x49')]=[{'all':!![]}];}return db[_0x5bc5('0x48')][_0x5bc5('0x4a')](_0x2c8a0b);})['then'](function(_0x2a1d27){_0x36572e['rows']=_0x2a1d27;return _0x36572e;})[_0x5bc5('0x26')](respondWithFilteredResult(_0x4dd49e,_0x2c8a0b))[_0x5bc5('0x4b')](handleError(_0x4dd49e,null));};exports['show']=function(_0x552a8b,_0x37819f){var _0x4d0b43={'raw':![],'where':{'id':_0x552a8b[_0x5bc5('0x4c')]['id']}},_0x5dc91a={};_0x5dc91a[_0x5bc5('0x3b')]=_['keys'](db[_0x5bc5('0x48')][_0x5bc5('0x37')]);_0x5dc91a['query']=_['keys'](_0x552a8b['query']);_0x5dc91a['filters']=_['intersection'](_0x5dc91a['model'],_0x5dc91a[_0x5bc5('0x3c')]);_0x4d0b43[_0x5bc5('0x40')]=_[_0x5bc5('0x4d')](_0x5dc91a[_0x5bc5('0x3b')],qs[_0x5bc5('0x3f')](_0x552a8b[_0x5bc5('0x3c')][_0x5bc5('0x3f')]));_0x4d0b43[_0x5bc5('0x40')]=_0x4d0b43[_0x5bc5('0x40')]['length']?_0x4d0b43[_0x5bc5('0x40')]:_0x5dc91a[_0x5bc5('0x3b')];if(_0x552a8b[_0x5bc5('0x3c')][_0x5bc5('0x4e')]){_0x4d0b43[_0x5bc5('0x49')]=[{'all':!![]}];}_0x4d0b43=_['merge']({},_0x4d0b43,_0x552a8b[_0x5bc5('0x4f')]);return db['VoiceChanSpy'][_0x5bc5('0x50')](_0x4d0b43)[_0x5bc5('0x26')](handleEntityNotFound(_0x37819f,null))[_0x5bc5('0x26')](respondWithResult(_0x37819f,null))['catch'](handleError(_0x37819f,null));};exports[_0x5bc5('0x51')]=function(_0xb4c37e,_0x340f9d){return db[_0x5bc5('0x48')][_0x5bc5('0x51')](_0xb4c37e[_0x5bc5('0x52')],{})[_0x5bc5('0x26')](function(_0x4c1020){var _0x43ec3f=_0xb4c37e['user']['get']({'plain':!![]});if(!_0x43ec3f)throw new Error(_0x5bc5('0x53'));if(_0x43ec3f[_0x5bc5('0x54')]===_0x5bc5('0x55')){var _0x383349=_0x4c1020['get']({'plain':!![]});var _0x363a1e=_0x5bc5('0x28');return db[_0x5bc5('0x56')][_0x5bc5('0x50')]({'where':{'name':_0x363a1e,'userProfileId':_0x43ec3f[_0x5bc5('0x57')]},'raw':!![]})['then'](function(_0x402fcb){if(_0x402fcb&&_0x402fcb[_0x5bc5('0x58')]===0x0){return db[_0x5bc5('0x29')][_0x5bc5('0x51')]({'name':_0x383349[_0x5bc5('0x2e')],'resourceId':_0x383349['id'],'type':_0x402fcb[_0x5bc5('0x2e')],'sectionId':_0x402fcb['id']},{})[_0x5bc5('0x26')](function(){return _0x4c1020;});}else{return _0x4c1020;}})[_0x5bc5('0x4b')](function(_0x2a5ad7){logger['error'](_0x5bc5('0x59'),_0x2a5ad7);throw _0x2a5ad7;});}return _0x4c1020;})[_0x5bc5('0x26')](respondWithResult(_0x340f9d,0xc9))[_0x5bc5('0x4b')](handleError(_0x340f9d,null));};exports[_0x5bc5('0x25')]=function(_0x2ffbf6,_0x417b8e){if(_0x2ffbf6['body']['id']){delete _0x2ffbf6['body']['id'];}return db[_0x5bc5('0x48')][_0x5bc5('0x50')]({'where':{'id':_0x2ffbf6['params']['id']}})[_0x5bc5('0x26')](handleEntityNotFound(_0x417b8e,null))[_0x5bc5('0x26')](saveUpdates(_0x2ffbf6[_0x5bc5('0x52')],null))['then'](respondWithResult(_0x417b8e,null))[_0x5bc5('0x4b')](handleError(_0x417b8e,null));};exports[_0x5bc5('0x2a')]=function(_0xcdcf20,_0x47ab10){return db[_0x5bc5('0x48')][_0x5bc5('0x50')]({'where':{'id':_0xcdcf20[_0x5bc5('0x4c')]['id']}})[_0x5bc5('0x26')](handleEntityNotFound(_0x47ab10,null))['then'](removeEntity(_0x47ab10,null))[_0x5bc5('0x4b')](handleError(_0x47ab10,null));};