Built motion from commit (unavailable).|2.5.23
[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 _0xf169=['includeAll','include','findAll','rows','catch','params','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','ChanSpies','autoAssociation','UserProfileResource','find','html-pdf','eml-format','request-promise','moment','sox','ejs','lodash','squel','jsforce','desk.js','to-csv','papaparse','ioredis','../../components/parsers/qs','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','count','offset','apply','reject','save','update','then','destroy','end','error','stack','send','index','VoiceChanSpy','rawAttributes','type','key','map','query','keys','filters','model','attributes','intersection','fields','length','hasOwnProperty','limit','order','sort','where','pick','filter','merge','VIRTUAL','name','options'];(function(_0x5aa87c,_0x499b32){var _0x3e67a8=function(_0x95004){while(--_0x95004){_0x5aa87c['push'](_0x5aa87c['shift']());}};_0x3e67a8(++_0x499b32);}(_0xf169,0x1d2));var _0x9f16=function(_0xc2c0ac,_0x5d9f93){_0xc2c0ac=_0xc2c0ac-0x0;var _0x32e848=_0xf169[_0xc2c0ac];return _0x32e848;};'use strict';var pdf=require(_0x9f16('0x0'));var emlformat=require(_0x9f16('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x9f16('0x2'));var moment=require(_0x9f16('0x3'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0x9f16('0x4'));var csv=require('to-csv');var ejs=require(_0x9f16('0x5'));var fs=require('fs');var _=require(_0x9f16('0x6'));var squel=require(_0x9f16('0x7'));var crypto=require('crypto');var jsforce=require(_0x9f16('0x8'));var deskjs=require(_0x9f16('0x9'));var toCsv=require(_0x9f16('0xa'));var querystring=require('querystring');var Papa=require(_0x9f16('0xb'));var Redis=require(_0x9f16('0xc'));var authService=require('../../components/auth/service');var qs=require(_0x9f16('0xd'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x9f16('0xe'));var utils=require(_0x9f16('0xf'));var config=require(_0x9f16('0x10'));var licenseUtil=require(_0x9f16('0x11'));var db=require(_0x9f16('0x12'))['db'];function respondWithStatusCode(_0x498ffa,_0x2b6ed1){_0x2b6ed1=_0x2b6ed1||0xcc;return function(_0x3647ae){if(_0x3647ae){return _0x498ffa[_0x9f16('0x13')](_0x2b6ed1);}return _0x498ffa[_0x9f16('0x14')](_0x2b6ed1)['end']();};}function respondWithResult(_0x55f9ee,_0xf36d79){_0xf36d79=_0xf36d79||0xc8;return function(_0x2ddada){if(_0x2ddada){return _0x55f9ee[_0x9f16('0x14')](_0xf36d79)[_0x9f16('0x15')](_0x2ddada);}};}function respondWithFilteredResult(_0x5a8f2f,_0xa6d761){return function(_0x57ea40){if(_0x57ea40){var _0x38e91f=_0x57ea40[_0x9f16('0x16')],_0xbea0ef=_0xa6d761[_0x9f16('0x17')],_0xb60602=_0xa6d761['offset']+_0xa6d761['limit'],_0xc72b4f;if(_0xb60602>=_0x38e91f){_0xb60602=_0x38e91f;_0xc72b4f=0xc8;}else{_0xc72b4f=0xce;}_0x5a8f2f[_0x9f16('0x14')](_0xc72b4f);return _0x5a8f2f['set']('Content-Range',_0xbea0ef+'-'+_0xb60602+'/'+_0x38e91f)[_0x9f16('0x15')](_0x57ea40);}return null;};}function patchUpdates(_0x1af36b){return function(_0x5488de){try{jsonpatch[_0x9f16('0x18')](_0x5488de,_0x1af36b,!![]);}catch(_0x3a0f6b){return BPromise[_0x9f16('0x19')](_0x3a0f6b);}return _0x5488de[_0x9f16('0x1a')]();};}function saveUpdates(_0x1853de,_0x3f69ac){return function(_0x541bf5){if(_0x541bf5){return _0x541bf5[_0x9f16('0x1b')](_0x1853de)[_0x9f16('0x1c')](function(_0x2c7a3c){return _0x2c7a3c;});}return null;};}function removeEntity(_0x2afa2e,_0x393893){return function(_0x39dac7){if(_0x39dac7){return _0x39dac7[_0x9f16('0x1d')]()[_0x9f16('0x1c')](function(){var _0x354ee4=_0x39dac7['get']({'plain':!![]});var _0x15fc66='ChanSpies';return db['UserProfileResource'][_0x9f16('0x1d')]({'where':{'type':_0x15fc66,'resourceId':_0x354ee4['id']}})['then'](function(){return _0x39dac7;});})[_0x9f16('0x1c')](function(){_0x2afa2e['status'](0xcc)[_0x9f16('0x1e')]();});}};}function handleEntityNotFound(_0x16cbdf,_0x2889f5){return function(_0x5a5daa){if(!_0x5a5daa){_0x16cbdf[_0x9f16('0x13')](0x194);}return _0x5a5daa;};}function handleError(_0x2c50cf,_0x3e111f){_0x3e111f=_0x3e111f||0x1f4;return function(_0x16d1d5){logger[_0x9f16('0x1f')](_0x16d1d5[_0x9f16('0x20')]);if(_0x16d1d5['name']){delete _0x16d1d5['name'];}_0x2c50cf[_0x9f16('0x14')](_0x3e111f)[_0x9f16('0x21')](_0x16d1d5);};}exports[_0x9f16('0x22')]=function(_0x2abd45,_0x167023){var _0x268f9e={},_0x56ad3b={},_0x290739={'count':0x0,'rows':[]};var _0x3e6929=_['map'](db[_0x9f16('0x23')][_0x9f16('0x24')],function(_0x217eed){return{'name':_0x217eed['fieldName'],'type':_0x217eed[_0x9f16('0x25')][_0x9f16('0x26')]};});_0x56ad3b['model']=_[_0x9f16('0x27')](_0x3e6929,'name');_0x56ad3b[_0x9f16('0x28')]=_[_0x9f16('0x29')](_0x2abd45['query']);_0x56ad3b[_0x9f16('0x2a')]=_['intersection'](_0x56ad3b[_0x9f16('0x2b')],_0x56ad3b[_0x9f16('0x28')]);_0x268f9e[_0x9f16('0x2c')]=_[_0x9f16('0x2d')](_0x56ad3b[_0x9f16('0x2b')],qs[_0x9f16('0x2e')](_0x2abd45[_0x9f16('0x28')][_0x9f16('0x2e')]));_0x268f9e[_0x9f16('0x2c')]=_0x268f9e[_0x9f16('0x2c')][_0x9f16('0x2f')]?_0x268f9e['attributes']:_0x56ad3b[_0x9f16('0x2b')];if(!_0x2abd45['query'][_0x9f16('0x30')]('nolimit')){_0x268f9e[_0x9f16('0x31')]=qs[_0x9f16('0x31')](_0x2abd45[_0x9f16('0x28')][_0x9f16('0x31')]);_0x268f9e[_0x9f16('0x17')]=qs[_0x9f16('0x17')](_0x2abd45[_0x9f16('0x28')][_0x9f16('0x17')]);}_0x268f9e[_0x9f16('0x32')]=qs[_0x9f16('0x33')](_0x2abd45[_0x9f16('0x28')][_0x9f16('0x33')]);_0x268f9e[_0x9f16('0x34')]=qs[_0x9f16('0x2a')](_[_0x9f16('0x35')](_0x2abd45['query'],_0x56ad3b['filters']),_0x3e6929);if(_0x2abd45['query'][_0x9f16('0x36')]){_0x268f9e[_0x9f16('0x34')]=_[_0x9f16('0x37')](_0x268f9e['where'],{'$or':_[_0x9f16('0x27')](_0x3e6929,function(_0x434528){if(_0x434528[_0x9f16('0x25')]!==_0x9f16('0x38')){var _0x175376={};_0x175376[_0x434528[_0x9f16('0x39')]]={'$like':'%'+_0x2abd45[_0x9f16('0x28')][_0x9f16('0x36')]+'%'};return _0x175376;}})});}_0x268f9e=_[_0x9f16('0x37')]({},_0x268f9e,_0x2abd45[_0x9f16('0x3a')]);var _0xcce2dc={'where':_0x268f9e[_0x9f16('0x34')]};return db[_0x9f16('0x23')][_0x9f16('0x16')](_0xcce2dc)[_0x9f16('0x1c')](function(_0x43161b){_0x290739['count']=_0x43161b;if(_0x2abd45[_0x9f16('0x28')][_0x9f16('0x3b')]){_0x268f9e[_0x9f16('0x3c')]=[{'all':!![]}];}return db[_0x9f16('0x23')][_0x9f16('0x3d')](_0x268f9e);})[_0x9f16('0x1c')](function(_0xd426c){_0x290739[_0x9f16('0x3e')]=_0xd426c;return _0x290739;})[_0x9f16('0x1c')](respondWithFilteredResult(_0x167023,_0x268f9e))[_0x9f16('0x3f')](handleError(_0x167023,null));};exports['show']=function(_0x3b5575,_0x9c42d3){var _0x5635dd={'raw':![],'where':{'id':_0x3b5575[_0x9f16('0x40')]['id']}},_0x11660a={};_0x11660a[_0x9f16('0x2b')]=_[_0x9f16('0x29')](db[_0x9f16('0x23')]['rawAttributes']);_0x11660a['query']=_[_0x9f16('0x29')](_0x3b5575['query']);_0x11660a['filters']=_[_0x9f16('0x2d')](_0x11660a[_0x9f16('0x2b')],_0x11660a[_0x9f16('0x28')]);_0x5635dd['attributes']=_[_0x9f16('0x2d')](_0x11660a[_0x9f16('0x2b')],qs['fields'](_0x3b5575['query'][_0x9f16('0x2e')]));_0x5635dd[_0x9f16('0x2c')]=_0x5635dd[_0x9f16('0x2c')][_0x9f16('0x2f')]?_0x5635dd['attributes']:_0x11660a[_0x9f16('0x2b')];if(_0x3b5575[_0x9f16('0x28')][_0x9f16('0x3b')]){_0x5635dd[_0x9f16('0x3c')]=[{'all':!![]}];}_0x5635dd=_['merge']({},_0x5635dd,_0x3b5575[_0x9f16('0x3a')]);return db[_0x9f16('0x23')]['find'](_0x5635dd)[_0x9f16('0x1c')](handleEntityNotFound(_0x9c42d3,null))[_0x9f16('0x1c')](respondWithResult(_0x9c42d3,null))[_0x9f16('0x3f')](handleError(_0x9c42d3,null));};exports[_0x9f16('0x41')]=function(_0x115259,_0x273625){return db[_0x9f16('0x23')][_0x9f16('0x41')](_0x115259[_0x9f16('0x42')],{})[_0x9f16('0x1c')](function(_0x4caff7){var _0x26737d=_0x115259[_0x9f16('0x43')][_0x9f16('0x44')]({'plain':!![]});if(!_0x26737d)throw new Error(_0x9f16('0x45'));if(_0x26737d[_0x9f16('0x46')]==='user'){var _0x210b43=_0x4caff7['get']({'plain':!![]});var _0x29a56b=_0x9f16('0x47');return db['UserProfileSection']['find']({'where':{'name':_0x29a56b,'userProfileId':_0x26737d['userProfileId']},'raw':!![]})[_0x9f16('0x1c')](function(_0x1fad65){if(_0x1fad65&&_0x1fad65[_0x9f16('0x48')]===0x0){return db[_0x9f16('0x49')][_0x9f16('0x41')]({'name':_0x210b43['name'],'resourceId':_0x210b43['id'],'type':_0x1fad65[_0x9f16('0x39')],'sectionId':_0x1fad65['id']},{})[_0x9f16('0x1c')](function(){return _0x4caff7;});}else{return _0x4caff7;}})[_0x9f16('0x3f')](function(_0x525e20){logger[_0x9f16('0x1f')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x525e20);throw _0x525e20;});}return _0x4caff7;})[_0x9f16('0x1c')](respondWithResult(_0x273625,0xc9))[_0x9f16('0x3f')](handleError(_0x273625,null));};exports[_0x9f16('0x1b')]=function(_0x1bee4d,_0x22ca4e){if(_0x1bee4d[_0x9f16('0x42')]['id']){delete _0x1bee4d['body']['id'];}return db[_0x9f16('0x23')]['find']({'where':{'id':_0x1bee4d[_0x9f16('0x40')]['id']}})[_0x9f16('0x1c')](handleEntityNotFound(_0x22ca4e,null))['then'](saveUpdates(_0x1bee4d[_0x9f16('0x42')],null))[_0x9f16('0x1c')](respondWithResult(_0x22ca4e,null))[_0x9f16('0x3f')](handleError(_0x22ca4e,null));};exports[_0x9f16('0x1d')]=function(_0x10b419,_0x542d3d){return db[_0x9f16('0x23')][_0x9f16('0x4a')]({'where':{'id':_0x10b419[_0x9f16('0x40')]['id']}})[_0x9f16('0x1c')](handleEntityNotFound(_0x542d3d,null))['then'](removeEntity(_0x542d3d,null))[_0x9f16('0x3f')](handleError(_0x542d3d,null));};