Built motion from commit 9efc8423.|2.6.31
[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 _0xa3f0=['password','ChanSpy','SIP/%s,%s','name','options','join','StopMixMonitor','length','concat','internal','findAll','agent','then','catch','exports','models','define','VoiceChanSpy','VoiceExtension','bulkCreate','destroy','lodash','util','bluebird','./voiceChanSpy.attributes','context','from-sip','prefix','system','push','merge','Set','format','CDR(type)=%s','chanspy','record','MixMonitor','${UNIQUEID}.%s,a','recordingFormat','Authenticate'];(function(_0x3e2e99,_0xad339){var _0x52ceef=function(_0x55c192){while(--_0x55c192){_0x3e2e99['push'](_0x3e2e99['shift']());}};_0x52ceef(++_0xad339);}(_0xa3f0,0xb5));var _0x0a3f=function(_0x3c6dce,_0x5424dd){_0x3c6dce=_0x3c6dce-0x0;var _0x1450e9=_0xa3f0[_0x3c6dce];return _0x1450e9;};'use strict';var _=require(_0x0a3f('0x0'));var util=require(_0x0a3f('0x1'));var BPromise=require(_0x0a3f('0x2'));var attributes=require(_0x0a3f('0x3'));var getUserApplications=function(_0x40f9ae,_0x4fe048,_0x9e6eb9){var _0x5a63db=0x1;var _0x1d672b=[];var _0x38c218={'context':_0x4fe048[_0x0a3f('0x4')]||_0x0a3f('0x5'),'exten':util['format']('%s%s',_0x40f9ae[_0x0a3f('0x6')],_0x9e6eb9),'type':_0x0a3f('0x7'),'isApp':![],'ChanSpyId':_0x40f9ae['id'],'UserId':_0x4fe048['id']};_0x1d672b[_0x0a3f('0x8')](_[_0x0a3f('0x9')]({'app':_0x0a3f('0xa'),'appdata':util[_0x0a3f('0xb')](_0x0a3f('0xc'),_0x0a3f('0xd')),'priority':_0x5a63db++},_0x38c218));if(_0x40f9ae[_0x0a3f('0xe')]){_0x1d672b[_0x0a3f('0x8')](_[_0x0a3f('0x9')]({'app':_0x0a3f('0xf'),'appdata':util['format'](_0x0a3f('0x10'),_0x40f9ae[_0x0a3f('0x11')]),'priority':_0x5a63db++},_0x38c218));}if(_0x40f9ae['auth']){_0x1d672b[_0x0a3f('0x8')](_[_0x0a3f('0x9')]({'app':_0x0a3f('0x12'),'appdata':_0x40f9ae[_0x0a3f('0x13')],'priority':_0x5a63db++},_0x38c218));}_0x1d672b[_0x0a3f('0x8')](_[_0x0a3f('0x9')]({'app':_0x0a3f('0x14'),'appdata':util[_0x0a3f('0xb')](_0x0a3f('0x15'),_0x4fe048[_0x0a3f('0x16')],_0x40f9ae['options']?_0x40f9ae[_0x0a3f('0x17')][_0x0a3f('0x18')](''):''),'priority':_0x5a63db++},_0x38c218));if(_0x40f9ae[_0x0a3f('0xe')]){_0x1d672b['push'](_[_0x0a3f('0x9')]({'app':_0x0a3f('0x19'),'priority':_0x5a63db++},_0x38c218));}return _0x1d672b;};var getChanSpyApplications=function(_0x40ce11,_0x5818e1){var _0x4b4ce2=[];for(var _0x970106=0x0,_0x476eb8=0x1;_0x970106<_0x5818e1[_0x0a3f('0x1a')];_0x970106++,_0x476eb8=0x1){_0x4b4ce2=_0x4b4ce2[_0x0a3f('0x1b')](getUserApplications(_0x40ce11,_0x5818e1[_0x970106],_0x5818e1[_0x970106]['internal']));if(_0x5818e1[_0x970106][_0x0a3f('0x1c')]!=_0x5818e1[_0x970106][_0x0a3f('0x16')]){_0x4b4ce2=_0x4b4ce2['concat'](getUserApplications(_0x40ce11,_0x5818e1[_0x970106],_0x5818e1[_0x970106][_0x0a3f('0x16')]));}}return _0x4b4ce2;};var getChanSpyPromise=function(_0x15b70a,_0x2fe328){return new BPromise(function(_0x263fa0,_0x43e798){return _0x15b70a['User'][_0x0a3f('0x1d')]({'attributes':['id',_0x0a3f('0x16'),_0x0a3f('0x1c')],'where':{'role':_0x0a3f('0x1e'),'chanspy':!![]},'raw':!![]})[_0x0a3f('0x1f')](function(_0x1828e0){if(_0x1828e0){return _0x263fa0(getChanSpyApplications(_0x2fe328,_0x1828e0));}return _0x263fa0([]);})[_0x0a3f('0x20')](function(_0x3094d2){_0x43e798(_0x3094d2);});});};module[_0x0a3f('0x21')]=function(_0x30677e,_0x3e0e06){var _0x33b20c=_0x30677e[_0x0a3f('0x22')];return _0x30677e[_0x0a3f('0x23')](_0x0a3f('0x24'),attributes,{'tableName':'voice_chanspy','paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x50676d,_0x81249e,_0x20eae1){return getChanSpyPromise(_0x33b20c,_0x50676d)[_0x0a3f('0x1f')](function(_0x40ef4d){if(_0x40ef4d&&_0x40ef4d['length']){return _0x33b20c[_0x0a3f('0x25')][_0x0a3f('0x26')](_0x40ef4d);}})['then'](function(){_0x20eae1();})['catch'](function(_0x278f53){_0x20eae1(_0x278f53);});},'afterUpdate':function(_0xf2e7dd,_0x1f0f8b,_0x339de8){return _0x33b20c[_0x0a3f('0x25')][_0x0a3f('0x27')]({'where':{'ChanSpyId':_0xf2e7dd['id']}})['then'](function(){return getChanSpyPromise(_0x33b20c,_0xf2e7dd);})['then'](function(_0x4141c3){if(_0x4141c3&&_0x4141c3[_0x0a3f('0x1a')]){return _0x33b20c[_0x0a3f('0x25')]['bulkCreate'](_0x4141c3);}})[_0x0a3f('0x1f')](function(){_0x339de8();})[_0x0a3f('0x20')](function(_0x47dd3b){_0x339de8(_0x47dd3b);});},'afterDestroy':function(_0x25d1ea,_0x391414,_0x540ff3){return _0x33b20c['VoiceExtension'][_0x0a3f('0x27')]({'where':{'ChanSpyId':_0x25d1ea['id']}})['then'](function(){_0x540ff3();})['catch'](function(_0x256ccf){_0x540ff3(_0x256ccf);});}}});};