Built motion from commit (unavailable).|2.4.1
[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 _0xf585=['squel','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','status','count','limit','set','Content-Range','json','apply','reject','update','then','destroy','get','UserProfileResource','end','sendStatus','error','stack','name','send','VoiceChanSpy','model','keys','query','filters','intersection','attributes','length','hasOwnProperty','nolimit','offset','order','sort','pick','where','merge','map','key','VIRTUAL','filter','includeAll','include','findAll','rows','catch','show','params','rawAttributes','fields','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','ChanSpies','UserProfileSection','userProfileId','autoAssociation','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','to-csv','ejs','lodash'];(function(_0x2f479d,_0x1d6836){var _0x300d48=function(_0x338a74){while(--_0x338a74){_0x2f479d['push'](_0x2f479d['shift']());}};_0x300d48(++_0x1d6836);}(_0xf585,0x1df));var _0x5f58=function(_0x565c49,_0x54acd0){_0x565c49=_0x565c49-0x0;var _0x20ca34=_0xf585[_0x565c49];return _0x20ca34;};'use strict';var pdf=require(_0x5f58('0x0'));var emlformat=require(_0x5f58('0x1'));var rimraf=require(_0x5f58('0x2'));var zipdir=require(_0x5f58('0x3'));var jsonpatch=require(_0x5f58('0x4'));var rp=require('request-promise');var moment=require(_0x5f58('0x5'));var BPromise=require(_0x5f58('0x6'));var Mustache=require(_0x5f58('0x7'));var util=require(_0x5f58('0x8'));var path=require(_0x5f58('0x9'));var sox=require('sox');var csv=require(_0x5f58('0xa'));var ejs=require(_0x5f58('0xb'));var fs=require('fs');var _=require(_0x5f58('0xc'));var squel=require(_0x5f58('0xd'));var crypto=require(_0x5f58('0xe'));var jsforce=require(_0x5f58('0xf'));var deskjs=require(_0x5f58('0x10'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x5f58('0x11'));var authService=require(_0x5f58('0x12'));var qs=require(_0x5f58('0x13'));var hardwareService=require(_0x5f58('0x14'));var logger=require(_0x5f58('0x15'))('api');var utils=require(_0x5f58('0x16'));var config=require(_0x5f58('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x23fa34,_0x3ece29){_0x3ece29=_0x3ece29||0xcc;return function(_0x36f1a5){if(_0x36f1a5){return _0x23fa34['sendStatus'](_0x3ece29);}return _0x23fa34[_0x5f58('0x18')](_0x3ece29)['end']();};}function respondWithResult(_0x439f0b,_0x4cb469){_0x4cb469=_0x4cb469||0xc8;return function(_0x58744a){if(_0x58744a){return _0x439f0b[_0x5f58('0x18')](_0x4cb469)['json'](_0x58744a);}};}function respondWithFilteredResult(_0x211180,_0xa9d300){return function(_0x2c29a2){if(_0x2c29a2){var _0x2e3bc3=_0x2c29a2[_0x5f58('0x19')],_0x24fb64=_0xa9d300['offset'],_0x5a5069=_0xa9d300['offset']+_0xa9d300[_0x5f58('0x1a')],_0x167259;if(_0x5a5069>=_0x2e3bc3){_0x5a5069=_0x2e3bc3;_0x167259=0xc8;}else{_0x167259=0xce;}_0x211180[_0x5f58('0x18')](_0x167259);return _0x211180[_0x5f58('0x1b')](_0x5f58('0x1c'),_0x24fb64+'-'+_0x5a5069+'/'+_0x2e3bc3)[_0x5f58('0x1d')](_0x2c29a2);}return null;};}function patchUpdates(_0x54e082){return function(_0x25c06b){try{jsonpatch[_0x5f58('0x1e')](_0x25c06b,_0x54e082,!![]);}catch(_0x1696cf){return BPromise[_0x5f58('0x1f')](_0x1696cf);}return _0x25c06b['save']();};}function saveUpdates(_0x51e7b8,_0x15a042){return function(_0x112957){if(_0x112957){return _0x112957[_0x5f58('0x20')](_0x51e7b8)[_0x5f58('0x21')](function(_0x247c6b){return _0x247c6b;});}return null;};}function removeEntity(_0x57a391,_0x5482a4){return function(_0x5c9c6f){if(_0x5c9c6f){return _0x5c9c6f[_0x5f58('0x22')]()[_0x5f58('0x21')](function(){var _0x3f116e=_0x5c9c6f[_0x5f58('0x23')]({'plain':!![]});var _0x2e6cf7='ChanSpies';return db[_0x5f58('0x24')][_0x5f58('0x22')]({'where':{'type':_0x2e6cf7,'resourceId':_0x3f116e['id']}})[_0x5f58('0x21')](function(){return _0x5c9c6f;});})[_0x5f58('0x21')](function(){_0x57a391[_0x5f58('0x18')](0xcc)[_0x5f58('0x25')]();});}};}function handleEntityNotFound(_0x1babbe,_0x8bc92c){return function(_0xd7c0f8){if(!_0xd7c0f8){_0x1babbe[_0x5f58('0x26')](0x194);}return _0xd7c0f8;};}function handleError(_0x10fe67,_0x4efe34){_0x4efe34=_0x4efe34||0x1f4;return function(_0x26bb71){logger[_0x5f58('0x27')](_0x26bb71[_0x5f58('0x28')]);if(_0x26bb71[_0x5f58('0x29')]){delete _0x26bb71[_0x5f58('0x29')];}_0x10fe67[_0x5f58('0x18')](_0x4efe34)[_0x5f58('0x2a')](_0x26bb71);};}exports['index']=function(_0x3684ad,_0x3c314f){var _0x226f2f={},_0x3088ca={},_0x3b80cd={'count':0x0,'rows':[]};var _0x15c2df=db[_0x5f58('0x2b')]['rawAttributes'];_0x3088ca[_0x5f58('0x2c')]=_[_0x5f58('0x2d')](_0x15c2df);_0x3088ca['query']=_[_0x5f58('0x2d')](_0x3684ad[_0x5f58('0x2e')]);_0x3088ca[_0x5f58('0x2f')]=_[_0x5f58('0x30')](_0x3088ca[_0x5f58('0x2c')],_0x3088ca[_0x5f58('0x2e')]);_0x226f2f[_0x5f58('0x31')]=_[_0x5f58('0x30')](_0x3088ca[_0x5f58('0x2c')],qs['fields'](_0x3684ad[_0x5f58('0x2e')]['fields']));_0x226f2f[_0x5f58('0x31')]=_0x226f2f[_0x5f58('0x31')][_0x5f58('0x32')]?_0x226f2f[_0x5f58('0x31')]:_0x3088ca[_0x5f58('0x2c')];if(!_0x3684ad[_0x5f58('0x2e')][_0x5f58('0x33')](_0x5f58('0x34'))){_0x226f2f['limit']=qs['limit'](_0x3684ad[_0x5f58('0x2e')][_0x5f58('0x1a')]);_0x226f2f[_0x5f58('0x35')]=qs['offset'](_0x3684ad[_0x5f58('0x2e')][_0x5f58('0x35')]);}_0x226f2f[_0x5f58('0x36')]=qs[_0x5f58('0x37')](_0x3684ad[_0x5f58('0x2e')]['sort']);_0x226f2f['where']=qs[_0x5f58('0x2f')](_[_0x5f58('0x38')](_0x3684ad['query'],_0x3088ca[_0x5f58('0x2f')]));if(_0x3684ad[_0x5f58('0x2e')]['filter']){_0x226f2f[_0x5f58('0x39')]=_[_0x5f58('0x3a')](_0x226f2f[_0x5f58('0x39')],{'$or':_[_0x5f58('0x3b')](_0x15c2df,function(_0x55a799){if(_0x55a799['type'][_0x5f58('0x3c')]!==_0x5f58('0x3d')){var _0x3cb07e={};_0x3cb07e[_0x55a799['field']]={'$like':'%'+_0x3684ad['query'][_0x5f58('0x3e')]+'%'};return _0x3cb07e;}})});}_0x226f2f=_['merge']({},_0x226f2f,_0x3684ad['options']);var _0x3a53d8={'where':_0x226f2f['where']};return db[_0x5f58('0x2b')][_0x5f58('0x19')](_0x3a53d8)[_0x5f58('0x21')](function(_0x2e7cf5){_0x3b80cd['count']=_0x2e7cf5;if(_0x3684ad[_0x5f58('0x2e')][_0x5f58('0x3f')]){_0x226f2f[_0x5f58('0x40')]=[{'all':!![]}];}return db[_0x5f58('0x2b')][_0x5f58('0x41')](_0x226f2f);})[_0x5f58('0x21')](function(_0x347110){_0x3b80cd[_0x5f58('0x42')]=_0x347110;return _0x3b80cd;})[_0x5f58('0x21')](respondWithFilteredResult(_0x3c314f,_0x226f2f))[_0x5f58('0x43')](handleError(_0x3c314f,null));};exports[_0x5f58('0x44')]=function(_0x134378,_0x129c0d){var _0x52549c={'raw':![],'where':{'id':_0x134378[_0x5f58('0x45')]['id']}},_0x498d95={};_0x498d95[_0x5f58('0x2c')]=_[_0x5f58('0x2d')](db[_0x5f58('0x2b')][_0x5f58('0x46')]);_0x498d95[_0x5f58('0x2e')]=_[_0x5f58('0x2d')](_0x134378[_0x5f58('0x2e')]);_0x498d95[_0x5f58('0x2f')]=_[_0x5f58('0x30')](_0x498d95['model'],_0x498d95[_0x5f58('0x2e')]);_0x52549c[_0x5f58('0x31')]=_[_0x5f58('0x30')](_0x498d95[_0x5f58('0x2c')],qs[_0x5f58('0x47')](_0x134378[_0x5f58('0x2e')][_0x5f58('0x47')]));_0x52549c['attributes']=_0x52549c['attributes'][_0x5f58('0x32')]?_0x52549c['attributes']:_0x498d95[_0x5f58('0x2c')];if(_0x134378['query'][_0x5f58('0x3f')]){_0x52549c['include']=[{'all':!![]}];}_0x52549c=_[_0x5f58('0x3a')]({},_0x52549c,_0x134378['options']);return db[_0x5f58('0x2b')][_0x5f58('0x48')](_0x52549c)['then'](handleEntityNotFound(_0x129c0d,null))[_0x5f58('0x21')](respondWithResult(_0x129c0d,null))['catch'](handleError(_0x129c0d,null));};exports[_0x5f58('0x49')]=function(_0x576798,_0x1774da){return db['VoiceChanSpy'][_0x5f58('0x49')](_0x576798[_0x5f58('0x4a')],{})[_0x5f58('0x21')](function(_0x1f700f){var _0x372e21=_0x576798['user']['get']({'plain':!![]});if(!_0x372e21)throw new Error(_0x5f58('0x4b'));if(_0x372e21[_0x5f58('0x4c')]===_0x5f58('0x4d')){var _0x5ce809=_0x1f700f[_0x5f58('0x23')]({'plain':!![]});var _0xb2bc09=_0x5f58('0x4e');return db[_0x5f58('0x4f')][_0x5f58('0x48')]({'where':{'name':_0xb2bc09,'userProfileId':_0x372e21[_0x5f58('0x50')]},'raw':!![]})[_0x5f58('0x21')](function(_0x37804e){if(_0x37804e&&_0x37804e[_0x5f58('0x51')]===0x0){return db['UserProfileResource'][_0x5f58('0x49')]({'name':_0x5ce809[_0x5f58('0x29')],'resourceId':_0x5ce809['id'],'type':_0x37804e[_0x5f58('0x29')],'sectionId':_0x37804e['id']},{})[_0x5f58('0x21')](function(){return _0x1f700f;});}else{return _0x1f700f;}})['catch'](function(_0x5f0618){logger[_0x5f58('0x27')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x5f0618);throw _0x5f0618;});}return _0x1f700f;})[_0x5f58('0x21')](respondWithResult(_0x1774da,0xc9))['catch'](handleError(_0x1774da,null));};exports[_0x5f58('0x20')]=function(_0x379078,_0x3e1f17){if(_0x379078[_0x5f58('0x4a')]['id']){delete _0x379078[_0x5f58('0x4a')]['id'];}return db[_0x5f58('0x2b')][_0x5f58('0x48')]({'where':{'id':_0x379078['params']['id']}})[_0x5f58('0x21')](handleEntityNotFound(_0x3e1f17,null))[_0x5f58('0x21')](saveUpdates(_0x379078['body'],null))[_0x5f58('0x21')](respondWithResult(_0x3e1f17,null))[_0x5f58('0x43')](handleError(_0x3e1f17,null));};exports['destroy']=function(_0x2577cc,_0x32d1b0){return db[_0x5f58('0x2b')]['find']({'where':{'id':_0x2577cc[_0x5f58('0x45')]['id']}})['then'](handleEntityNotFound(_0x32d1b0,null))[_0x5f58('0x21')](removeEntity(_0x32d1b0,null))[_0x5f58('0x43')](handleError(_0x32d1b0,null));};