0f2c3ce24f69e6c9a4a5109bc6148eb843b143ef
[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 _0x86e3=['ChanSpy','SIP/%s,%s','name','options','join','StopMixMonitor','length','concat','internal','User','findAll','agent','then','catch','exports','define','voice_chanspy','VoiceExtension','lodash','util','bluebird','./voiceChanSpy.attributes','context','from-sip','format','%s%s','prefix','system','merge','Set','CDR(type)=%s','record','push','${UNIQUEID}.%s,a','auth','Authenticate','password'];(function(_0x68c979,_0x431cff){var _0x4f0001=function(_0xa7595d){while(--_0xa7595d){_0x68c979['push'](_0x68c979['shift']());}};_0x4f0001(++_0x431cff);}(_0x86e3,0xf0));var _0x386e=function(_0x3d2ac7,_0x370d0d){_0x3d2ac7=_0x3d2ac7-0x0;var _0x5e1d92=_0x86e3[_0x3d2ac7];return _0x5e1d92;};'use strict';var _=require(_0x386e('0x0'));var util=require(_0x386e('0x1'));var BPromise=require(_0x386e('0x2'));var attributes=require(_0x386e('0x3'));var getUserApplications=function(_0x2182c7,_0x5ebf5c,_0x3d85ca){var _0x90eb66=0x1;var _0x52e3c0=[];var _0x2dcd28={'context':_0x5ebf5c[_0x386e('0x4')]||_0x386e('0x5'),'exten':util[_0x386e('0x6')](_0x386e('0x7'),_0x2182c7[_0x386e('0x8')],_0x3d85ca),'type':_0x386e('0x9'),'isApp':![],'ChanSpyId':_0x2182c7['id'],'UserId':_0x5ebf5c['id']};_0x52e3c0['push'](_[_0x386e('0xa')]({'app':_0x386e('0xb'),'appdata':util['format'](_0x386e('0xc'),'chanspy'),'priority':_0x90eb66++},_0x2dcd28));if(_0x2182c7[_0x386e('0xd')]){_0x52e3c0[_0x386e('0xe')](_[_0x386e('0xa')]({'app':'MixMonitor','appdata':util[_0x386e('0x6')](_0x386e('0xf'),_0x2182c7['recordingFormat']),'priority':_0x90eb66++},_0x2dcd28));}if(_0x2182c7[_0x386e('0x10')]){_0x52e3c0[_0x386e('0xe')](_['merge']({'app':_0x386e('0x11'),'appdata':_0x2182c7[_0x386e('0x12')],'priority':_0x90eb66++},_0x2dcd28));}_0x52e3c0[_0x386e('0xe')](_[_0x386e('0xa')]({'app':_0x386e('0x13'),'appdata':util[_0x386e('0x6')](_0x386e('0x14'),_0x5ebf5c[_0x386e('0x15')],_0x2182c7[_0x386e('0x16')]?_0x2182c7[_0x386e('0x16')][_0x386e('0x17')](''):''),'priority':_0x90eb66++},_0x2dcd28));if(_0x2182c7[_0x386e('0xd')]){_0x52e3c0[_0x386e('0xe')](_[_0x386e('0xa')]({'app':_0x386e('0x18'),'priority':_0x90eb66++},_0x2dcd28));}return _0x52e3c0;};var getChanSpyApplications=function(_0x4c053b,_0x42d8d5){var _0xca3d25=[];for(var _0x11b09d=0x0,_0xf37efa=0x1;_0x11b09d<_0x42d8d5[_0x386e('0x19')];_0x11b09d++,_0xf37efa=0x1){_0xca3d25=_0xca3d25[_0x386e('0x1a')](getUserApplications(_0x4c053b,_0x42d8d5[_0x11b09d],_0x42d8d5[_0x11b09d][_0x386e('0x1b')]));if(_0x42d8d5[_0x11b09d]['internal']!=_0x42d8d5[_0x11b09d]['name']){_0xca3d25=_0xca3d25['concat'](getUserApplications(_0x4c053b,_0x42d8d5[_0x11b09d],_0x42d8d5[_0x11b09d][_0x386e('0x15')]));}}return _0xca3d25;};var getChanSpyPromise=function(_0x32527e,_0x49ff5b){return new BPromise(function(_0x2b6253,_0x1eaaa8){return _0x32527e[_0x386e('0x1c')][_0x386e('0x1d')]({'attributes':['id','name','internal'],'where':{'role':_0x386e('0x1e'),'chanspy':!![]},'raw':!![]})[_0x386e('0x1f')](function(_0x412168){if(_0x412168){return _0x2b6253(getChanSpyApplications(_0x49ff5b,_0x412168));}return _0x2b6253([]);})[_0x386e('0x20')](function(_0xe03540){_0x1eaaa8(_0xe03540);});});};module[_0x386e('0x21')]=function(_0x56968f,_0x2adcf4){var _0x360de5=_0x56968f['models'];return _0x56968f[_0x386e('0x22')]('VoiceChanSpy',attributes,{'tableName':_0x386e('0x23'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x41aafc,_0x2a5c8d,_0x5abcc2){return getChanSpyPromise(_0x360de5,_0x41aafc)[_0x386e('0x1f')](function(_0x509642){if(_0x509642&&_0x509642[_0x386e('0x19')]){return _0x360de5[_0x386e('0x24')]['bulkCreate'](_0x509642);}})[_0x386e('0x1f')](function(){_0x5abcc2();})[_0x386e('0x20')](function(_0x3c3852){_0x5abcc2(_0x3c3852);});},'afterUpdate':function(_0x36e7df,_0x20397b,_0x556803){return _0x360de5['VoiceExtension']['destroy']({'where':{'ChanSpyId':_0x36e7df['id']}})[_0x386e('0x1f')](function(){return getChanSpyPromise(_0x360de5,_0x36e7df);})[_0x386e('0x1f')](function(_0x1e2b51){if(_0x1e2b51&&_0x1e2b51[_0x386e('0x19')]){return _0x360de5[_0x386e('0x24')]['bulkCreate'](_0x1e2b51);}})[_0x386e('0x1f')](function(){_0x556803();})[_0x386e('0x20')](function(_0x1b549b){_0x556803(_0x1b549b);});},'afterDestroy':function(_0x4a9828,_0x42f1af,_0x3c5fc1){return _0x360de5[_0x386e('0x24')]['destroy']({'where':{'ChanSpyId':_0x4a9828['id']}})['then'](function(){_0x3c5fc1();})[_0x386e('0x20')](function(_0x15a9fb){_0x3c5fc1(_0x15a9fb);});}}});};