Built motion from commit (unavailable).|2.3.95
[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 _0xc534=['StopMixMonitor','length','concat','internal','name','User','findAll','agent','then','catch','exports','models','define','VoiceChanSpy','voice_chanspy','VoiceExtension','destroy','bulkCreate','util','bluebird','context','from-sip','format','%s%s','prefix','system','push','merge','CDR(type)=%s','record','MixMonitor','${UNIQUEID}.%s,ab','recordingFormat','auth','Authenticate','password','ChanSpy','SIP/%s,%s','options','join'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xc534,0x1ca));var _0x4c53=function(_0x5beda8,_0x1e8554){_0x5beda8=_0x5beda8-0x0;var _0x2aa042=_0xc534[_0x5beda8];return _0x2aa042;};'use strict';var _=require('lodash');var util=require(_0x4c53('0x0'));var BPromise=require(_0x4c53('0x1'));var attributes=require('./voiceChanSpy.attributes');var getUserApplications=function(_0x3426ed,_0x1fb9d7,_0x1bb0cb){var _0x53bca0=0x1;var _0xd2f9d9=[];var _0x50f2d0={'context':_0x1fb9d7[_0x4c53('0x2')]||_0x4c53('0x3'),'exten':util[_0x4c53('0x4')](_0x4c53('0x5'),_0x3426ed[_0x4c53('0x6')],_0x1bb0cb),'type':_0x4c53('0x7'),'isApp':![],'ChanSpyId':_0x3426ed['id'],'UserId':_0x1fb9d7['id']};_0xd2f9d9[_0x4c53('0x8')](_[_0x4c53('0x9')]({'app':'Set','appdata':util[_0x4c53('0x4')](_0x4c53('0xa'),'chanspy'),'priority':_0x53bca0++},_0x50f2d0));if(_0x3426ed[_0x4c53('0xb')]){_0xd2f9d9[_0x4c53('0x8')](_[_0x4c53('0x9')]({'app':_0x4c53('0xc'),'appdata':util[_0x4c53('0x4')](_0x4c53('0xd'),_0x3426ed[_0x4c53('0xe')]),'priority':_0x53bca0++},_0x50f2d0));}if(_0x3426ed[_0x4c53('0xf')]){_0xd2f9d9[_0x4c53('0x8')](_[_0x4c53('0x9')]({'app':_0x4c53('0x10'),'appdata':_0x3426ed[_0x4c53('0x11')],'priority':_0x53bca0++},_0x50f2d0));}_0xd2f9d9[_0x4c53('0x8')](_[_0x4c53('0x9')]({'app':_0x4c53('0x12'),'appdata':util['format'](_0x4c53('0x13'),_0x1fb9d7['name'],_0x3426ed[_0x4c53('0x14')]?_0x3426ed[_0x4c53('0x14')][_0x4c53('0x15')](''):''),'priority':_0x53bca0++},_0x50f2d0));if(_0x3426ed[_0x4c53('0xb')]){_0xd2f9d9[_0x4c53('0x8')](_['merge']({'app':_0x4c53('0x16'),'priority':_0x53bca0++},_0x50f2d0));}return _0xd2f9d9;};var getChanSpyApplications=function(_0x199c42,_0x565f08){var _0x4705a3=[];for(var _0x880449=0x0,_0x19abd1=0x1;_0x880449<_0x565f08[_0x4c53('0x17')];_0x880449++,_0x19abd1=0x1){_0x4705a3=_0x4705a3[_0x4c53('0x18')](getUserApplications(_0x199c42,_0x565f08[_0x880449],_0x565f08[_0x880449][_0x4c53('0x19')]));if(_0x565f08[_0x880449][_0x4c53('0x19')]!=_0x565f08[_0x880449][_0x4c53('0x1a')]){_0x4705a3=_0x4705a3[_0x4c53('0x18')](getUserApplications(_0x199c42,_0x565f08[_0x880449],_0x565f08[_0x880449][_0x4c53('0x1a')]));}}return _0x4705a3;};var getChanSpyPromise=function(_0x3bf5a9,_0x50b4e1){return new BPromise(function(_0x8bf6a9,_0x48d72d){return _0x3bf5a9[_0x4c53('0x1b')][_0x4c53('0x1c')]({'attributes':['id',_0x4c53('0x1a'),_0x4c53('0x19')],'where':{'role':_0x4c53('0x1d'),'chanspy':!![]},'raw':!![]})[_0x4c53('0x1e')](function(_0x1fed39){if(_0x1fed39){return _0x8bf6a9(getChanSpyApplications(_0x50b4e1,_0x1fed39));}return _0x8bf6a9([]);})[_0x4c53('0x1f')](function(_0x4f139b){_0x48d72d(_0x4f139b);});});};module[_0x4c53('0x20')]=function(_0x1da82a,_0x2981e6){var _0xa620d7=_0x1da82a[_0x4c53('0x21')];return _0x1da82a[_0x4c53('0x22')](_0x4c53('0x23'),attributes,{'tableName':_0x4c53('0x24'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x2700df,_0x107788,_0x14fde2){return getChanSpyPromise(_0xa620d7,_0x2700df)[_0x4c53('0x1e')](function(_0x3e3576){if(_0x3e3576&&_0x3e3576[_0x4c53('0x17')]){return _0xa620d7[_0x4c53('0x25')]['bulkCreate'](_0x3e3576);}})[_0x4c53('0x1e')](function(){_0x14fde2();})[_0x4c53('0x1f')](function(_0x29fd50){_0x14fde2(_0x29fd50);});},'afterUpdate':function(_0x5ecebd,_0xea2a5d,_0x3be0ba){return _0xa620d7['VoiceExtension'][_0x4c53('0x26')]({'where':{'ChanSpyId':_0x5ecebd['id']}})[_0x4c53('0x1e')](function(){return getChanSpyPromise(_0xa620d7,_0x5ecebd);})[_0x4c53('0x1e')](function(_0x467646){if(_0x467646&&_0x467646[_0x4c53('0x17')]){return _0xa620d7[_0x4c53('0x25')][_0x4c53('0x27')](_0x467646);}})[_0x4c53('0x1e')](function(){_0x3be0ba();})[_0x4c53('0x1f')](function(_0x92c41){_0x3be0ba(_0x92c41);});},'afterDestroy':function(_0x5220b0,_0x3393f6,_0xcecee3){return _0xa620d7[_0x4c53('0x25')][_0x4c53('0x26')]({'where':{'ChanSpyId':_0x5220b0['id']}})[_0x4c53('0x1e')](function(){_0xcecee3();})['catch'](function(_0xc94987){_0xcecee3(_0xc94987);});}}});};