6e7f488a67b8b5baf19c57353a55f286fc50d8f3
[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 _0xa1b9=['intersection','attributes','fields','length','nolimit','sort','where','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','params','keys','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','get','ChanSpies','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','squel','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','undefined','limit','count','offset','Content-Range','reject','save','update','then','destroy','UserProfileResource','error','stack','name','send','index','map','VoiceChanSpy','rawAttributes','type','model','query','filters'];(function(_0x4e676e,_0x2a7c6d){var _0x336a3c=function(_0x4767c4){while(--_0x4767c4){_0x4e676e['push'](_0x4e676e['shift']());}};_0x336a3c(++_0x2a7c6d);}(_0xa1b9,0x71));var _0x9a1b=function(_0x2d8fc2,_0x1c461d){_0x2d8fc2=_0x2d8fc2-0x0;var _0x3a9e53=_0xa1b9[_0x2d8fc2];return _0x3a9e53;};'use strict';var emlformat=require(_0x9a1b('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x9a1b('0x1'));var jsonpatch=require(_0x9a1b('0x2'));var rp=require(_0x9a1b('0x3'));var moment=require(_0x9a1b('0x4'));var BPromise=require(_0x9a1b('0x5'));var Mustache=require(_0x9a1b('0x6'));var util=require(_0x9a1b('0x7'));var path=require('path');var sox=require(_0x9a1b('0x8'));var csv=require(_0x9a1b('0x9'));var ejs=require(_0x9a1b('0xa'));var fs=require('fs');var fs_extra=require(_0x9a1b('0xb'));var _=require('lodash');var squel=require(_0x9a1b('0xc'));var crypto=require('crypto');var jsforce=require(_0x9a1b('0xd'));var deskjs=require(_0x9a1b('0xe'));var toCsv=require(_0x9a1b('0x9'));var querystring=require(_0x9a1b('0xf'));var Papa=require(_0x9a1b('0x10'));var Redis=require('ioredis');var authService=require(_0x9a1b('0x11'));var qs=require(_0x9a1b('0x12'));var as=require(_0x9a1b('0x13'));var hardwareService=require(_0x9a1b('0x14'));var logger=require(_0x9a1b('0x15'))(_0x9a1b('0x16'));var utils=require(_0x9a1b('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0x9a1b('0x18'));var db=require(_0x9a1b('0x19'))['db'];function respondWithStatusCode(_0x27062b,_0x5ee9d3){_0x5ee9d3=_0x5ee9d3||0xcc;return function(_0x1d016d){if(_0x1d016d){return _0x27062b[_0x9a1b('0x1a')](_0x5ee9d3);}return _0x27062b[_0x9a1b('0x1b')](_0x5ee9d3)[_0x9a1b('0x1c')]();};}function respondWithResult(_0x390ad9,_0x157b6f){_0x157b6f=_0x157b6f||0xc8;return function(_0x3fe388){if(_0x3fe388){return _0x390ad9[_0x9a1b('0x1b')](_0x157b6f)[_0x9a1b('0x1d')](_0x3fe388);}};}function respondWithFilteredResult(_0x101622,_0x5c397f){return function(_0x357cd9){if(_0x357cd9){var _0x2440fc=typeof _0x5c397f['offset']===_0x9a1b('0x1e')&&typeof _0x5c397f[_0x9a1b('0x1f')]===_0x9a1b('0x1e');var _0x1a7324=_0x357cd9[_0x9a1b('0x20')];var _0x478626=_0x2440fc?0x0:_0x5c397f[_0x9a1b('0x21')];var _0x599325=_0x2440fc?_0x357cd9[_0x9a1b('0x20')]:_0x5c397f[_0x9a1b('0x21')]+_0x5c397f[_0x9a1b('0x1f')];var _0x1f1dea;if(_0x599325>=_0x1a7324){_0x599325=_0x1a7324;_0x1f1dea=0xc8;}else{_0x1f1dea=0xce;}_0x101622[_0x9a1b('0x1b')](_0x1f1dea);return _0x101622['set'](_0x9a1b('0x22'),_0x478626+'-'+_0x599325+'/'+_0x1a7324)[_0x9a1b('0x1d')](_0x357cd9);}return null;};}function patchUpdates(_0x36c95c){return function(_0x1977a7){try{jsonpatch['apply'](_0x1977a7,_0x36c95c,!![]);}catch(_0x2ccb02){return BPromise[_0x9a1b('0x23')](_0x2ccb02);}return _0x1977a7[_0x9a1b('0x24')]();};}function saveUpdates(_0x13f828,_0x1c9ab3){return function(_0x327cac){if(_0x327cac){return _0x327cac[_0x9a1b('0x25')](_0x13f828)[_0x9a1b('0x26')](function(_0xb6b23a){return _0xb6b23a;});}return null;};}function removeEntity(_0x37971c,_0x5841c1){return function(_0x2439e9){if(_0x2439e9){return _0x2439e9[_0x9a1b('0x27')]()[_0x9a1b('0x26')](function(){var _0x4bb81c=_0x2439e9['get']({'plain':!![]});var _0x3b0ff3='ChanSpies';return db[_0x9a1b('0x28')]['destroy']({'where':{'type':_0x3b0ff3,'resourceId':_0x4bb81c['id']}})['then'](function(){return _0x2439e9;});})['then'](function(){_0x37971c[_0x9a1b('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2bd6b3,_0x116d3e){return function(_0x4983f6){if(!_0x4983f6){_0x2bd6b3[_0x9a1b('0x1a')](0x194);}return _0x4983f6;};}function handleError(_0x44f930,_0x15812d){_0x15812d=_0x15812d||0x1f4;return function(_0x1c13d6){logger[_0x9a1b('0x29')](_0x1c13d6[_0x9a1b('0x2a')]);if(_0x1c13d6[_0x9a1b('0x2b')]){delete _0x1c13d6['name'];}_0x44f930['status'](_0x15812d)[_0x9a1b('0x2c')](_0x1c13d6);};}exports[_0x9a1b('0x2d')]=function(_0x56e6ed,_0x14ea6b){var _0x43c2e7={},_0x4028f0={},_0x3bc034={'count':0x0,'rows':[]};var _0x311432=_[_0x9a1b('0x2e')](db[_0x9a1b('0x2f')][_0x9a1b('0x30')],function(_0x1e7f23){return{'name':_0x1e7f23['fieldName'],'type':_0x1e7f23[_0x9a1b('0x31')]['key']};});_0x4028f0[_0x9a1b('0x32')]=_[_0x9a1b('0x2e')](_0x311432,_0x9a1b('0x2b'));_0x4028f0[_0x9a1b('0x33')]=_['keys'](_0x56e6ed[_0x9a1b('0x33')]);_0x4028f0[_0x9a1b('0x34')]=_[_0x9a1b('0x35')](_0x4028f0[_0x9a1b('0x32')],_0x4028f0[_0x9a1b('0x33')]);_0x43c2e7[_0x9a1b('0x36')]=_[_0x9a1b('0x35')](_0x4028f0[_0x9a1b('0x32')],qs[_0x9a1b('0x37')](_0x56e6ed['query'][_0x9a1b('0x37')]));_0x43c2e7[_0x9a1b('0x36')]=_0x43c2e7[_0x9a1b('0x36')][_0x9a1b('0x38')]?_0x43c2e7[_0x9a1b('0x36')]:_0x4028f0[_0x9a1b('0x32')];if(!_0x56e6ed[_0x9a1b('0x33')]['hasOwnProperty'](_0x9a1b('0x39'))){_0x43c2e7[_0x9a1b('0x1f')]=qs[_0x9a1b('0x1f')](_0x56e6ed[_0x9a1b('0x33')][_0x9a1b('0x1f')]);_0x43c2e7[_0x9a1b('0x21')]=qs[_0x9a1b('0x21')](_0x56e6ed[_0x9a1b('0x33')][_0x9a1b('0x21')]);}_0x43c2e7['order']=qs[_0x9a1b('0x3a')](_0x56e6ed[_0x9a1b('0x33')]['sort']);_0x43c2e7[_0x9a1b('0x3b')]=qs[_0x9a1b('0x34')](_['pick'](_0x56e6ed['query'],_0x4028f0['filters']),_0x311432);if(_0x56e6ed[_0x9a1b('0x33')][_0x9a1b('0x3c')]){_0x43c2e7[_0x9a1b('0x3b')]=_[_0x9a1b('0x3d')](_0x43c2e7[_0x9a1b('0x3b')],{'$or':_['map'](_0x311432,function(_0x28cac7){if(_0x28cac7[_0x9a1b('0x31')]!==_0x9a1b('0x3e')){var _0x383003={};_0x383003[_0x28cac7[_0x9a1b('0x2b')]]={'$like':'%'+_0x56e6ed[_0x9a1b('0x33')][_0x9a1b('0x3c')]+'%'};return _0x383003;}})});}_0x43c2e7=_['merge']({},_0x43c2e7,_0x56e6ed[_0x9a1b('0x3f')]);var _0x1599df={'where':_0x43c2e7['where']};return db[_0x9a1b('0x2f')][_0x9a1b('0x20')](_0x1599df)[_0x9a1b('0x26')](function(_0x69c499){_0x3bc034['count']=_0x69c499;if(_0x56e6ed[_0x9a1b('0x33')][_0x9a1b('0x40')]){_0x43c2e7[_0x9a1b('0x41')]=[{'all':!![]}];}return db[_0x9a1b('0x2f')][_0x9a1b('0x42')](_0x43c2e7);})[_0x9a1b('0x26')](function(_0x515bb8){_0x3bc034[_0x9a1b('0x43')]=_0x515bb8;return _0x3bc034;})[_0x9a1b('0x26')](respondWithFilteredResult(_0x14ea6b,_0x43c2e7))[_0x9a1b('0x44')](handleError(_0x14ea6b,null));};exports['show']=function(_0x1a7c68,_0x3ffa84){var _0x3c1fc3={'raw':![],'where':{'id':_0x1a7c68[_0x9a1b('0x45')]['id']}},_0xd86ff5={};_0xd86ff5[_0x9a1b('0x32')]=_[_0x9a1b('0x46')](db['VoiceChanSpy'][_0x9a1b('0x30')]);_0xd86ff5[_0x9a1b('0x33')]=_[_0x9a1b('0x46')](_0x1a7c68[_0x9a1b('0x33')]);_0xd86ff5['filters']=_[_0x9a1b('0x35')](_0xd86ff5[_0x9a1b('0x32')],_0xd86ff5[_0x9a1b('0x33')]);_0x3c1fc3[_0x9a1b('0x36')]=_[_0x9a1b('0x35')](_0xd86ff5[_0x9a1b('0x32')],qs[_0x9a1b('0x37')](_0x1a7c68['query']['fields']));_0x3c1fc3[_0x9a1b('0x36')]=_0x3c1fc3[_0x9a1b('0x36')]['length']?_0x3c1fc3[_0x9a1b('0x36')]:_0xd86ff5[_0x9a1b('0x32')];if(_0x1a7c68[_0x9a1b('0x33')]['includeAll']){_0x3c1fc3['include']=[{'all':!![]}];}_0x3c1fc3=_['merge']({},_0x3c1fc3,_0x1a7c68[_0x9a1b('0x3f')]);return db[_0x9a1b('0x2f')]['find'](_0x3c1fc3)[_0x9a1b('0x26')](handleEntityNotFound(_0x3ffa84,null))[_0x9a1b('0x26')](respondWithResult(_0x3ffa84,null))['catch'](handleError(_0x3ffa84,null));};exports['create']=function(_0x23e3b8,_0x2ff4b5){return db['VoiceChanSpy'][_0x9a1b('0x47')](_0x23e3b8[_0x9a1b('0x48')],{})[_0x9a1b('0x26')](function(_0x3eab82){var _0x4b0353=_0x23e3b8['user']['get']({'plain':!![]});if(!_0x4b0353)throw new Error(_0x9a1b('0x49'));if(_0x4b0353[_0x9a1b('0x4a')]===_0x9a1b('0x4b')){var _0x3f9c17=_0x3eab82[_0x9a1b('0x4c')]({'plain':!![]});var _0x36bb41=_0x9a1b('0x4d');return db[_0x9a1b('0x4e')][_0x9a1b('0x4f')]({'where':{'name':_0x36bb41,'userProfileId':_0x4b0353[_0x9a1b('0x50')]},'raw':!![]})[_0x9a1b('0x26')](function(_0xd1f1fc){if(_0xd1f1fc&&_0xd1f1fc[_0x9a1b('0x51')]===0x0){return db[_0x9a1b('0x28')]['create']({'name':_0x3f9c17['name'],'resourceId':_0x3f9c17['id'],'type':_0xd1f1fc[_0x9a1b('0x2b')],'sectionId':_0xd1f1fc['id']},{})[_0x9a1b('0x26')](function(){return _0x3eab82;});}else{return _0x3eab82;}})[_0x9a1b('0x44')](function(_0x2ae8f3){logger[_0x9a1b('0x29')](_0x9a1b('0x52'),_0x2ae8f3);throw _0x2ae8f3;});}return _0x3eab82;})[_0x9a1b('0x26')](respondWithResult(_0x2ff4b5,0xc9))[_0x9a1b('0x44')](handleError(_0x2ff4b5,null));};exports[_0x9a1b('0x25')]=function(_0x5c35b7,_0x11b466){if(_0x5c35b7[_0x9a1b('0x48')]['id']){delete _0x5c35b7[_0x9a1b('0x48')]['id'];}return db[_0x9a1b('0x2f')]['find']({'where':{'id':_0x5c35b7[_0x9a1b('0x45')]['id']}})[_0x9a1b('0x26')](handleEntityNotFound(_0x11b466,null))['then'](saveUpdates(_0x5c35b7[_0x9a1b('0x48')],null))['then'](respondWithResult(_0x11b466,null))['catch'](handleError(_0x11b466,null));};exports[_0x9a1b('0x27')]=function(_0x160f22,_0xa6215){return db['VoiceChanSpy'][_0x9a1b('0x4f')]({'where':{'id':_0x160f22[_0x9a1b('0x45')]['id']}})[_0x9a1b('0x26')](handleEntityNotFound(_0xa6215,null))[_0x9a1b('0x26')](removeEntity(_0xa6215,null))[_0x9a1b('0x44')](handleError(_0xa6215,null));};