Built motion from commit a679711e.|2.6.15
[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 _0x9224=['request-promise','moment','bluebird','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','sendStatus','status','json','offset','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','get','UserProfileResource','stack','name','index','map','VoiceChanSpy','fieldName','type','key','query','filters','intersection','model','fields','attributes','hasOwnProperty','nolimit','order','sort','pick','filter','merge','where','includeAll','include','findAll','rows','show','params','keys','length','options','find','catch','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','ChanSpies','UserProfileSection','userProfileId','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','rimraf','zip-dir','fast-json-patch'];(function(_0x33032e,_0x31411a){var _0x13316b=function(_0x2fb049){while(--_0x2fb049){_0x33032e['push'](_0x33032e['shift']());}};_0x13316b(++_0x31411a);}(_0x9224,0xa3));var _0x4922=function(_0x465ca8,_0x58e1b1){_0x465ca8=_0x465ca8-0x0;var _0x31036b=_0x9224[_0x465ca8];return _0x31036b;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x4922('0x0'));var zipdir=require(_0x4922('0x1'));var jsonpatch=require(_0x4922('0x2'));var rp=require(_0x4922('0x3'));var moment=require(_0x4922('0x4'));var BPromise=require(_0x4922('0x5'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0x4922('0x6'));var csv=require('to-csv');var ejs=require(_0x4922('0x7'));var fs=require('fs');var fs_extra=require(_0x4922('0x8'));var _=require(_0x4922('0x9'));var squel=require(_0x4922('0xa'));var crypto=require(_0x4922('0xb'));var jsforce=require(_0x4922('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x4922('0xd'));var querystring=require(_0x4922('0xe'));var Papa=require('papaparse');var Redis=require(_0x4922('0xf'));var authService=require(_0x4922('0x10'));var qs=require(_0x4922('0x11'));var as=require(_0x4922('0x12'));var hardwareService=require(_0x4922('0x13'));var logger=require(_0x4922('0x14'))(_0x4922('0x15'));var utils=require(_0x4922('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0x4922('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x410502,_0x45de0c){_0x45de0c=_0x45de0c||0xcc;return function(_0x35ca3d){if(_0x35ca3d){return _0x410502[_0x4922('0x18')](_0x45de0c);}return _0x410502[_0x4922('0x19')](_0x45de0c)['end']();};}function respondWithResult(_0x103fa8,_0x704e23){_0x704e23=_0x704e23||0xc8;return function(_0x542410){if(_0x542410){return _0x103fa8[_0x4922('0x19')](_0x704e23)[_0x4922('0x1a')](_0x542410);}};}function respondWithFilteredResult(_0x15bf3a,_0x3010bb){return function(_0x434f62){if(_0x434f62){var _0x4385d2=typeof _0x3010bb[_0x4922('0x1b')]==='undefined'&&typeof _0x3010bb[_0x4922('0x1c')]==='undefined';var _0x15fe9e=_0x434f62[_0x4922('0x1d')];var _0x1d7fc2=_0x4385d2?0x0:_0x3010bb[_0x4922('0x1b')];var _0x2ef410=_0x4385d2?_0x434f62[_0x4922('0x1d')]:_0x3010bb['offset']+_0x3010bb[_0x4922('0x1c')];var _0x3abfbf;if(_0x2ef410>=_0x15fe9e){_0x2ef410=_0x15fe9e;_0x3abfbf=0xc8;}else{_0x3abfbf=0xce;}_0x15bf3a[_0x4922('0x19')](_0x3abfbf);return _0x15bf3a[_0x4922('0x1e')](_0x4922('0x1f'),_0x1d7fc2+'-'+_0x2ef410+'/'+_0x15fe9e)['json'](_0x434f62);}return null;};}function patchUpdates(_0x2b6a2d){return function(_0x20ef64){try{jsonpatch[_0x4922('0x20')](_0x20ef64,_0x2b6a2d,!![]);}catch(_0x183ec9){return BPromise[_0x4922('0x21')](_0x183ec9);}return _0x20ef64[_0x4922('0x22')]();};}function saveUpdates(_0x1c1243,_0x3b182b){return function(_0x5c766e){if(_0x5c766e){return _0x5c766e[_0x4922('0x23')](_0x1c1243)[_0x4922('0x24')](function(_0x4bd606){return _0x4bd606;});}return null;};}function removeEntity(_0x21859a,_0x23ce8d){return function(_0x4f93cb){if(_0x4f93cb){return _0x4f93cb[_0x4922('0x25')]()['then'](function(){var _0x3daefd=_0x4f93cb[_0x4922('0x26')]({'plain':!![]});var _0x26bb17='ChanSpies';return db[_0x4922('0x27')][_0x4922('0x25')]({'where':{'type':_0x26bb17,'resourceId':_0x3daefd['id']}})[_0x4922('0x24')](function(){return _0x4f93cb;});})['then'](function(){_0x21859a[_0x4922('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3f39d5,_0x28d3ba){return function(_0x41ef37){if(!_0x41ef37){_0x3f39d5[_0x4922('0x18')](0x194);}return _0x41ef37;};}function handleError(_0x30b538,_0x4a7934){_0x4a7934=_0x4a7934||0x1f4;return function(_0x46cd81){logger['error'](_0x46cd81[_0x4922('0x28')]);if(_0x46cd81[_0x4922('0x29')]){delete _0x46cd81['name'];}_0x30b538['status'](_0x4a7934)['send'](_0x46cd81);};}exports[_0x4922('0x2a')]=function(_0x575024,_0x5e7709){var _0x187c73={},_0x2db1c6={},_0x481ae3={'count':0x0,'rows':[]};var _0x2b132d=_[_0x4922('0x2b')](db[_0x4922('0x2c')]['rawAttributes'],function(_0x49c88e){return{'name':_0x49c88e[_0x4922('0x2d')],'type':_0x49c88e[_0x4922('0x2e')][_0x4922('0x2f')]};});_0x2db1c6['model']=_[_0x4922('0x2b')](_0x2b132d,_0x4922('0x29'));_0x2db1c6[_0x4922('0x30')]=_['keys'](_0x575024['query']);_0x2db1c6[_0x4922('0x31')]=_[_0x4922('0x32')](_0x2db1c6['model'],_0x2db1c6[_0x4922('0x30')]);_0x187c73['attributes']=_[_0x4922('0x32')](_0x2db1c6[_0x4922('0x33')],qs[_0x4922('0x34')](_0x575024[_0x4922('0x30')][_0x4922('0x34')]));_0x187c73[_0x4922('0x35')]=_0x187c73[_0x4922('0x35')]['length']?_0x187c73[_0x4922('0x35')]:_0x2db1c6[_0x4922('0x33')];if(!_0x575024[_0x4922('0x30')][_0x4922('0x36')](_0x4922('0x37'))){_0x187c73[_0x4922('0x1c')]=qs[_0x4922('0x1c')](_0x575024[_0x4922('0x30')][_0x4922('0x1c')]);_0x187c73[_0x4922('0x1b')]=qs['offset'](_0x575024['query'][_0x4922('0x1b')]);}_0x187c73[_0x4922('0x38')]=qs[_0x4922('0x39')](_0x575024[_0x4922('0x30')][_0x4922('0x39')]);_0x187c73['where']=qs['filters'](_[_0x4922('0x3a')](_0x575024[_0x4922('0x30')],_0x2db1c6[_0x4922('0x31')]),_0x2b132d);if(_0x575024[_0x4922('0x30')][_0x4922('0x3b')]){_0x187c73['where']=_[_0x4922('0x3c')](_0x187c73[_0x4922('0x3d')],{'$or':_[_0x4922('0x2b')](_0x2b132d,function(_0x33f84f){if(_0x33f84f[_0x4922('0x2e')]!=='VIRTUAL'){var _0x5a4ec6={};_0x5a4ec6[_0x33f84f[_0x4922('0x29')]]={'$like':'%'+_0x575024[_0x4922('0x30')]['filter']+'%'};return _0x5a4ec6;}})});}_0x187c73=_[_0x4922('0x3c')]({},_0x187c73,_0x575024['options']);var _0x1f81cc={'where':_0x187c73[_0x4922('0x3d')]};return db[_0x4922('0x2c')][_0x4922('0x1d')](_0x1f81cc)[_0x4922('0x24')](function(_0x499b26){_0x481ae3['count']=_0x499b26;if(_0x575024[_0x4922('0x30')][_0x4922('0x3e')]){_0x187c73[_0x4922('0x3f')]=[{'all':!![]}];}return db[_0x4922('0x2c')][_0x4922('0x40')](_0x187c73);})[_0x4922('0x24')](function(_0xa2fec8){_0x481ae3[_0x4922('0x41')]=_0xa2fec8;return _0x481ae3;})[_0x4922('0x24')](respondWithFilteredResult(_0x5e7709,_0x187c73))['catch'](handleError(_0x5e7709,null));};exports[_0x4922('0x42')]=function(_0xc7bd23,_0x114bb8){var _0x1a4c06={'raw':![],'where':{'id':_0xc7bd23[_0x4922('0x43')]['id']}},_0x58bc02={};_0x58bc02[_0x4922('0x33')]=_[_0x4922('0x44')](db[_0x4922('0x2c')]['rawAttributes']);_0x58bc02['query']=_[_0x4922('0x44')](_0xc7bd23[_0x4922('0x30')]);_0x58bc02[_0x4922('0x31')]=_['intersection'](_0x58bc02['model'],_0x58bc02[_0x4922('0x30')]);_0x1a4c06[_0x4922('0x35')]=_[_0x4922('0x32')](_0x58bc02[_0x4922('0x33')],qs[_0x4922('0x34')](_0xc7bd23[_0x4922('0x30')][_0x4922('0x34')]));_0x1a4c06[_0x4922('0x35')]=_0x1a4c06['attributes'][_0x4922('0x45')]?_0x1a4c06[_0x4922('0x35')]:_0x58bc02[_0x4922('0x33')];if(_0xc7bd23[_0x4922('0x30')][_0x4922('0x3e')]){_0x1a4c06[_0x4922('0x3f')]=[{'all':!![]}];}_0x1a4c06=_[_0x4922('0x3c')]({},_0x1a4c06,_0xc7bd23[_0x4922('0x46')]);return db[_0x4922('0x2c')][_0x4922('0x47')](_0x1a4c06)[_0x4922('0x24')](handleEntityNotFound(_0x114bb8,null))[_0x4922('0x24')](respondWithResult(_0x114bb8,null))[_0x4922('0x48')](handleError(_0x114bb8,null));};exports[_0x4922('0x49')]=function(_0x4c7c02,_0x58fadf){return db[_0x4922('0x2c')]['create'](_0x4c7c02[_0x4922('0x4a')],{})[_0x4922('0x24')](function(_0x2fd67b){var _0x4f1054=_0x4c7c02['user'][_0x4922('0x26')]({'plain':!![]});if(!_0x4f1054)throw new Error(_0x4922('0x4b'));if(_0x4f1054['role']===_0x4922('0x4c')){var _0x121b03=_0x2fd67b['get']({'plain':!![]});var _0x3a7330=_0x4922('0x4d');return db[_0x4922('0x4e')][_0x4922('0x47')]({'where':{'name':_0x3a7330,'userProfileId':_0x4f1054[_0x4922('0x4f')]},'raw':!![]})[_0x4922('0x24')](function(_0x1951eb){if(_0x1951eb&&_0x1951eb[_0x4922('0x50')]===0x0){return db[_0x4922('0x27')][_0x4922('0x49')]({'name':_0x121b03[_0x4922('0x29')],'resourceId':_0x121b03['id'],'type':_0x1951eb['name'],'sectionId':_0x1951eb['id']},{})[_0x4922('0x24')](function(){return _0x2fd67b;});}else{return _0x2fd67b;}})[_0x4922('0x48')](function(_0x15f169){logger[_0x4922('0x51')](_0x4922('0x52'),_0x15f169);throw _0x15f169;});}return _0x2fd67b;})[_0x4922('0x24')](respondWithResult(_0x58fadf,0xc9))[_0x4922('0x48')](handleError(_0x58fadf,null));};exports[_0x4922('0x23')]=function(_0x16daad,_0xb45a07){if(_0x16daad['body']['id']){delete _0x16daad['body']['id'];}return db[_0x4922('0x2c')][_0x4922('0x47')]({'where':{'id':_0x16daad['params']['id']}})[_0x4922('0x24')](handleEntityNotFound(_0xb45a07,null))[_0x4922('0x24')](saveUpdates(_0x16daad[_0x4922('0x4a')],null))[_0x4922('0x24')](respondWithResult(_0xb45a07,null))[_0x4922('0x48')](handleError(_0xb45a07,null));};exports[_0x4922('0x25')]=function(_0xbcc817,_0x2c0f35){return db[_0x4922('0x2c')][_0x4922('0x47')]({'where':{'id':_0xbcc817[_0x4922('0x43')]['id']}})[_0x4922('0x24')](handleEntityNotFound(_0x2c0f35,null))['then'](removeEntity(_0x2c0f35,null))[_0x4922('0x48')](handleError(_0x2c0f35,null));};