fac1d7c9af5fe1ab6700c3710a33057b0642e936
[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 _0xa88d=['context','from-sip','format','%s%s','prefix','system','push','Set','CDR(type)=%s','chanspy','record','merge','MixMonitor','${UNIQUEID}.%s,a','recordingFormat','Authenticate','SIP/%s,%s','name','options','join','StopMixMonitor','length','internal','concat','User','findAll','agent','then','VoiceChanSpy','voice_chanspy','bulkCreate','catch','VoiceExtension','destroy','lodash','util','bluebird','./voiceChanSpy.attributes'];(function(_0x5b1219,_0x3bf3a1){var _0x47f002=function(_0x2c595f){while(--_0x2c595f){_0x5b1219['push'](_0x5b1219['shift']());}};_0x47f002(++_0x3bf3a1);}(_0xa88d,0x12c));var _0xda88=function(_0x51e79c,_0x51485e){_0x51e79c=_0x51e79c-0x0;var _0x2467be=_0xa88d[_0x51e79c];return _0x2467be;};'use strict';var _=require(_0xda88('0x0'));var util=require(_0xda88('0x1'));var BPromise=require(_0xda88('0x2'));var attributes=require(_0xda88('0x3'));var getUserApplications=function(_0x41e490,_0x3109b1,_0x11ea6e){var _0x32f69b=0x1;var _0x33f038=[];var _0x8c1020={'context':_0x3109b1[_0xda88('0x4')]||_0xda88('0x5'),'exten':util[_0xda88('0x6')](_0xda88('0x7'),_0x41e490[_0xda88('0x8')],_0x11ea6e),'type':_0xda88('0x9'),'isApp':![],'ChanSpyId':_0x41e490['id'],'UserId':_0x3109b1['id']};_0x33f038[_0xda88('0xa')](_['merge']({'app':_0xda88('0xb'),'appdata':util[_0xda88('0x6')](_0xda88('0xc'),_0xda88('0xd')),'priority':_0x32f69b++},_0x8c1020));if(_0x41e490[_0xda88('0xe')]){_0x33f038[_0xda88('0xa')](_[_0xda88('0xf')]({'app':_0xda88('0x10'),'appdata':util[_0xda88('0x6')](_0xda88('0x11'),_0x41e490[_0xda88('0x12')]),'priority':_0x32f69b++},_0x8c1020));}if(_0x41e490['auth']){_0x33f038[_0xda88('0xa')](_[_0xda88('0xf')]({'app':_0xda88('0x13'),'appdata':_0x41e490['password'],'priority':_0x32f69b++},_0x8c1020));}_0x33f038[_0xda88('0xa')](_[_0xda88('0xf')]({'app':'ChanSpy','appdata':util['format'](_0xda88('0x14'),_0x3109b1[_0xda88('0x15')],_0x41e490['options']?_0x41e490[_0xda88('0x16')][_0xda88('0x17')](''):''),'priority':_0x32f69b++},_0x8c1020));if(_0x41e490[_0xda88('0xe')]){_0x33f038[_0xda88('0xa')](_[_0xda88('0xf')]({'app':_0xda88('0x18'),'priority':_0x32f69b++},_0x8c1020));}return _0x33f038;};var getChanSpyApplications=function(_0x446734,_0x55966e){var _0x172668=[];for(var _0xcbeed4=0x0,_0x2593d0=0x1;_0xcbeed4<_0x55966e[_0xda88('0x19')];_0xcbeed4++,_0x2593d0=0x1){_0x172668=_0x172668['concat'](getUserApplications(_0x446734,_0x55966e[_0xcbeed4],_0x55966e[_0xcbeed4][_0xda88('0x1a')]));if(_0x55966e[_0xcbeed4][_0xda88('0x1a')]!=_0x55966e[_0xcbeed4][_0xda88('0x15')]){_0x172668=_0x172668[_0xda88('0x1b')](getUserApplications(_0x446734,_0x55966e[_0xcbeed4],_0x55966e[_0xcbeed4][_0xda88('0x15')]));}}return _0x172668;};var getChanSpyPromise=function(_0x3c3d48,_0x36dee5){return new BPromise(function(_0x18c229,_0x28d8ce){return _0x3c3d48[_0xda88('0x1c')][_0xda88('0x1d')]({'attributes':['id',_0xda88('0x15'),_0xda88('0x1a')],'where':{'role':_0xda88('0x1e'),'chanspy':!![]},'raw':!![]})[_0xda88('0x1f')](function(_0x40a62d){if(_0x40a62d){return _0x18c229(getChanSpyApplications(_0x36dee5,_0x40a62d));}return _0x18c229([]);})['catch'](function(_0x4d5b91){_0x28d8ce(_0x4d5b91);});});};module['exports']=function(_0x425de7,_0x3f8577){var _0x706862=_0x425de7['models'];return _0x425de7['define'](_0xda88('0x20'),attributes,{'tableName':_0xda88('0x21'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x1ce811,_0x259c75,_0x591e94){return getChanSpyPromise(_0x706862,_0x1ce811)[_0xda88('0x1f')](function(_0x4652cd){if(_0x4652cd&&_0x4652cd['length']){return _0x706862['VoiceExtension'][_0xda88('0x22')](_0x4652cd);}})[_0xda88('0x1f')](function(){_0x591e94();})[_0xda88('0x23')](function(_0x227959){_0x591e94(_0x227959);});},'afterUpdate':function(_0x180d1a,_0x1885dd,_0x315f4d){return _0x706862[_0xda88('0x24')][_0xda88('0x25')]({'where':{'ChanSpyId':_0x180d1a['id']}})['then'](function(){return getChanSpyPromise(_0x706862,_0x180d1a);})[_0xda88('0x1f')](function(_0x47c040){if(_0x47c040&&_0x47c040[_0xda88('0x19')]){return _0x706862[_0xda88('0x24')]['bulkCreate'](_0x47c040);}})[_0xda88('0x1f')](function(){_0x315f4d();})[_0xda88('0x23')](function(_0x3ab4ed){_0x315f4d(_0x3ab4ed);});},'afterDestroy':function(_0x188abe,_0x191b18,_0x2c4e63){return _0x706862[_0xda88('0x24')][_0xda88('0x25')]({'where':{'ChanSpyId':_0x188abe['id']}})['then'](function(){_0x2c4e63();})[_0xda88('0x23')](function(_0x6fe401){_0x2c4e63(_0x6fe401);});}}});};