2e66716068ed4ada96f14a0e65d9bbf65368f8df
[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 _0x8d9b=['exports','models','define','VoiceChanSpy','voice_chanspy','VoiceExtension','bulkCreate','destroy','lodash','util','bluebird','./voiceChanSpy.attributes','context','prefix','Set','format','CDR(type)=%s','chanspy','record','push','merge','recordingFormat','auth','Authenticate','password','ChanSpy','SIP/%s,%s','name','options','StopMixMonitor','length','concat','internal','agent','then','catch'];(function(_0xbf4ddf,_0x66b3cb){var _0x3cb273=function(_0x3cf903){while(--_0x3cf903){_0xbf4ddf['push'](_0xbf4ddf['shift']());}};_0x3cb273(++_0x66b3cb);}(_0x8d9b,0x104));var _0xb8d9=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x8d9b[_0x3dd15e];return _0x231fd0;};'use strict';var _=require(_0xb8d9('0x0'));var util=require(_0xb8d9('0x1'));var BPromise=require(_0xb8d9('0x2'));var attributes=require(_0xb8d9('0x3'));var getUserApplications=function(_0x44ddd9,_0x5d3b29,_0x4daeb1){var _0x3f763a=0x1;var _0x47b650=[];var _0x2192ff={'context':_0x5d3b29[_0xb8d9('0x4')]||'from-sip','exten':util['format']('%s%s',_0x44ddd9[_0xb8d9('0x5')],_0x4daeb1),'type':'system','isApp':![],'ChanSpyId':_0x44ddd9['id'],'UserId':_0x5d3b29['id']};_0x47b650['push'](_['merge']({'app':_0xb8d9('0x6'),'appdata':util[_0xb8d9('0x7')](_0xb8d9('0x8'),_0xb8d9('0x9')),'priority':_0x3f763a++},_0x2192ff));if(_0x44ddd9[_0xb8d9('0xa')]){_0x47b650[_0xb8d9('0xb')](_[_0xb8d9('0xc')]({'app':'MixMonitor','appdata':util[_0xb8d9('0x7')]('${UNIQUEID}.%s,a',_0x44ddd9[_0xb8d9('0xd')]),'priority':_0x3f763a++},_0x2192ff));}if(_0x44ddd9[_0xb8d9('0xe')]){_0x47b650[_0xb8d9('0xb')](_[_0xb8d9('0xc')]({'app':_0xb8d9('0xf'),'appdata':_0x44ddd9[_0xb8d9('0x10')],'priority':_0x3f763a++},_0x2192ff));}_0x47b650[_0xb8d9('0xb')](_[_0xb8d9('0xc')]({'app':_0xb8d9('0x11'),'appdata':util[_0xb8d9('0x7')](_0xb8d9('0x12'),_0x5d3b29[_0xb8d9('0x13')],_0x44ddd9[_0xb8d9('0x14')]?_0x44ddd9[_0xb8d9('0x14')]['join'](''):''),'priority':_0x3f763a++},_0x2192ff));if(_0x44ddd9[_0xb8d9('0xa')]){_0x47b650[_0xb8d9('0xb')](_[_0xb8d9('0xc')]({'app':_0xb8d9('0x15'),'priority':_0x3f763a++},_0x2192ff));}return _0x47b650;};var getChanSpyApplications=function(_0x283780,_0x5081dc){var _0x542141=[];for(var _0x5b7d5a=0x0,_0x2d2fc3=0x1;_0x5b7d5a<_0x5081dc[_0xb8d9('0x16')];_0x5b7d5a++,_0x2d2fc3=0x1){_0x542141=_0x542141[_0xb8d9('0x17')](getUserApplications(_0x283780,_0x5081dc[_0x5b7d5a],_0x5081dc[_0x5b7d5a][_0xb8d9('0x18')]));if(_0x5081dc[_0x5b7d5a]['internal']!=_0x5081dc[_0x5b7d5a][_0xb8d9('0x13')]){_0x542141=_0x542141['concat'](getUserApplications(_0x283780,_0x5081dc[_0x5b7d5a],_0x5081dc[_0x5b7d5a][_0xb8d9('0x13')]));}}return _0x542141;};var getChanSpyPromise=function(_0x1709da,_0x447367){return new BPromise(function(_0x3ff41e,_0x96b2eb){return _0x1709da['User']['findAll']({'attributes':['id','name',_0xb8d9('0x18')],'where':{'role':_0xb8d9('0x19'),'chanspy':!![]},'raw':!![]})[_0xb8d9('0x1a')](function(_0x32fd09){if(_0x32fd09){return _0x3ff41e(getChanSpyApplications(_0x447367,_0x32fd09));}return _0x3ff41e([]);})[_0xb8d9('0x1b')](function(_0x48c504){_0x96b2eb(_0x48c504);});});};module[_0xb8d9('0x1c')]=function(_0x430794,_0x1a2bfe){var _0x1e70e2=_0x430794[_0xb8d9('0x1d')];return _0x430794[_0xb8d9('0x1e')](_0xb8d9('0x1f'),attributes,{'tableName':_0xb8d9('0x20'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x3fa36e,_0x250457,_0x52df47){return getChanSpyPromise(_0x1e70e2,_0x3fa36e)[_0xb8d9('0x1a')](function(_0x49380d){if(_0x49380d&&_0x49380d['length']){return _0x1e70e2[_0xb8d9('0x21')][_0xb8d9('0x22')](_0x49380d);}})[_0xb8d9('0x1a')](function(){_0x52df47();})[_0xb8d9('0x1b')](function(_0x30b346){_0x52df47(_0x30b346);});},'afterUpdate':function(_0x4885f2,_0x241041,_0x282db6){return _0x1e70e2[_0xb8d9('0x21')]['destroy']({'where':{'ChanSpyId':_0x4885f2['id']}})[_0xb8d9('0x1a')](function(){return getChanSpyPromise(_0x1e70e2,_0x4885f2);})[_0xb8d9('0x1a')](function(_0x336918){if(_0x336918&&_0x336918['length']){return _0x1e70e2[_0xb8d9('0x21')][_0xb8d9('0x22')](_0x336918);}})['then'](function(){_0x282db6();})[_0xb8d9('0x1b')](function(_0x6cd7f6){_0x282db6(_0x6cd7f6);});},'afterDestroy':function(_0x2694f0,_0x1b1212,_0x358e4d){return _0x1e70e2[_0xb8d9('0x21')][_0xb8d9('0x23')]({'where':{'ChanSpyId':_0x2694f0['id']}})[_0xb8d9('0x1a')](function(){_0x358e4d();})[_0xb8d9('0x1b')](function(_0x390a28){_0x358e4d(_0x390a28);});}}});};