4702e9b51197ce76572e731496c9234387b0558b
[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 _0xfdec=['%s%s','prefix','push','merge','Set','CDR(type)=%s','chanspy','record','${UNIQUEID}.%s,a','recordingFormat','auth','password','ChanSpy','format','SIP/%s,%s','name','options','join','StopMixMonitor','concat','internal','User','findAll','agent','then','catch','exports','models','define','VoiceChanSpy','length','bulkCreate','VoiceExtension','lodash','util','bluebird','./voiceChanSpy.attributes','context','from-sip'];(function(_0x236d24,_0x29e80a){var _0x1574cf=function(_0x5d1dad){while(--_0x5d1dad){_0x236d24['push'](_0x236d24['shift']());}};_0x1574cf(++_0x29e80a);}(_0xfdec,0x132));var _0xcfde=function(_0x26bdda,_0x3ae7ec){_0x26bdda=_0x26bdda-0x0;var _0x4c4761=_0xfdec[_0x26bdda];return _0x4c4761;};'use strict';var _=require(_0xcfde('0x0'));var util=require(_0xcfde('0x1'));var BPromise=require(_0xcfde('0x2'));var attributes=require(_0xcfde('0x3'));var getUserApplications=function(_0x258657,_0x38f576,_0x29f28c){var _0x21b4ed=0x1;var _0x3e702b=[];var _0x450920={'context':_0x38f576[_0xcfde('0x4')]||_0xcfde('0x5'),'exten':util['format'](_0xcfde('0x6'),_0x258657[_0xcfde('0x7')],_0x29f28c),'type':'system','isApp':![],'ChanSpyId':_0x258657['id'],'UserId':_0x38f576['id']};_0x3e702b[_0xcfde('0x8')](_[_0xcfde('0x9')]({'app':_0xcfde('0xa'),'appdata':util['format'](_0xcfde('0xb'),_0xcfde('0xc')),'priority':_0x21b4ed++},_0x450920));if(_0x258657[_0xcfde('0xd')]){_0x3e702b[_0xcfde('0x8')](_[_0xcfde('0x9')]({'app':'MixMonitor','appdata':util['format'](_0xcfde('0xe'),_0x258657[_0xcfde('0xf')]),'priority':_0x21b4ed++},_0x450920));}if(_0x258657[_0xcfde('0x10')]){_0x3e702b[_0xcfde('0x8')](_[_0xcfde('0x9')]({'app':'Authenticate','appdata':_0x258657[_0xcfde('0x11')],'priority':_0x21b4ed++},_0x450920));}_0x3e702b[_0xcfde('0x8')](_[_0xcfde('0x9')]({'app':_0xcfde('0x12'),'appdata':util[_0xcfde('0x13')](_0xcfde('0x14'),_0x38f576[_0xcfde('0x15')],_0x258657[_0xcfde('0x16')]?_0x258657[_0xcfde('0x16')][_0xcfde('0x17')](''):''),'priority':_0x21b4ed++},_0x450920));if(_0x258657['record']){_0x3e702b[_0xcfde('0x8')](_[_0xcfde('0x9')]({'app':_0xcfde('0x18'),'priority':_0x21b4ed++},_0x450920));}return _0x3e702b;};var getChanSpyApplications=function(_0x3927ad,_0x2e9cce){var _0x584d21=[];for(var _0x274008=0x0,_0x357774=0x1;_0x274008<_0x2e9cce['length'];_0x274008++,_0x357774=0x1){_0x584d21=_0x584d21[_0xcfde('0x19')](getUserApplications(_0x3927ad,_0x2e9cce[_0x274008],_0x2e9cce[_0x274008][_0xcfde('0x1a')]));if(_0x2e9cce[_0x274008][_0xcfde('0x1a')]!=_0x2e9cce[_0x274008][_0xcfde('0x15')]){_0x584d21=_0x584d21['concat'](getUserApplications(_0x3927ad,_0x2e9cce[_0x274008],_0x2e9cce[_0x274008][_0xcfde('0x15')]));}}return _0x584d21;};var getChanSpyPromise=function(_0x507708,_0x3990ba){return new BPromise(function(_0x143899,_0x1e2383){return _0x507708[_0xcfde('0x1b')][_0xcfde('0x1c')]({'attributes':['id',_0xcfde('0x15'),_0xcfde('0x1a')],'where':{'role':_0xcfde('0x1d'),'chanspy':!![]},'raw':!![]})[_0xcfde('0x1e')](function(_0x42dd02){if(_0x42dd02){return _0x143899(getChanSpyApplications(_0x3990ba,_0x42dd02));}return _0x143899([]);})[_0xcfde('0x1f')](function(_0x4701e6){_0x1e2383(_0x4701e6);});});};module[_0xcfde('0x20')]=function(_0x3b2e5e,_0xe12150){var _0x1c2c74=_0x3b2e5e[_0xcfde('0x21')];return _0x3b2e5e[_0xcfde('0x22')](_0xcfde('0x23'),attributes,{'tableName':'voice_chanspy','paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x59f3a1,_0x6567a1,_0x186705){return getChanSpyPromise(_0x1c2c74,_0x59f3a1)[_0xcfde('0x1e')](function(_0x1acedd){if(_0x1acedd&&_0x1acedd[_0xcfde('0x24')]){return _0x1c2c74['VoiceExtension'][_0xcfde('0x25')](_0x1acedd);}})[_0xcfde('0x1e')](function(){_0x186705();})[_0xcfde('0x1f')](function(_0x41aaf5){_0x186705(_0x41aaf5);});},'afterUpdate':function(_0x59441f,_0x570746,_0x226614){return _0x1c2c74[_0xcfde('0x26')]['destroy']({'where':{'ChanSpyId':_0x59441f['id']}})['then'](function(){return getChanSpyPromise(_0x1c2c74,_0x59441f);})[_0xcfde('0x1e')](function(_0xb9d089){if(_0xb9d089&&_0xb9d089['length']){return _0x1c2c74[_0xcfde('0x26')][_0xcfde('0x25')](_0xb9d089);}})['then'](function(){_0x226614();})[_0xcfde('0x1f')](function(_0x34cecf){_0x226614(_0x34cecf);});},'afterDestroy':function(_0x35cb34,_0x57d495,_0x3701fb){return _0x1c2c74[_0xcfde('0x26')]['destroy']({'where':{'ChanSpyId':_0x35cb34['id']}})[_0xcfde('0x1e')](function(){_0x3701fb();})[_0xcfde('0x1f')](function(_0x1bfca8){_0x3701fb(_0x1bfca8);});}}});};