7c1c2161669bace274ea274725f92b738dd09620
[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 _0x6f90=['name','send','index','map','VoiceChanSpy','rawAttributes','type','key','model','keys','query','filters','intersection','attributes','fields','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','count','includeAll','rows','catch','filtears','length','include','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','html-pdf','eml-format','rimraf','request-promise','moment','bluebird','sox','to-csv','ejs','lodash','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset','limit','set','apply','reject','save','update','then','destroy','get','ChanSpies','UserProfileResource','error'];(function(_0x3b0731,_0xcf9925){var _0x4204d7=function(_0x635ac5){while(--_0x635ac5){_0x3b0731['push'](_0x3b0731['shift']());}};_0x4204d7(++_0xcf9925);}(_0x6f90,0x105));var _0x06f9=function(_0x1c430a,_0x14b71c){_0x1c430a=_0x1c430a-0x0;var _0x28e625=_0x6f90[_0x1c430a];return _0x28e625;};'use strict';var pdf=require(_0x06f9('0x0'));var emlformat=require(_0x06f9('0x1'));var rimraf=require(_0x06f9('0x2'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x06f9('0x3'));var moment=require(_0x06f9('0x4'));var BPromise=require(_0x06f9('0x5'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0x06f9('0x6'));var csv=require(_0x06f9('0x7'));var ejs=require(_0x06f9('0x8'));var fs=require('fs');var _=require(_0x06f9('0x9'));var squel=require('squel');var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x06f9('0x7'));var querystring=require(_0x06f9('0xa'));var Papa=require(_0x06f9('0xb'));var Redis=require('ioredis');var authService=require(_0x06f9('0xc'));var qs=require('../../components/parsers/qs');var as=require(_0x06f9('0xd'));var hardwareService=require(_0x06f9('0xe'));var logger=require('../../config/logger')('api');var utils=require(_0x06f9('0xf'));var config=require(_0x06f9('0x10'));var licenseUtil=require(_0x06f9('0x11'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x6d29f8,_0xc76fe5){_0xc76fe5=_0xc76fe5||0xcc;return function(_0x12e9e5){if(_0x12e9e5){return _0x6d29f8[_0x06f9('0x12')](_0xc76fe5);}return _0x6d29f8[_0x06f9('0x13')](_0xc76fe5)[_0x06f9('0x14')]();};}function respondWithResult(_0x311620,_0x16309f){_0x16309f=_0x16309f||0xc8;return function(_0x5508c5){if(_0x5508c5){return _0x311620[_0x06f9('0x13')](_0x16309f)[_0x06f9('0x15')](_0x5508c5);}};}function respondWithFilteredResult(_0x26684,_0x182242){return function(_0x2f0a4c){if(_0x2f0a4c){var _0x4ea03e=_0x2f0a4c['count'],_0x555250=_0x182242[_0x06f9('0x16')],_0x214965=_0x182242[_0x06f9('0x16')]+_0x182242[_0x06f9('0x17')],_0x35b468;if(_0x214965>=_0x4ea03e){_0x214965=_0x4ea03e;_0x35b468=0xc8;}else{_0x35b468=0xce;}_0x26684[_0x06f9('0x13')](_0x35b468);return _0x26684[_0x06f9('0x18')]('Content-Range',_0x555250+'-'+_0x214965+'/'+_0x4ea03e)['json'](_0x2f0a4c);}return null;};}function patchUpdates(_0x5f01ae){return function(_0x18c110){try{jsonpatch[_0x06f9('0x19')](_0x18c110,_0x5f01ae,!![]);}catch(_0x19d8cb){return BPromise[_0x06f9('0x1a')](_0x19d8cb);}return _0x18c110[_0x06f9('0x1b')]();};}function saveUpdates(_0x3d96f5,_0x2bff1d){return function(_0x520235){if(_0x520235){return _0x520235[_0x06f9('0x1c')](_0x3d96f5)[_0x06f9('0x1d')](function(_0x58dfaa){return _0x58dfaa;});}return null;};}function removeEntity(_0x3a4486,_0x2925bb){return function(_0xeb6535){if(_0xeb6535){return _0xeb6535[_0x06f9('0x1e')]()[_0x06f9('0x1d')](function(){var _0x59d74a=_0xeb6535[_0x06f9('0x1f')]({'plain':!![]});var _0x582e17=_0x06f9('0x20');return db[_0x06f9('0x21')][_0x06f9('0x1e')]({'where':{'type':_0x582e17,'resourceId':_0x59d74a['id']}})[_0x06f9('0x1d')](function(){return _0xeb6535;});})[_0x06f9('0x1d')](function(){_0x3a4486[_0x06f9('0x13')](0xcc)[_0x06f9('0x14')]();});}};}function handleEntityNotFound(_0x49f1bb,_0xad283b){return function(_0x2192e1){if(!_0x2192e1){_0x49f1bb[_0x06f9('0x12')](0x194);}return _0x2192e1;};}function handleError(_0x1ca61d,_0x34787c){_0x34787c=_0x34787c||0x1f4;return function(_0x718d30){logger[_0x06f9('0x22')](_0x718d30['stack']);if(_0x718d30[_0x06f9('0x23')]){delete _0x718d30[_0x06f9('0x23')];}_0x1ca61d[_0x06f9('0x13')](_0x34787c)[_0x06f9('0x24')](_0x718d30);};}exports[_0x06f9('0x25')]=function(_0x5b0f01,_0x21bb7a){var _0x22136e={},_0x15ff7b={},_0x6b04ac={'count':0x0,'rows':[]};var _0x114e23=_[_0x06f9('0x26')](db[_0x06f9('0x27')][_0x06f9('0x28')],function(_0x15f777){return{'name':_0x15f777['fieldName'],'type':_0x15f777[_0x06f9('0x29')][_0x06f9('0x2a')]};});_0x15ff7b[_0x06f9('0x2b')]=_[_0x06f9('0x26')](_0x114e23,_0x06f9('0x23'));_0x15ff7b['query']=_[_0x06f9('0x2c')](_0x5b0f01[_0x06f9('0x2d')]);_0x15ff7b[_0x06f9('0x2e')]=_[_0x06f9('0x2f')](_0x15ff7b['model'],_0x15ff7b[_0x06f9('0x2d')]);_0x22136e[_0x06f9('0x30')]=_[_0x06f9('0x2f')](_0x15ff7b[_0x06f9('0x2b')],qs[_0x06f9('0x31')](_0x5b0f01['query'][_0x06f9('0x31')]));_0x22136e[_0x06f9('0x30')]=_0x22136e['attributes']['length']?_0x22136e[_0x06f9('0x30')]:_0x15ff7b['model'];if(!_0x5b0f01['query']['hasOwnProperty'](_0x06f9('0x32'))){_0x22136e[_0x06f9('0x17')]=qs[_0x06f9('0x17')](_0x5b0f01['query']['limit']);_0x22136e[_0x06f9('0x16')]=qs[_0x06f9('0x16')](_0x5b0f01['query'][_0x06f9('0x16')]);}_0x22136e[_0x06f9('0x33')]=qs[_0x06f9('0x34')](_0x5b0f01['query'][_0x06f9('0x34')]);_0x22136e[_0x06f9('0x35')]=qs['filters'](_[_0x06f9('0x36')](_0x5b0f01[_0x06f9('0x2d')],_0x15ff7b[_0x06f9('0x2e')]),_0x114e23);if(_0x5b0f01[_0x06f9('0x2d')][_0x06f9('0x37')]){_0x22136e[_0x06f9('0x35')]=_[_0x06f9('0x38')](_0x22136e[_0x06f9('0x35')],{'$or':_[_0x06f9('0x26')](_0x114e23,function(_0x343aba){if(_0x343aba[_0x06f9('0x29')]!==_0x06f9('0x39')){var _0x4cab60={};_0x4cab60[_0x343aba[_0x06f9('0x23')]]={'$like':'%'+_0x5b0f01[_0x06f9('0x2d')]['filter']+'%'};return _0x4cab60;}})});}_0x22136e=_[_0x06f9('0x38')]({},_0x22136e,_0x5b0f01['options']);var _0xab7630={'where':_0x22136e[_0x06f9('0x35')]};return db[_0x06f9('0x27')][_0x06f9('0x3a')](_0xab7630)[_0x06f9('0x1d')](function(_0x56b057){_0x6b04ac[_0x06f9('0x3a')]=_0x56b057;if(_0x5b0f01[_0x06f9('0x2d')][_0x06f9('0x3b')]){_0x22136e['include']=[{'all':!![]}];}return db[_0x06f9('0x27')]['findAll'](_0x22136e);})['then'](function(_0x39f011){_0x6b04ac[_0x06f9('0x3c')]=_0x39f011;return _0x6b04ac;})['then'](respondWithFilteredResult(_0x21bb7a,_0x22136e))[_0x06f9('0x3d')](handleError(_0x21bb7a,null));};exports['show']=function(_0x26bc03,_0x45af9d){var _0x5ae39c={'raw':![],'where':{'id':_0x26bc03['params']['id']}},_0x5f3e73={};_0x5f3e73[_0x06f9('0x2b')]=_[_0x06f9('0x2c')](db[_0x06f9('0x27')][_0x06f9('0x28')]);_0x5f3e73[_0x06f9('0x2d')]=_[_0x06f9('0x2c')](_0x26bc03['query']);_0x5f3e73[_0x06f9('0x3e')]=_['intersection'](_0x5f3e73['model'],_0x5f3e73[_0x06f9('0x2d')]);_0x5ae39c['attributes']=_['intersection'](_0x5f3e73[_0x06f9('0x2b')],qs['fields'](_0x26bc03[_0x06f9('0x2d')][_0x06f9('0x31')]));_0x5ae39c[_0x06f9('0x30')]=_0x5ae39c[_0x06f9('0x30')][_0x06f9('0x3f')]?_0x5ae39c['attributes']:_0x5f3e73[_0x06f9('0x2b')];if(_0x26bc03['query']['includeAll']){_0x5ae39c[_0x06f9('0x40')]=[{'all':!![]}];}_0x5ae39c=_['merge']({},_0x5ae39c,_0x26bc03['options']);return db[_0x06f9('0x27')]['find'](_0x5ae39c)[_0x06f9('0x1d')](handleEntityNotFound(_0x45af9d,null))[_0x06f9('0x1d')](respondWithResult(_0x45af9d,null))[_0x06f9('0x3d')](handleError(_0x45af9d,null));};exports[_0x06f9('0x41')]=function(_0x279f44,_0x4f4e35){return db[_0x06f9('0x27')][_0x06f9('0x41')](_0x279f44[_0x06f9('0x42')],{})['then'](function(_0x4efdb3){var _0x57efc=_0x279f44[_0x06f9('0x43')]['get']({'plain':!![]});if(!_0x57efc)throw new Error(_0x06f9('0x44'));if(_0x57efc[_0x06f9('0x45')]==='user'){var _0x4639ea=_0x4efdb3['get']({'plain':!![]});var _0x292cf9=_0x06f9('0x20');return db[_0x06f9('0x46')]['find']({'where':{'name':_0x292cf9,'userProfileId':_0x57efc[_0x06f9('0x47')]},'raw':!![]})[_0x06f9('0x1d')](function(_0x6232ce){if(_0x6232ce&&_0x6232ce[_0x06f9('0x48')]===0x0){return db[_0x06f9('0x21')]['create']({'name':_0x4639ea['name'],'resourceId':_0x4639ea['id'],'type':_0x6232ce['name'],'sectionId':_0x6232ce['id']},{})[_0x06f9('0x1d')](function(){return _0x4efdb3;});}else{return _0x4efdb3;}})['catch'](function(_0x4009f7){logger[_0x06f9('0x22')](_0x06f9('0x49'),_0x4009f7);throw _0x4009f7;});}return _0x4efdb3;})[_0x06f9('0x1d')](respondWithResult(_0x4f4e35,0xc9))['catch'](handleError(_0x4f4e35,null));};exports[_0x06f9('0x1c')]=function(_0x3aba00,_0x340db1){if(_0x3aba00[_0x06f9('0x42')]['id']){delete _0x3aba00[_0x06f9('0x42')]['id'];}return db['VoiceChanSpy']['find']({'where':{'id':_0x3aba00['params']['id']}})['then'](handleEntityNotFound(_0x340db1,null))[_0x06f9('0x1d')](saveUpdates(_0x3aba00[_0x06f9('0x42')],null))[_0x06f9('0x1d')](respondWithResult(_0x340db1,null))['catch'](handleError(_0x340db1,null));};exports[_0x06f9('0x1e')]=function(_0x5967cf,_0x151ff6){return db['VoiceChanSpy']['find']({'where':{'id':_0x5967cf['params']['id']}})[_0x06f9('0x1d')](handleEntityNotFound(_0x151ff6,null))[_0x06f9('0x1d')](removeEntity(_0x151ff6,null))['catch'](handleError(_0x151ff6,null));};