Built motion from commit 980b26c3.|2.6.29
[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 _0xdfff=['name','User','findAll','agent','then','catch','exports','define','VoiceChanSpy','VoiceExtension','bulkCreate','lodash','util','bluebird','./voiceChanSpy.attributes','context','from-sip','format','%s%s','prefix','push','merge','chanspy','record','${UNIQUEID}.%s,a','auth','password','ChanSpy','SIP/%s,%s','options','join','StopMixMonitor','length','concat','internal'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0xdfff,0x169));var _0xfdff=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xdfff[_0x3dd15e];return _0x231fd0;};'use strict';var _=require(_0xfdff('0x0'));var util=require(_0xfdff('0x1'));var BPromise=require(_0xfdff('0x2'));var attributes=require(_0xfdff('0x3'));var getUserApplications=function(_0x7fb161,_0x5e3fb0,_0x41d041){var _0x2ed92f=0x1;var _0x391b14=[];var _0x1e8c63={'context':_0x5e3fb0[_0xfdff('0x4')]||_0xfdff('0x5'),'exten':util[_0xfdff('0x6')](_0xfdff('0x7'),_0x7fb161[_0xfdff('0x8')],_0x41d041),'type':'system','isApp':![],'ChanSpyId':_0x7fb161['id'],'UserId':_0x5e3fb0['id']};_0x391b14[_0xfdff('0x9')](_[_0xfdff('0xa')]({'app':'Set','appdata':util[_0xfdff('0x6')]('CDR(type)=%s',_0xfdff('0xb')),'priority':_0x2ed92f++},_0x1e8c63));if(_0x7fb161[_0xfdff('0xc')]){_0x391b14[_0xfdff('0x9')](_[_0xfdff('0xa')]({'app':'MixMonitor','appdata':util[_0xfdff('0x6')](_0xfdff('0xd'),_0x7fb161['recordingFormat']),'priority':_0x2ed92f++},_0x1e8c63));}if(_0x7fb161[_0xfdff('0xe')]){_0x391b14[_0xfdff('0x9')](_[_0xfdff('0xa')]({'app':'Authenticate','appdata':_0x7fb161[_0xfdff('0xf')],'priority':_0x2ed92f++},_0x1e8c63));}_0x391b14[_0xfdff('0x9')](_['merge']({'app':_0xfdff('0x10'),'appdata':util[_0xfdff('0x6')](_0xfdff('0x11'),_0x5e3fb0['name'],_0x7fb161[_0xfdff('0x12')]?_0x7fb161[_0xfdff('0x12')][_0xfdff('0x13')](''):''),'priority':_0x2ed92f++},_0x1e8c63));if(_0x7fb161[_0xfdff('0xc')]){_0x391b14['push'](_[_0xfdff('0xa')]({'app':_0xfdff('0x14'),'priority':_0x2ed92f++},_0x1e8c63));}return _0x391b14;};var getChanSpyApplications=function(_0x4a6312,_0x580ce8){var _0x28e645=[];for(var _0x560869=0x0,_0x48a245=0x1;_0x560869<_0x580ce8[_0xfdff('0x15')];_0x560869++,_0x48a245=0x1){_0x28e645=_0x28e645[_0xfdff('0x16')](getUserApplications(_0x4a6312,_0x580ce8[_0x560869],_0x580ce8[_0x560869][_0xfdff('0x17')]));if(_0x580ce8[_0x560869][_0xfdff('0x17')]!=_0x580ce8[_0x560869][_0xfdff('0x18')]){_0x28e645=_0x28e645['concat'](getUserApplications(_0x4a6312,_0x580ce8[_0x560869],_0x580ce8[_0x560869][_0xfdff('0x18')]));}}return _0x28e645;};var getChanSpyPromise=function(_0x3dd80a,_0x338e51){return new BPromise(function(_0x516eb1,_0x2d17da){return _0x3dd80a[_0xfdff('0x19')][_0xfdff('0x1a')]({'attributes':['id','name','internal'],'where':{'role':_0xfdff('0x1b'),'chanspy':!![]},'raw':!![]})[_0xfdff('0x1c')](function(_0x5d9516){if(_0x5d9516){return _0x516eb1(getChanSpyApplications(_0x338e51,_0x5d9516));}return _0x516eb1([]);})[_0xfdff('0x1d')](function(_0x340a89){_0x2d17da(_0x340a89);});});};module[_0xfdff('0x1e')]=function(_0x469591,_0x5478ca){var _0x1f0d1d=_0x469591['models'];return _0x469591[_0xfdff('0x1f')](_0xfdff('0x20'),attributes,{'tableName':'voice_chanspy','paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x24f0ba,_0xa23216,_0x160413){return getChanSpyPromise(_0x1f0d1d,_0x24f0ba)['then'](function(_0x12735d){if(_0x12735d&&_0x12735d[_0xfdff('0x15')]){return _0x1f0d1d[_0xfdff('0x21')][_0xfdff('0x22')](_0x12735d);}})[_0xfdff('0x1c')](function(){_0x160413();})['catch'](function(_0x2bfc14){_0x160413(_0x2bfc14);});},'afterUpdate':function(_0x3ca8aa,_0x2c8033,_0x2a90bb){return _0x1f0d1d['VoiceExtension']['destroy']({'where':{'ChanSpyId':_0x3ca8aa['id']}})[_0xfdff('0x1c')](function(){return getChanSpyPromise(_0x1f0d1d,_0x3ca8aa);})['then'](function(_0x15bc5f){if(_0x15bc5f&&_0x15bc5f[_0xfdff('0x15')]){return _0x1f0d1d[_0xfdff('0x21')][_0xfdff('0x22')](_0x15bc5f);}})[_0xfdff('0x1c')](function(){_0x2a90bb();})[_0xfdff('0x1d')](function(_0x562d6b){_0x2a90bb(_0x562d6b);});},'afterDestroy':function(_0xfeae57,_0x422f44,_0x2d533c){return _0x1f0d1d[_0xfdff('0x21')]['destroy']({'where':{'ChanSpyId':_0xfeae57['id']}})['then'](function(){_0x2d533c();})[_0xfdff('0x1d')](function(_0x1780c){_0x2d533c(_0x1780c);});}}});};