Built motion from commit (unavailable).|2.4.4
[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 _0x4a3a=['exports','models','define','VoiceChanSpy','voice_chanspy','destroy','VoiceExtension','bulkCreate','lodash','util','bluebird','./voiceChanSpy.attributes','context','from-sip','%s%s','prefix','system','push','merge','Set','format','CDR(type)=%s','chanspy','record','${UNIQUEID}.%s,ab','auth','Authenticate','password','SIP/%s,%s','name','options','join','length','concat','internal','findAll','agent','then','catch'];(function(_0x3dbd54,_0x2dc6f5){var _0x3adad0=function(_0x30bdfa){while(--_0x30bdfa){_0x3dbd54['push'](_0x3dbd54['shift']());}};_0x3adad0(++_0x2dc6f5);}(_0x4a3a,0x140));var _0xa4a3=function(_0x2b6c5b,_0x123bcc){_0x2b6c5b=_0x2b6c5b-0x0;var _0x233ba8=_0x4a3a[_0x2b6c5b];return _0x233ba8;};'use strict';var _=require(_0xa4a3('0x0'));var util=require(_0xa4a3('0x1'));var BPromise=require(_0xa4a3('0x2'));var attributes=require(_0xa4a3('0x3'));var getUserApplications=function(_0x210ae5,_0x573686,_0x10094b){var _0x4f2ff4=0x1;var _0x3a66ad=[];var _0x5d48bc={'context':_0x573686[_0xa4a3('0x4')]||_0xa4a3('0x5'),'exten':util['format'](_0xa4a3('0x6'),_0x210ae5[_0xa4a3('0x7')],_0x10094b),'type':_0xa4a3('0x8'),'isApp':![],'ChanSpyId':_0x210ae5['id'],'UserId':_0x573686['id']};_0x3a66ad[_0xa4a3('0x9')](_[_0xa4a3('0xa')]({'app':_0xa4a3('0xb'),'appdata':util[_0xa4a3('0xc')](_0xa4a3('0xd'),_0xa4a3('0xe')),'priority':_0x4f2ff4++},_0x5d48bc));if(_0x210ae5[_0xa4a3('0xf')]){_0x3a66ad[_0xa4a3('0x9')](_[_0xa4a3('0xa')]({'app':'MixMonitor','appdata':util[_0xa4a3('0xc')](_0xa4a3('0x10'),_0x210ae5['recordingFormat']),'priority':_0x4f2ff4++},_0x5d48bc));}if(_0x210ae5[_0xa4a3('0x11')]){_0x3a66ad['push'](_['merge']({'app':_0xa4a3('0x12'),'appdata':_0x210ae5[_0xa4a3('0x13')],'priority':_0x4f2ff4++},_0x5d48bc));}_0x3a66ad[_0xa4a3('0x9')](_[_0xa4a3('0xa')]({'app':'ChanSpy','appdata':util[_0xa4a3('0xc')](_0xa4a3('0x14'),_0x573686[_0xa4a3('0x15')],_0x210ae5[_0xa4a3('0x16')]?_0x210ae5[_0xa4a3('0x16')][_0xa4a3('0x17')](''):''),'priority':_0x4f2ff4++},_0x5d48bc));if(_0x210ae5[_0xa4a3('0xf')]){_0x3a66ad[_0xa4a3('0x9')](_[_0xa4a3('0xa')]({'app':'StopMixMonitor','priority':_0x4f2ff4++},_0x5d48bc));}return _0x3a66ad;};var getChanSpyApplications=function(_0x40b0a5,_0xb17e96){var _0x2e672b=[];for(var _0x5461d5=0x0,_0x1505f9=0x1;_0x5461d5<_0xb17e96[_0xa4a3('0x18')];_0x5461d5++,_0x1505f9=0x1){_0x2e672b=_0x2e672b[_0xa4a3('0x19')](getUserApplications(_0x40b0a5,_0xb17e96[_0x5461d5],_0xb17e96[_0x5461d5][_0xa4a3('0x1a')]));if(_0xb17e96[_0x5461d5][_0xa4a3('0x1a')]!=_0xb17e96[_0x5461d5][_0xa4a3('0x15')]){_0x2e672b=_0x2e672b['concat'](getUserApplications(_0x40b0a5,_0xb17e96[_0x5461d5],_0xb17e96[_0x5461d5]['name']));}}return _0x2e672b;};var getChanSpyPromise=function(_0x558ac3,_0xe49d88){return new BPromise(function(_0x480504,_0x528ee5){return _0x558ac3['User'][_0xa4a3('0x1b')]({'attributes':['id','name',_0xa4a3('0x1a')],'where':{'role':_0xa4a3('0x1c'),'chanspy':!![]},'raw':!![]})[_0xa4a3('0x1d')](function(_0x2482fa){if(_0x2482fa){return _0x480504(getChanSpyApplications(_0xe49d88,_0x2482fa));}return _0x480504([]);})[_0xa4a3('0x1e')](function(_0x48c53e){_0x528ee5(_0x48c53e);});});};module[_0xa4a3('0x1f')]=function(_0x319fb8,_0x954d02){var _0x48340e=_0x319fb8[_0xa4a3('0x20')];return _0x319fb8[_0xa4a3('0x21')](_0xa4a3('0x22'),attributes,{'tableName':_0xa4a3('0x23'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x5273de,_0x23b257,_0x45202d){return getChanSpyPromise(_0x48340e,_0x5273de)['then'](function(_0x38c7a9){if(_0x38c7a9&&_0x38c7a9[_0xa4a3('0x18')]){return _0x48340e['VoiceExtension']['bulkCreate'](_0x38c7a9);}})[_0xa4a3('0x1d')](function(){_0x45202d();})[_0xa4a3('0x1e')](function(_0x21baf8){_0x45202d(_0x21baf8);});},'afterUpdate':function(_0x57e4f9,_0x1f10d4,_0xe730b8){return _0x48340e['VoiceExtension'][_0xa4a3('0x24')]({'where':{'ChanSpyId':_0x57e4f9['id']}})['then'](function(){return getChanSpyPromise(_0x48340e,_0x57e4f9);})[_0xa4a3('0x1d')](function(_0x45cb98){if(_0x45cb98&&_0x45cb98[_0xa4a3('0x18')]){return _0x48340e[_0xa4a3('0x25')][_0xa4a3('0x26')](_0x45cb98);}})[_0xa4a3('0x1d')](function(){_0xe730b8();})['catch'](function(_0x58c323){_0xe730b8(_0x58c323);});},'afterDestroy':function(_0x3aee69,_0x2ad2e2,_0x48554c){return _0x48340e['VoiceExtension'][_0xa4a3('0x24')]({'where':{'ChanSpyId':_0x3aee69['id']}})['then'](function(){_0x48554c();})[_0xa4a3('0x1e')](function(_0x5b585f){_0x48554c(_0x5b585f);});}}});};