a987e6cec2c3fcb3694c25336ade3ab2a5648096
[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 _0xa436=['password','ChanSpy','SIP/%s,%s','name','options','join','StopMixMonitor','length','concat','internal','User','agent','catch','exports','models','define','voice_chanspy','then','VoiceExtension','bulkCreate','destroy','bluebird','./voiceChanSpy.attributes','context','from-sip','format','%s%s','prefix','system','push','Set','CDR(type)=%s','chanspy','record','merge','MixMonitor','${UNIQUEID}.%s,a','recordingFormat','Authenticate'];(function(_0x3e343d,_0x5d804d){var _0x424612=function(_0x61aed1){while(--_0x61aed1){_0x3e343d['push'](_0x3e343d['shift']());}};_0x424612(++_0x5d804d);}(_0xa436,0x174));var _0x6a43=function(_0x199c6e,_0x1c3613){_0x199c6e=_0x199c6e-0x0;var _0x50f11e=_0xa436[_0x199c6e];return _0x50f11e;};'use strict';var _=require('lodash');var util=require('util');var BPromise=require(_0x6a43('0x0'));var attributes=require(_0x6a43('0x1'));var getUserApplications=function(_0x2becd2,_0x4f6eda,_0x1dc7ab){var _0x160164=0x1;var _0x6d1e47=[];var _0x8e7d09={'context':_0x4f6eda[_0x6a43('0x2')]||_0x6a43('0x3'),'exten':util[_0x6a43('0x4')](_0x6a43('0x5'),_0x2becd2[_0x6a43('0x6')],_0x1dc7ab),'type':_0x6a43('0x7'),'isApp':![],'ChanSpyId':_0x2becd2['id'],'UserId':_0x4f6eda['id']};_0x6d1e47[_0x6a43('0x8')](_['merge']({'app':_0x6a43('0x9'),'appdata':util[_0x6a43('0x4')](_0x6a43('0xa'),_0x6a43('0xb')),'priority':_0x160164++},_0x8e7d09));if(_0x2becd2[_0x6a43('0xc')]){_0x6d1e47['push'](_[_0x6a43('0xd')]({'app':_0x6a43('0xe'),'appdata':util['format'](_0x6a43('0xf'),_0x2becd2[_0x6a43('0x10')]),'priority':_0x160164++},_0x8e7d09));}if(_0x2becd2['auth']){_0x6d1e47[_0x6a43('0x8')](_['merge']({'app':_0x6a43('0x11'),'appdata':_0x2becd2[_0x6a43('0x12')],'priority':_0x160164++},_0x8e7d09));}_0x6d1e47[_0x6a43('0x8')](_['merge']({'app':_0x6a43('0x13'),'appdata':util[_0x6a43('0x4')](_0x6a43('0x14'),_0x4f6eda[_0x6a43('0x15')],_0x2becd2[_0x6a43('0x16')]?_0x2becd2[_0x6a43('0x16')][_0x6a43('0x17')](''):''),'priority':_0x160164++},_0x8e7d09));if(_0x2becd2[_0x6a43('0xc')]){_0x6d1e47[_0x6a43('0x8')](_[_0x6a43('0xd')]({'app':_0x6a43('0x18'),'priority':_0x160164++},_0x8e7d09));}return _0x6d1e47;};var getChanSpyApplications=function(_0x5463fe,_0x4b39bb){var _0x39d30b=[];for(var _0x29f1c1=0x0,_0x224120=0x1;_0x29f1c1<_0x4b39bb[_0x6a43('0x19')];_0x29f1c1++,_0x224120=0x1){_0x39d30b=_0x39d30b[_0x6a43('0x1a')](getUserApplications(_0x5463fe,_0x4b39bb[_0x29f1c1],_0x4b39bb[_0x29f1c1][_0x6a43('0x1b')]));if(_0x4b39bb[_0x29f1c1][_0x6a43('0x1b')]!=_0x4b39bb[_0x29f1c1]['name']){_0x39d30b=_0x39d30b['concat'](getUserApplications(_0x5463fe,_0x4b39bb[_0x29f1c1],_0x4b39bb[_0x29f1c1]['name']));}}return _0x39d30b;};var getChanSpyPromise=function(_0x6cd8af,_0x288688){return new BPromise(function(_0x5cf074,_0x5ef8ef){return _0x6cd8af[_0x6a43('0x1c')]['findAll']({'attributes':['id',_0x6a43('0x15'),_0x6a43('0x1b')],'where':{'role':_0x6a43('0x1d'),'chanspy':!![]},'raw':!![]})['then'](function(_0x59f275){if(_0x59f275){return _0x5cf074(getChanSpyApplications(_0x288688,_0x59f275));}return _0x5cf074([]);})[_0x6a43('0x1e')](function(_0x1c3ae1){_0x5ef8ef(_0x1c3ae1);});});};module[_0x6a43('0x1f')]=function(_0x1ae959,_0x2a483b){var _0x36f87b=_0x1ae959[_0x6a43('0x20')];return _0x1ae959[_0x6a43('0x21')]('VoiceChanSpy',attributes,{'tableName':_0x6a43('0x22'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x2aafc7,_0x47600f,_0x27b997){return getChanSpyPromise(_0x36f87b,_0x2aafc7)[_0x6a43('0x23')](function(_0x1f4a51){if(_0x1f4a51&&_0x1f4a51['length']){return _0x36f87b[_0x6a43('0x24')][_0x6a43('0x25')](_0x1f4a51);}})[_0x6a43('0x23')](function(){_0x27b997();})['catch'](function(_0x295757){_0x27b997(_0x295757);});},'afterUpdate':function(_0x1befab,_0x55ece1,_0x67a290){return _0x36f87b[_0x6a43('0x24')][_0x6a43('0x26')]({'where':{'ChanSpyId':_0x1befab['id']}})['then'](function(){return getChanSpyPromise(_0x36f87b,_0x1befab);})[_0x6a43('0x23')](function(_0x591e51){if(_0x591e51&&_0x591e51[_0x6a43('0x19')]){return _0x36f87b[_0x6a43('0x24')][_0x6a43('0x25')](_0x591e51);}})['then'](function(){_0x67a290();})[_0x6a43('0x1e')](function(_0x6e6926){_0x67a290(_0x6e6926);});},'afterDestroy':function(_0x48d21a,_0xabf99a,_0x41a861){return _0x36f87b[_0x6a43('0x24')][_0x6a43('0x26')]({'where':{'ChanSpyId':_0x48d21a['id']}})[_0x6a43('0x23')](function(){_0x41a861();})[_0x6a43('0x1e')](function(_0x1fd359){_0x41a861(_0x1fd359);});}}});};