Built motion from commit b5413ace.|2.6.9
[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 _0xf1a2=['destroy','lodash','util','bluebird','format','%s%s','prefix','system','push','Set','CDR(type)=%s','chanspy','record','merge','MixMonitor','${UNIQUEID}.%s,a','recordingFormat','auth','Authenticate','password','ChanSpy','SIP/%s,%s','name','options','StopMixMonitor','length','internal','User','findAll','agent','then','catch','exports','define','VoiceChanSpy','voice_chanspy','VoiceExtension','bulkCreate'];(function(_0x1a6967,_0x95d92b){var _0x952e59=function(_0x6b63a9){while(--_0x6b63a9){_0x1a6967['push'](_0x1a6967['shift']());}};_0x952e59(++_0x95d92b);}(_0xf1a2,0x1a3));var _0x2f1a=function(_0x3ae5af,_0x45d0f2){_0x3ae5af=_0x3ae5af-0x0;var _0x543d0f=_0xf1a2[_0x3ae5af];return _0x543d0f;};'use strict';var _=require(_0x2f1a('0x0'));var util=require(_0x2f1a('0x1'));var BPromise=require(_0x2f1a('0x2'));var attributes=require('./voiceChanSpy.attributes');var getUserApplications=function(_0x36ef95,_0x114cc1,_0x4a77d6){var _0x271e5a=0x1;var _0xdb1da0=[];var _0x26e1f4={'context':_0x114cc1['context']||'from-sip','exten':util[_0x2f1a('0x3')](_0x2f1a('0x4'),_0x36ef95[_0x2f1a('0x5')],_0x4a77d6),'type':_0x2f1a('0x6'),'isApp':![],'ChanSpyId':_0x36ef95['id'],'UserId':_0x114cc1['id']};_0xdb1da0[_0x2f1a('0x7')](_['merge']({'app':_0x2f1a('0x8'),'appdata':util['format'](_0x2f1a('0x9'),_0x2f1a('0xa')),'priority':_0x271e5a++},_0x26e1f4));if(_0x36ef95[_0x2f1a('0xb')]){_0xdb1da0[_0x2f1a('0x7')](_[_0x2f1a('0xc')]({'app':_0x2f1a('0xd'),'appdata':util[_0x2f1a('0x3')](_0x2f1a('0xe'),_0x36ef95[_0x2f1a('0xf')]),'priority':_0x271e5a++},_0x26e1f4));}if(_0x36ef95[_0x2f1a('0x10')]){_0xdb1da0[_0x2f1a('0x7')](_[_0x2f1a('0xc')]({'app':_0x2f1a('0x11'),'appdata':_0x36ef95[_0x2f1a('0x12')],'priority':_0x271e5a++},_0x26e1f4));}_0xdb1da0['push'](_[_0x2f1a('0xc')]({'app':_0x2f1a('0x13'),'appdata':util[_0x2f1a('0x3')](_0x2f1a('0x14'),_0x114cc1[_0x2f1a('0x15')],_0x36ef95[_0x2f1a('0x16')]?_0x36ef95[_0x2f1a('0x16')]['join'](''):''),'priority':_0x271e5a++},_0x26e1f4));if(_0x36ef95['record']){_0xdb1da0[_0x2f1a('0x7')](_[_0x2f1a('0xc')]({'app':_0x2f1a('0x17'),'priority':_0x271e5a++},_0x26e1f4));}return _0xdb1da0;};var getChanSpyApplications=function(_0x38549a,_0x5bf9e5){var _0x112d09=[];for(var _0x2072c6=0x0,_0x36c681=0x1;_0x2072c6<_0x5bf9e5[_0x2f1a('0x18')];_0x2072c6++,_0x36c681=0x1){_0x112d09=_0x112d09['concat'](getUserApplications(_0x38549a,_0x5bf9e5[_0x2072c6],_0x5bf9e5[_0x2072c6][_0x2f1a('0x19')]));if(_0x5bf9e5[_0x2072c6][_0x2f1a('0x19')]!=_0x5bf9e5[_0x2072c6]['name']){_0x112d09=_0x112d09['concat'](getUserApplications(_0x38549a,_0x5bf9e5[_0x2072c6],_0x5bf9e5[_0x2072c6][_0x2f1a('0x15')]));}}return _0x112d09;};var getChanSpyPromise=function(_0x40e301,_0x3af1d1){return new BPromise(function(_0x22a75c,_0x862f78){return _0x40e301[_0x2f1a('0x1a')][_0x2f1a('0x1b')]({'attributes':['id',_0x2f1a('0x15'),_0x2f1a('0x19')],'where':{'role':_0x2f1a('0x1c'),'chanspy':!![]},'raw':!![]})[_0x2f1a('0x1d')](function(_0x4438ac){if(_0x4438ac){return _0x22a75c(getChanSpyApplications(_0x3af1d1,_0x4438ac));}return _0x22a75c([]);})[_0x2f1a('0x1e')](function(_0x185b60){_0x862f78(_0x185b60);});});};module[_0x2f1a('0x1f')]=function(_0x59cef2,_0xec9428){var _0x4505cd=_0x59cef2['models'];return _0x59cef2[_0x2f1a('0x20')](_0x2f1a('0x21'),attributes,{'tableName':_0x2f1a('0x22'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0xabe870,_0x1eca15,_0x323035){return getChanSpyPromise(_0x4505cd,_0xabe870)['then'](function(_0x1fec5e){if(_0x1fec5e&&_0x1fec5e[_0x2f1a('0x18')]){return _0x4505cd[_0x2f1a('0x23')][_0x2f1a('0x24')](_0x1fec5e);}})[_0x2f1a('0x1d')](function(){_0x323035();})['catch'](function(_0x570279){_0x323035(_0x570279);});},'afterUpdate':function(_0x52cd6f,_0x10bf26,_0xd3217a){return _0x4505cd['VoiceExtension'][_0x2f1a('0x25')]({'where':{'ChanSpyId':_0x52cd6f['id']}})[_0x2f1a('0x1d')](function(){return getChanSpyPromise(_0x4505cd,_0x52cd6f);})[_0x2f1a('0x1d')](function(_0x2fa4ca){if(_0x2fa4ca&&_0x2fa4ca[_0x2f1a('0x18')]){return _0x4505cd[_0x2f1a('0x23')]['bulkCreate'](_0x2fa4ca);}})['then'](function(){_0xd3217a();})[_0x2f1a('0x1e')](function(_0x52576c){_0xd3217a(_0x52576c);});},'afterDestroy':function(_0x393b3e,_0x1d23fc,_0x3aa53b){return _0x4505cd[_0x2f1a('0x23')][_0x2f1a('0x25')]({'where':{'ChanSpyId':_0x393b3e['id']}})['then'](function(){_0x3aa53b();})[_0x2f1a('0x1e')](function(_0x22692c){_0x3aa53b(_0x22692c);});}}});};