Built motion from commit a8c4dd89.|2.6.33
[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 _0xbf6e=['moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','get','ChanSpies','error','stack','name','send','map','VoiceChanSpy','rawAttributes','fieldName','type','keys','query','intersection','model','fields','attributes','length','nolimit','sort','where','filters','pick','filter','merge','VIRTUAL','includeAll','include','findAll','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','catch','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','zip-dir','fast-json-patch','request-promise'];(function(_0x46e363,_0x45d7e2){var _0x3fb059=function(_0x5e6274){while(--_0x5e6274){_0x46e363['push'](_0x46e363['shift']());}};_0x3fb059(++_0x45d7e2);}(_0xbf6e,0x149));var _0xebf6=function(_0x4be7a0,_0xfb3d5b){_0x4be7a0=_0x4be7a0-0x0;var _0x55482b=_0xbf6e[_0x4be7a0];return _0x55482b;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xebf6('0x0'));var jsonpatch=require(_0xebf6('0x1'));var rp=require(_0xebf6('0x2'));var moment=require(_0xebf6('0x3'));var BPromise=require(_0xebf6('0x4'));var Mustache=require(_0xebf6('0x5'));var util=require(_0xebf6('0x6'));var path=require('path');var sox=require(_0xebf6('0x7'));var csv=require(_0xebf6('0x8'));var ejs=require(_0xebf6('0x9'));var fs=require('fs');var fs_extra=require(_0xebf6('0xa'));var _=require(_0xebf6('0xb'));var squel=require(_0xebf6('0xc'));var crypto=require(_0xebf6('0xd'));var jsforce=require('jsforce');var deskjs=require(_0xebf6('0xe'));var toCsv=require(_0xebf6('0x8'));var querystring=require(_0xebf6('0xf'));var Papa=require('papaparse');var Redis=require(_0xebf6('0x10'));var authService=require(_0xebf6('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xebf6('0x12'));var hardwareService=require(_0xebf6('0x13'));var logger=require(_0xebf6('0x14'))(_0xebf6('0x15'));var utils=require(_0xebf6('0x16'));var config=require(_0xebf6('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0xebf6('0x18'))['db'];function respondWithStatusCode(_0xedc361,_0x4919f1){_0x4919f1=_0x4919f1||0xcc;return function(_0x332ca0){if(_0x332ca0){return _0xedc361[_0xebf6('0x19')](_0x4919f1);}return _0xedc361[_0xebf6('0x1a')](_0x4919f1)[_0xebf6('0x1b')]();};}function respondWithResult(_0x3f69e6,_0x4dbf51){_0x4dbf51=_0x4dbf51||0xc8;return function(_0x4c01f4){if(_0x4c01f4){return _0x3f69e6['status'](_0x4dbf51)[_0xebf6('0x1c')](_0x4c01f4);}};}function respondWithFilteredResult(_0x1ae2f7,_0x50d80f){return function(_0x35570e){if(_0x35570e){var _0x2c980f=typeof _0x50d80f[_0xebf6('0x1d')]===_0xebf6('0x1e')&&typeof _0x50d80f[_0xebf6('0x1f')]===_0xebf6('0x1e');var _0x219621=_0x35570e[_0xebf6('0x20')];var _0x2d3984=_0x2c980f?0x0:_0x50d80f[_0xebf6('0x1d')];var _0x55fa31=_0x2c980f?_0x35570e['count']:_0x50d80f[_0xebf6('0x1d')]+_0x50d80f[_0xebf6('0x1f')];var _0x10051e;if(_0x55fa31>=_0x219621){_0x55fa31=_0x219621;_0x10051e=0xc8;}else{_0x10051e=0xce;}_0x1ae2f7[_0xebf6('0x1a')](_0x10051e);return _0x1ae2f7[_0xebf6('0x21')](_0xebf6('0x22'),_0x2d3984+'-'+_0x55fa31+'/'+_0x219621)[_0xebf6('0x1c')](_0x35570e);}return null;};}function patchUpdates(_0x80f523){return function(_0x4fb497){try{jsonpatch[_0xebf6('0x23')](_0x4fb497,_0x80f523,!![]);}catch(_0x81fdb3){return BPromise[_0xebf6('0x24')](_0x81fdb3);}return _0x4fb497[_0xebf6('0x25')]();};}function saveUpdates(_0x6303ac,_0x14c8ac){return function(_0x2f419e){if(_0x2f419e){return _0x2f419e[_0xebf6('0x26')](_0x6303ac)[_0xebf6('0x27')](function(_0x2e32c6){return _0x2e32c6;});}return null;};}function removeEntity(_0x232074,_0x2dd2ed){return function(_0x43c4e2){if(_0x43c4e2){return _0x43c4e2[_0xebf6('0x28')]()[_0xebf6('0x27')](function(){var _0x1d0078=_0x43c4e2[_0xebf6('0x29')]({'plain':!![]});var _0x1534b2=_0xebf6('0x2a');return db['UserProfileResource']['destroy']({'where':{'type':_0x1534b2,'resourceId':_0x1d0078['id']}})[_0xebf6('0x27')](function(){return _0x43c4e2;});})['then'](function(){_0x232074[_0xebf6('0x1a')](0xcc)[_0xebf6('0x1b')]();});}};}function handleEntityNotFound(_0x5a01ea,_0x4f39eb){return function(_0x37950c){if(!_0x37950c){_0x5a01ea[_0xebf6('0x19')](0x194);}return _0x37950c;};}function handleError(_0x3c3d5c,_0x7959c8){_0x7959c8=_0x7959c8||0x1f4;return function(_0xedaaeb){logger[_0xebf6('0x2b')](_0xedaaeb[_0xebf6('0x2c')]);if(_0xedaaeb[_0xebf6('0x2d')]){delete _0xedaaeb['name'];}_0x3c3d5c[_0xebf6('0x1a')](_0x7959c8)[_0xebf6('0x2e')](_0xedaaeb);};}exports['index']=function(_0x2fe3ee,_0x28bbea){var _0x5ea6b2={},_0x2901fc={},_0x1fa407={'count':0x0,'rows':[]};var _0x32afa3=_[_0xebf6('0x2f')](db[_0xebf6('0x30')][_0xebf6('0x31')],function(_0x4907d0){return{'name':_0x4907d0[_0xebf6('0x32')],'type':_0x4907d0[_0xebf6('0x33')]['key']};});_0x2901fc['model']=_[_0xebf6('0x2f')](_0x32afa3,_0xebf6('0x2d'));_0x2901fc['query']=_[_0xebf6('0x34')](_0x2fe3ee[_0xebf6('0x35')]);_0x2901fc['filters']=_[_0xebf6('0x36')](_0x2901fc[_0xebf6('0x37')],_0x2901fc[_0xebf6('0x35')]);_0x5ea6b2['attributes']=_[_0xebf6('0x36')](_0x2901fc[_0xebf6('0x37')],qs[_0xebf6('0x38')](_0x2fe3ee[_0xebf6('0x35')]['fields']));_0x5ea6b2['attributes']=_0x5ea6b2[_0xebf6('0x39')][_0xebf6('0x3a')]?_0x5ea6b2['attributes']:_0x2901fc[_0xebf6('0x37')];if(!_0x2fe3ee[_0xebf6('0x35')]['hasOwnProperty'](_0xebf6('0x3b'))){_0x5ea6b2[_0xebf6('0x1f')]=qs[_0xebf6('0x1f')](_0x2fe3ee[_0xebf6('0x35')][_0xebf6('0x1f')]);_0x5ea6b2['offset']=qs[_0xebf6('0x1d')](_0x2fe3ee['query'][_0xebf6('0x1d')]);}_0x5ea6b2['order']=qs[_0xebf6('0x3c')](_0x2fe3ee[_0xebf6('0x35')][_0xebf6('0x3c')]);_0x5ea6b2[_0xebf6('0x3d')]=qs[_0xebf6('0x3e')](_[_0xebf6('0x3f')](_0x2fe3ee['query'],_0x2901fc[_0xebf6('0x3e')]),_0x32afa3);if(_0x2fe3ee[_0xebf6('0x35')][_0xebf6('0x40')]){_0x5ea6b2[_0xebf6('0x3d')]=_[_0xebf6('0x41')](_0x5ea6b2[_0xebf6('0x3d')],{'$or':_['map'](_0x32afa3,function(_0xcbe240){if(_0xcbe240[_0xebf6('0x33')]!==_0xebf6('0x42')){var _0x111ff7={};_0x111ff7[_0xcbe240[_0xebf6('0x2d')]]={'$like':'%'+_0x2fe3ee[_0xebf6('0x35')]['filter']+'%'};return _0x111ff7;}})});}_0x5ea6b2=_['merge']({},_0x5ea6b2,_0x2fe3ee['options']);var _0xd4d5f4={'where':_0x5ea6b2[_0xebf6('0x3d')]};return db[_0xebf6('0x30')]['count'](_0xd4d5f4)[_0xebf6('0x27')](function(_0x1c3809){_0x1fa407[_0xebf6('0x20')]=_0x1c3809;if(_0x2fe3ee['query'][_0xebf6('0x43')]){_0x5ea6b2[_0xebf6('0x44')]=[{'all':!![]}];}return db['VoiceChanSpy'][_0xebf6('0x45')](_0x5ea6b2);})[_0xebf6('0x27')](function(_0x17c4af){_0x1fa407['rows']=_0x17c4af;return _0x1fa407;})[_0xebf6('0x27')](respondWithFilteredResult(_0x28bbea,_0x5ea6b2))['catch'](handleError(_0x28bbea,null));};exports['show']=function(_0x256552,_0x470f62){var _0x10ca29={'raw':![],'where':{'id':_0x256552['params']['id']}},_0x2ac140={};_0x2ac140[_0xebf6('0x37')]=_['keys'](db[_0xebf6('0x30')][_0xebf6('0x31')]);_0x2ac140[_0xebf6('0x35')]=_[_0xebf6('0x34')](_0x256552[_0xebf6('0x35')]);_0x2ac140['filters']=_['intersection'](_0x2ac140[_0xebf6('0x37')],_0x2ac140[_0xebf6('0x35')]);_0x10ca29[_0xebf6('0x39')]=_[_0xebf6('0x36')](_0x2ac140['model'],qs[_0xebf6('0x38')](_0x256552[_0xebf6('0x35')][_0xebf6('0x38')]));_0x10ca29[_0xebf6('0x39')]=_0x10ca29[_0xebf6('0x39')][_0xebf6('0x3a')]?_0x10ca29[_0xebf6('0x39')]:_0x2ac140['model'];if(_0x256552[_0xebf6('0x35')][_0xebf6('0x43')]){_0x10ca29[_0xebf6('0x44')]=[{'all':!![]}];}_0x10ca29=_[_0xebf6('0x41')]({},_0x10ca29,_0x256552[_0xebf6('0x46')]);return db[_0xebf6('0x30')][_0xebf6('0x47')](_0x10ca29)['then'](handleEntityNotFound(_0x470f62,null))[_0xebf6('0x27')](respondWithResult(_0x470f62,null))['catch'](handleError(_0x470f62,null));};exports[_0xebf6('0x48')]=function(_0x31d8ba,_0x5d84ac){return db[_0xebf6('0x30')]['create'](_0x31d8ba[_0xebf6('0x49')],{})[_0xebf6('0x27')](function(_0x186655){var _0x32c8b1=_0x31d8ba[_0xebf6('0x4a')]['get']({'plain':!![]});if(!_0x32c8b1)throw new Error(_0xebf6('0x4b'));if(_0x32c8b1[_0xebf6('0x4c')]==='user'){var _0x1f98fd=_0x186655[_0xebf6('0x29')]({'plain':!![]});var _0x1455c4=_0xebf6('0x2a');return db[_0xebf6('0x4d')]['find']({'where':{'name':_0x1455c4,'userProfileId':_0x32c8b1[_0xebf6('0x4e')]},'raw':!![]})[_0xebf6('0x27')](function(_0x212414){if(_0x212414&&_0x212414[_0xebf6('0x4f')]===0x0){return db['UserProfileResource'][_0xebf6('0x48')]({'name':_0x1f98fd[_0xebf6('0x2d')],'resourceId':_0x1f98fd['id'],'type':_0x212414[_0xebf6('0x2d')],'sectionId':_0x212414['id']},{})[_0xebf6('0x27')](function(){return _0x186655;});}else{return _0x186655;}})[_0xebf6('0x50')](function(_0x2e7e30){logger[_0xebf6('0x2b')](_0xebf6('0x51'),_0x2e7e30);throw _0x2e7e30;});}return _0x186655;})[_0xebf6('0x27')](respondWithResult(_0x5d84ac,0xc9))['catch'](handleError(_0x5d84ac,null));};exports[_0xebf6('0x26')]=function(_0xe78fe5,_0x24ed4e){if(_0xe78fe5['body']['id']){delete _0xe78fe5[_0xebf6('0x49')]['id'];}return db['VoiceChanSpy']['find']({'where':{'id':_0xe78fe5[_0xebf6('0x52')]['id']}})[_0xebf6('0x27')](handleEntityNotFound(_0x24ed4e,null))[_0xebf6('0x27')](saveUpdates(_0xe78fe5[_0xebf6('0x49')],null))[_0xebf6('0x27')](respondWithResult(_0x24ed4e,null))['catch'](handleError(_0x24ed4e,null));};exports[_0xebf6('0x28')]=function(_0x5a1b51,_0x4ed306){return db['VoiceChanSpy'][_0xebf6('0x47')]({'where':{'id':_0x5a1b51[_0xebf6('0x52')]['id']}})['then'](handleEntityNotFound(_0x4ed306,null))[_0xebf6('0x27')](removeEntity(_0x4ed306,null))[_0xebf6('0x50')](handleError(_0x4ed306,null));};