4dcaaf21c2e45fcf827a38fdd8e71de2cdb8e046
[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 _0xb9f9=['filters','filter','where','merge','count','include','findAll','rows','show','includeAll','options','find','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','ChanSpies','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','catch','params','html-pdf','eml-format','zip-dir','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','set','Content-Range','reject','save','update','then','destroy','UserProfileResource','stack','name','index','VoiceChanSpy','rawAttributes','type','key','model','map','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort'];(function(_0x21f2d7,_0x1c828a){var _0x17691e=function(_0x53ae55){while(--_0x53ae55){_0x21f2d7['push'](_0x21f2d7['shift']());}};_0x17691e(++_0x1c828a);}(_0xb9f9,0x6b));var _0x9b9f=function(_0xb4e052,_0x1d3cb6){_0xb4e052=_0xb4e052-0x0;var _0x5197e7=_0xb9f9[_0xb4e052];return _0x5197e7;};'use strict';var pdf=require(_0x9b9f('0x0'));var emlformat=require(_0x9b9f('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x9b9f('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x9b9f('0x3'));var moment=require(_0x9b9f('0x4'));var BPromise=require(_0x9b9f('0x5'));var Mustache=require(_0x9b9f('0x6'));var util=require(_0x9b9f('0x7'));var path=require(_0x9b9f('0x8'));var sox=require('sox');var csv=require(_0x9b9f('0x9'));var ejs=require(_0x9b9f('0xa'));var fs=require('fs');var _=require(_0x9b9f('0xb'));var squel=require(_0x9b9f('0xc'));var crypto=require(_0x9b9f('0xd'));var jsforce=require(_0x9b9f('0xe'));var deskjs=require(_0x9b9f('0xf'));var toCsv=require(_0x9b9f('0x9'));var querystring=require(_0x9b9f('0x10'));var Papa=require('papaparse');var Redis=require(_0x9b9f('0x11'));var authService=require(_0x9b9f('0x12'));var qs=require(_0x9b9f('0x13'));var as=require(_0x9b9f('0x14'));var hardwareService=require(_0x9b9f('0x15'));var logger=require(_0x9b9f('0x16'))('api');var utils=require(_0x9b9f('0x17'));var config=require(_0x9b9f('0x18'));var licenseUtil=require(_0x9b9f('0x19'));var db=require(_0x9b9f('0x1a'))['db'];function respondWithStatusCode(_0x5e4683,_0x437a0c){_0x437a0c=_0x437a0c||0xcc;return function(_0x28245a){if(_0x28245a){return _0x5e4683[_0x9b9f('0x1b')](_0x437a0c);}return _0x5e4683[_0x9b9f('0x1c')](_0x437a0c)[_0x9b9f('0x1d')]();};}function respondWithResult(_0x11630a,_0x1282b2){_0x1282b2=_0x1282b2||0xc8;return function(_0x12526e){if(_0x12526e){return _0x11630a[_0x9b9f('0x1c')](_0x1282b2)[_0x9b9f('0x1e')](_0x12526e);}};}function respondWithFilteredResult(_0x4a2156,_0x3fc89b){return function(_0x330bae){if(_0x330bae){var _0x321328=_0x330bae['count'],_0x2312ff=_0x3fc89b[_0x9b9f('0x1f')],_0x1673f9=_0x3fc89b[_0x9b9f('0x1f')]+_0x3fc89b['limit'],_0x2bae6a;if(_0x1673f9>=_0x321328){_0x1673f9=_0x321328;_0x2bae6a=0xc8;}else{_0x2bae6a=0xce;}_0x4a2156[_0x9b9f('0x1c')](_0x2bae6a);return _0x4a2156[_0x9b9f('0x20')](_0x9b9f('0x21'),_0x2312ff+'-'+_0x1673f9+'/'+_0x321328)[_0x9b9f('0x1e')](_0x330bae);}return null;};}function patchUpdates(_0x56af22){return function(_0x3e16e1){try{jsonpatch['apply'](_0x3e16e1,_0x56af22,!![]);}catch(_0x1adeef){return BPromise[_0x9b9f('0x22')](_0x1adeef);}return _0x3e16e1[_0x9b9f('0x23')]();};}function saveUpdates(_0x3e509e,_0x5171f4){return function(_0x4eb60b){if(_0x4eb60b){return _0x4eb60b[_0x9b9f('0x24')](_0x3e509e)[_0x9b9f('0x25')](function(_0x322da6){return _0x322da6;});}return null;};}function removeEntity(_0x41501c,_0x31d766){return function(_0xfed8ed){if(_0xfed8ed){return _0xfed8ed[_0x9b9f('0x26')]()[_0x9b9f('0x25')](function(){var _0x61dfdf=_0xfed8ed['get']({'plain':!![]});var _0x2a80a5='ChanSpies';return db[_0x9b9f('0x27')]['destroy']({'where':{'type':_0x2a80a5,'resourceId':_0x61dfdf['id']}})[_0x9b9f('0x25')](function(){return _0xfed8ed;});})[_0x9b9f('0x25')](function(){_0x41501c[_0x9b9f('0x1c')](0xcc)[_0x9b9f('0x1d')]();});}};}function handleEntityNotFound(_0x58e2bf,_0x342a0d){return function(_0x37d934){if(!_0x37d934){_0x58e2bf[_0x9b9f('0x1b')](0x194);}return _0x37d934;};}function handleError(_0x4402bf,_0x12d7e1){_0x12d7e1=_0x12d7e1||0x1f4;return function(_0x4614d1){logger['error'](_0x4614d1[_0x9b9f('0x28')]);if(_0x4614d1[_0x9b9f('0x29')]){delete _0x4614d1[_0x9b9f('0x29')];}_0x4402bf[_0x9b9f('0x1c')](_0x12d7e1)['send'](_0x4614d1);};}exports[_0x9b9f('0x2a')]=function(_0xdfc103,_0x2c2063){var _0x4d8301={},_0x1b1d1a={},_0x284227={'count':0x0,'rows':[]};var _0x120589=_['map'](db[_0x9b9f('0x2b')][_0x9b9f('0x2c')],function(_0x5e4c98){return{'name':_0x5e4c98['fieldName'],'type':_0x5e4c98[_0x9b9f('0x2d')][_0x9b9f('0x2e')]};});_0x1b1d1a[_0x9b9f('0x2f')]=_[_0x9b9f('0x30')](_0x120589,_0x9b9f('0x29'));_0x1b1d1a[_0x9b9f('0x31')]=_[_0x9b9f('0x32')](_0xdfc103[_0x9b9f('0x31')]);_0x1b1d1a['filters']=_[_0x9b9f('0x33')](_0x1b1d1a[_0x9b9f('0x2f')],_0x1b1d1a[_0x9b9f('0x31')]);_0x4d8301[_0x9b9f('0x34')]=_[_0x9b9f('0x33')](_0x1b1d1a[_0x9b9f('0x2f')],qs[_0x9b9f('0x35')](_0xdfc103['query'][_0x9b9f('0x35')]));_0x4d8301['attributes']=_0x4d8301[_0x9b9f('0x34')][_0x9b9f('0x36')]?_0x4d8301[_0x9b9f('0x34')]:_0x1b1d1a[_0x9b9f('0x2f')];if(!_0xdfc103[_0x9b9f('0x31')][_0x9b9f('0x37')](_0x9b9f('0x38'))){_0x4d8301['limit']=qs['limit'](_0xdfc103['query']['limit']);_0x4d8301[_0x9b9f('0x1f')]=qs[_0x9b9f('0x1f')](_0xdfc103[_0x9b9f('0x31')][_0x9b9f('0x1f')]);}_0x4d8301[_0x9b9f('0x39')]=qs[_0x9b9f('0x3a')](_0xdfc103[_0x9b9f('0x31')]['sort']);_0x4d8301['where']=qs[_0x9b9f('0x3b')](_['pick'](_0xdfc103['query'],_0x1b1d1a[_0x9b9f('0x3b')]),_0x120589);if(_0xdfc103[_0x9b9f('0x31')][_0x9b9f('0x3c')]){_0x4d8301[_0x9b9f('0x3d')]=_[_0x9b9f('0x3e')](_0x4d8301[_0x9b9f('0x3d')],{'$or':_[_0x9b9f('0x30')](_0x120589,function(_0x4527db){if(_0x4527db[_0x9b9f('0x2d')]!=='VIRTUAL'){var _0x247e09={};_0x247e09[_0x4527db[_0x9b9f('0x29')]]={'$like':'%'+_0xdfc103[_0x9b9f('0x31')]['filter']+'%'};return _0x247e09;}})});}_0x4d8301=_[_0x9b9f('0x3e')]({},_0x4d8301,_0xdfc103['options']);var _0x5a4b27={'where':_0x4d8301['where']};return db[_0x9b9f('0x2b')][_0x9b9f('0x3f')](_0x5a4b27)['then'](function(_0xcb2de0){_0x284227[_0x9b9f('0x3f')]=_0xcb2de0;if(_0xdfc103[_0x9b9f('0x31')]['includeAll']){_0x4d8301[_0x9b9f('0x40')]=[{'all':!![]}];}return db['VoiceChanSpy'][_0x9b9f('0x41')](_0x4d8301);})[_0x9b9f('0x25')](function(_0x197d95){_0x284227[_0x9b9f('0x42')]=_0x197d95;return _0x284227;})['then'](respondWithFilteredResult(_0x2c2063,_0x4d8301))['catch'](handleError(_0x2c2063,null));};exports[_0x9b9f('0x43')]=function(_0x1db30d,_0x2f0c36){var _0x6ee818={'raw':![],'where':{'id':_0x1db30d['params']['id']}},_0x284388={};_0x284388['model']=_[_0x9b9f('0x32')](db[_0x9b9f('0x2b')][_0x9b9f('0x2c')]);_0x284388[_0x9b9f('0x31')]=_[_0x9b9f('0x32')](_0x1db30d[_0x9b9f('0x31')]);_0x284388[_0x9b9f('0x3b')]=_[_0x9b9f('0x33')](_0x284388[_0x9b9f('0x2f')],_0x284388['query']);_0x6ee818[_0x9b9f('0x34')]=_['intersection'](_0x284388[_0x9b9f('0x2f')],qs[_0x9b9f('0x35')](_0x1db30d[_0x9b9f('0x31')][_0x9b9f('0x35')]));_0x6ee818[_0x9b9f('0x34')]=_0x6ee818[_0x9b9f('0x34')][_0x9b9f('0x36')]?_0x6ee818[_0x9b9f('0x34')]:_0x284388[_0x9b9f('0x2f')];if(_0x1db30d[_0x9b9f('0x31')][_0x9b9f('0x44')]){_0x6ee818[_0x9b9f('0x40')]=[{'all':!![]}];}_0x6ee818=_[_0x9b9f('0x3e')]({},_0x6ee818,_0x1db30d[_0x9b9f('0x45')]);return db['VoiceChanSpy'][_0x9b9f('0x46')](_0x6ee818)[_0x9b9f('0x25')](handleEntityNotFound(_0x2f0c36,null))[_0x9b9f('0x25')](respondWithResult(_0x2f0c36,null))['catch'](handleError(_0x2f0c36,null));};exports[_0x9b9f('0x47')]=function(_0x54caec,_0x58ec46){return db[_0x9b9f('0x2b')][_0x9b9f('0x47')](_0x54caec[_0x9b9f('0x48')],{})[_0x9b9f('0x25')](function(_0x4bcd4c){var _0x2d18d2=_0x54caec[_0x9b9f('0x49')][_0x9b9f('0x4a')]({'plain':!![]});if(!_0x2d18d2)throw new Error(_0x9b9f('0x4b'));if(_0x2d18d2[_0x9b9f('0x4c')]===_0x9b9f('0x49')){var _0x19a738=_0x4bcd4c[_0x9b9f('0x4a')]({'plain':!![]});var _0x101d86=_0x9b9f('0x4d');return db[_0x9b9f('0x4e')][_0x9b9f('0x46')]({'where':{'name':_0x101d86,'userProfileId':_0x2d18d2['userProfileId']},'raw':!![]})[_0x9b9f('0x25')](function(_0x205425){if(_0x205425&&_0x205425[_0x9b9f('0x4f')]===0x0){return db[_0x9b9f('0x27')][_0x9b9f('0x47')]({'name':_0x19a738[_0x9b9f('0x29')],'resourceId':_0x19a738['id'],'type':_0x205425[_0x9b9f('0x29')],'sectionId':_0x205425['id']},{})[_0x9b9f('0x25')](function(){return _0x4bcd4c;});}else{return _0x4bcd4c;}})['catch'](function(_0x55c023){logger['error'](_0x9b9f('0x50'),_0x55c023);throw _0x55c023;});}return _0x4bcd4c;})['then'](respondWithResult(_0x58ec46,0xc9))[_0x9b9f('0x51')](handleError(_0x58ec46,null));};exports[_0x9b9f('0x24')]=function(_0x4ca67b,_0x4b99c1){if(_0x4ca67b[_0x9b9f('0x48')]['id']){delete _0x4ca67b['body']['id'];}return db[_0x9b9f('0x2b')][_0x9b9f('0x46')]({'where':{'id':_0x4ca67b['params']['id']}})[_0x9b9f('0x25')](handleEntityNotFound(_0x4b99c1,null))[_0x9b9f('0x25')](saveUpdates(_0x4ca67b[_0x9b9f('0x48')],null))['then'](respondWithResult(_0x4b99c1,null))['catch'](handleError(_0x4b99c1,null));};exports[_0x9b9f('0x26')]=function(_0xebbb04,_0x438602){return db[_0x9b9f('0x2b')][_0x9b9f('0x46')]({'where':{'id':_0xebbb04[_0x9b9f('0x52')]['id']}})[_0x9b9f('0x25')](handleEntityNotFound(_0x438602,null))[_0x9b9f('0x25')](removeEntity(_0x438602,null))[_0x9b9f('0x51')](handleError(_0x438602,null));};