3b8ba6bae2a24527b66afbb30f92e278c2dfb07f
[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 _0x5814=['context','format','prefix','system','push','merge','CDR(type)=%s','record','MixMonitor','${UNIQUEID}.%s,a','recordingFormat','Authenticate','password','ChanSpy','name','options','join','StopMixMonitor','length','concat','internal','agent','then','catch','VoiceChanSpy','voice_chanspy','VoiceExtension','bulkCreate','destroy','lodash','util','./voiceChanSpy.attributes'];(function(_0x4fde08,_0x463a36){var _0x12e725=function(_0x2670c5){while(--_0x2670c5){_0x4fde08['push'](_0x4fde08['shift']());}};_0x12e725(++_0x463a36);}(_0x5814,0x9d));var _0x4581=function(_0x52cdb3,_0x247869){_0x52cdb3=_0x52cdb3-0x0;var _0x23671e=_0x5814[_0x52cdb3];return _0x23671e;};'use strict';var _=require(_0x4581('0x0'));var util=require(_0x4581('0x1'));var BPromise=require('bluebird');var attributes=require(_0x4581('0x2'));var getUserApplications=function(_0x53d390,_0x4c0184,_0x11c3a9){var _0x192582=0x1;var _0x4dbbb3=[];var _0x2470fc={'context':_0x4c0184[_0x4581('0x3')]||'from-sip','exten':util[_0x4581('0x4')]('%s%s',_0x53d390[_0x4581('0x5')],_0x11c3a9),'type':_0x4581('0x6'),'isApp':![],'ChanSpyId':_0x53d390['id'],'UserId':_0x4c0184['id']};_0x4dbbb3[_0x4581('0x7')](_[_0x4581('0x8')]({'app':'Set','appdata':util[_0x4581('0x4')](_0x4581('0x9'),'chanspy'),'priority':_0x192582++},_0x2470fc));if(_0x53d390[_0x4581('0xa')]){_0x4dbbb3[_0x4581('0x7')](_[_0x4581('0x8')]({'app':_0x4581('0xb'),'appdata':util[_0x4581('0x4')](_0x4581('0xc'),_0x53d390[_0x4581('0xd')]),'priority':_0x192582++},_0x2470fc));}if(_0x53d390['auth']){_0x4dbbb3[_0x4581('0x7')](_[_0x4581('0x8')]({'app':_0x4581('0xe'),'appdata':_0x53d390[_0x4581('0xf')],'priority':_0x192582++},_0x2470fc));}_0x4dbbb3[_0x4581('0x7')](_['merge']({'app':_0x4581('0x10'),'appdata':util['format']('SIP/%s,%s',_0x4c0184[_0x4581('0x11')],_0x53d390[_0x4581('0x12')]?_0x53d390[_0x4581('0x12')][_0x4581('0x13')](''):''),'priority':_0x192582++},_0x2470fc));if(_0x53d390[_0x4581('0xa')]){_0x4dbbb3[_0x4581('0x7')](_[_0x4581('0x8')]({'app':_0x4581('0x14'),'priority':_0x192582++},_0x2470fc));}return _0x4dbbb3;};var getChanSpyApplications=function(_0x24a9ce,_0x1753cc){var _0x12e9ce=[];for(var _0x3e8b77=0x0,_0x5f1f82=0x1;_0x3e8b77<_0x1753cc[_0x4581('0x15')];_0x3e8b77++,_0x5f1f82=0x1){_0x12e9ce=_0x12e9ce[_0x4581('0x16')](getUserApplications(_0x24a9ce,_0x1753cc[_0x3e8b77],_0x1753cc[_0x3e8b77][_0x4581('0x17')]));if(_0x1753cc[_0x3e8b77][_0x4581('0x17')]!=_0x1753cc[_0x3e8b77][_0x4581('0x11')]){_0x12e9ce=_0x12e9ce[_0x4581('0x16')](getUserApplications(_0x24a9ce,_0x1753cc[_0x3e8b77],_0x1753cc[_0x3e8b77][_0x4581('0x11')]));}}return _0x12e9ce;};var getChanSpyPromise=function(_0x5d1e47,_0x12959f){return new BPromise(function(_0x570351,_0xce9407){return _0x5d1e47['User']['findAll']({'attributes':['id',_0x4581('0x11'),_0x4581('0x17')],'where':{'role':_0x4581('0x18'),'chanspy':!![]},'raw':!![]})[_0x4581('0x19')](function(_0x4ca663){if(_0x4ca663){return _0x570351(getChanSpyApplications(_0x12959f,_0x4ca663));}return _0x570351([]);})[_0x4581('0x1a')](function(_0xf9a70){_0xce9407(_0xf9a70);});});};module['exports']=function(_0x305faa,_0x519622){var _0x455c97=_0x305faa['models'];return _0x305faa['define'](_0x4581('0x1b'),attributes,{'tableName':_0x4581('0x1c'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x4ef972,_0x4b808e,_0x1c897a){return getChanSpyPromise(_0x455c97,_0x4ef972)[_0x4581('0x19')](function(_0x4a0dbb){if(_0x4a0dbb&&_0x4a0dbb['length']){return _0x455c97[_0x4581('0x1d')][_0x4581('0x1e')](_0x4a0dbb);}})[_0x4581('0x19')](function(){_0x1c897a();})['catch'](function(_0x3735c3){_0x1c897a(_0x3735c3);});},'afterUpdate':function(_0x14ff8f,_0x1a4729,_0x2a781b){return _0x455c97['VoiceExtension'][_0x4581('0x1f')]({'where':{'ChanSpyId':_0x14ff8f['id']}})[_0x4581('0x19')](function(){return getChanSpyPromise(_0x455c97,_0x14ff8f);})[_0x4581('0x19')](function(_0xcfcdfe){if(_0xcfcdfe&&_0xcfcdfe[_0x4581('0x15')]){return _0x455c97[_0x4581('0x1d')][_0x4581('0x1e')](_0xcfcdfe);}})[_0x4581('0x19')](function(){_0x2a781b();})[_0x4581('0x1a')](function(_0x4ac25f){_0x2a781b(_0x4ac25f);});},'afterDestroy':function(_0x11ab59,_0x5c065e,_0x4061bf){return _0x455c97[_0x4581('0x1d')][_0x4581('0x1f')]({'where':{'ChanSpyId':_0x11ab59['id']}})[_0x4581('0x19')](function(){_0x4061bf();})['catch'](function(_0x1c0320){_0x4061bf(_0x1c0320);});}}});};