Built motion from commit 953226e6.|2.6.32
[motion2.git] / server / api / voiceChanSpy / voiceChanSpy.model.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 _0x0c21=['User','findAll','internal','agent','then','exports','models','VoiceChanSpy','voice_chanspy','VoiceExtension','bulkCreate','catch','destroy','lodash','util','bluebird','./voiceChanSpy.attributes','context','format','system','push','merge','Set','MixMonitor','Authenticate','password','ChanSpy','SIP/%s,%s','name','options','record','StopMixMonitor','length','concat'];(function(_0x36c5b0,_0x5001da){var _0xf19333=function(_0x1e880a){while(--_0x1e880a){_0x36c5b0['push'](_0x36c5b0['shift']());}};_0xf19333(++_0x5001da);}(_0x0c21,0x1c7));var _0x10c2=function(_0x510baa,_0x2ef9bc){_0x510baa=_0x510baa-0x0;var _0x53da25=_0x0c21[_0x510baa];return _0x53da25;};'use strict';var _=require(_0x10c2('0x0'));var util=require(_0x10c2('0x1'));var BPromise=require(_0x10c2('0x2'));var attributes=require(_0x10c2('0x3'));var getUserApplications=function(_0xfda3ca,_0xc68d66,_0x64a713){var _0x1cd97a=0x1;var _0x20917a=[];var _0x21ea2d={'context':_0xc68d66[_0x10c2('0x4')]||'from-sip','exten':util[_0x10c2('0x5')]('%s%s',_0xfda3ca['prefix'],_0x64a713),'type':_0x10c2('0x6'),'isApp':![],'ChanSpyId':_0xfda3ca['id'],'UserId':_0xc68d66['id']};_0x20917a[_0x10c2('0x7')](_[_0x10c2('0x8')]({'app':_0x10c2('0x9'),'appdata':util[_0x10c2('0x5')]('CDR(type)=%s','chanspy'),'priority':_0x1cd97a++},_0x21ea2d));if(_0xfda3ca['record']){_0x20917a[_0x10c2('0x7')](_['merge']({'app':_0x10c2('0xa'),'appdata':util[_0x10c2('0x5')]('${UNIQUEID}.%s,a',_0xfda3ca['recordingFormat']),'priority':_0x1cd97a++},_0x21ea2d));}if(_0xfda3ca['auth']){_0x20917a[_0x10c2('0x7')](_[_0x10c2('0x8')]({'app':_0x10c2('0xb'),'appdata':_0xfda3ca[_0x10c2('0xc')],'priority':_0x1cd97a++},_0x21ea2d));}_0x20917a[_0x10c2('0x7')](_[_0x10c2('0x8')]({'app':_0x10c2('0xd'),'appdata':util[_0x10c2('0x5')](_0x10c2('0xe'),_0xc68d66[_0x10c2('0xf')],_0xfda3ca[_0x10c2('0x10')]?_0xfda3ca[_0x10c2('0x10')]['join'](''):''),'priority':_0x1cd97a++},_0x21ea2d));if(_0xfda3ca[_0x10c2('0x11')]){_0x20917a[_0x10c2('0x7')](_[_0x10c2('0x8')]({'app':_0x10c2('0x12'),'priority':_0x1cd97a++},_0x21ea2d));}return _0x20917a;};var getChanSpyApplications=function(_0x51b074,_0x57edd6){var _0x1a2673=[];for(var _0x53f0af=0x0,_0x2f5ac2=0x1;_0x53f0af<_0x57edd6[_0x10c2('0x13')];_0x53f0af++,_0x2f5ac2=0x1){_0x1a2673=_0x1a2673[_0x10c2('0x14')](getUserApplications(_0x51b074,_0x57edd6[_0x53f0af],_0x57edd6[_0x53f0af]['internal']));if(_0x57edd6[_0x53f0af]['internal']!=_0x57edd6[_0x53f0af]['name']){_0x1a2673=_0x1a2673[_0x10c2('0x14')](getUserApplications(_0x51b074,_0x57edd6[_0x53f0af],_0x57edd6[_0x53f0af][_0x10c2('0xf')]));}}return _0x1a2673;};var getChanSpyPromise=function(_0x2a8ded,_0x20bcd1){return new BPromise(function(_0x4dc7d2,_0x4d4457){return _0x2a8ded[_0x10c2('0x15')][_0x10c2('0x16')]({'attributes':['id','name',_0x10c2('0x17')],'where':{'role':_0x10c2('0x18'),'chanspy':!![]},'raw':!![]})[_0x10c2('0x19')](function(_0x2bd3bb){if(_0x2bd3bb){return _0x4dc7d2(getChanSpyApplications(_0x20bcd1,_0x2bd3bb));}return _0x4dc7d2([]);})['catch'](function(_0x5f955){_0x4d4457(_0x5f955);});});};module[_0x10c2('0x1a')]=function(_0x12ca50,_0x530723){var _0x3c1e7a=_0x12ca50[_0x10c2('0x1b')];return _0x12ca50['define'](_0x10c2('0x1c'),attributes,{'tableName':_0x10c2('0x1d'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x3c1e31,_0x4c4d9a,_0x31cd0a){return getChanSpyPromise(_0x3c1e7a,_0x3c1e31)[_0x10c2('0x19')](function(_0x1ee8e3){if(_0x1ee8e3&&_0x1ee8e3[_0x10c2('0x13')]){return _0x3c1e7a[_0x10c2('0x1e')][_0x10c2('0x1f')](_0x1ee8e3);}})['then'](function(){_0x31cd0a();})[_0x10c2('0x20')](function(_0x38d904){_0x31cd0a(_0x38d904);});},'afterUpdate':function(_0x299013,_0x30f9b3,_0x5a8ded){return _0x3c1e7a[_0x10c2('0x1e')][_0x10c2('0x21')]({'where':{'ChanSpyId':_0x299013['id']}})['then'](function(){return getChanSpyPromise(_0x3c1e7a,_0x299013);})[_0x10c2('0x19')](function(_0x1eae01){if(_0x1eae01&&_0x1eae01['length']){return _0x3c1e7a[_0x10c2('0x1e')]['bulkCreate'](_0x1eae01);}})['then'](function(){_0x5a8ded();})['catch'](function(_0x12dbee){_0x5a8ded(_0x12dbee);});},'afterDestroy':function(_0x53e516,_0x3f4c33,_0x4b6e98){return _0x3c1e7a[_0x10c2('0x1e')]['destroy']({'where':{'ChanSpyId':_0x53e516['id']}})[_0x10c2('0x19')](function(){_0x4b6e98();})[_0x10c2('0x20')](function(_0x4e3b15){_0x4b6e98(_0x4e3b15);});}}});};