Built motion from commit (unavailable).|2.5.30
[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 _0x9532=['User','findAll','agent','then','catch','models','define','VoiceChanSpy','voice_chanspy','VoiceExtension','bulkCreate','destroy','lodash','util','bluebird','./voiceChanSpy.attributes','context','format','%s%s','push','chanspy','record','merge','${UNIQUEID}.%s,a','recordingFormat','auth','join','StopMixMonitor','length','concat','internal','name'];(function(_0x1d1779,_0x284147){var _0x2377e9=function(_0x299f6f){while(--_0x299f6f){_0x1d1779['push'](_0x1d1779['shift']());}};_0x2377e9(++_0x284147);}(_0x9532,0x8c));var _0x2953=function(_0x407c80,_0x281267){_0x407c80=_0x407c80-0x0;var _0x3bf273=_0x9532[_0x407c80];return _0x3bf273;};'use strict';var _=require(_0x2953('0x0'));var util=require(_0x2953('0x1'));var BPromise=require(_0x2953('0x2'));var attributes=require(_0x2953('0x3'));var getUserApplications=function(_0x3f89d9,_0xabd12e,_0x51aa45){var _0xd41242=0x1;var _0x3058d6=[];var _0x5dceda={'context':_0xabd12e[_0x2953('0x4')]||'from-sip','exten':util[_0x2953('0x5')](_0x2953('0x6'),_0x3f89d9['prefix'],_0x51aa45),'type':'system','isApp':![],'ChanSpyId':_0x3f89d9['id'],'UserId':_0xabd12e['id']};_0x3058d6[_0x2953('0x7')](_['merge']({'app':'Set','appdata':util[_0x2953('0x5')]('CDR(type)=%s',_0x2953('0x8')),'priority':_0xd41242++},_0x5dceda));if(_0x3f89d9[_0x2953('0x9')]){_0x3058d6[_0x2953('0x7')](_[_0x2953('0xa')]({'app':'MixMonitor','appdata':util[_0x2953('0x5')](_0x2953('0xb'),_0x3f89d9[_0x2953('0xc')]),'priority':_0xd41242++},_0x5dceda));}if(_0x3f89d9[_0x2953('0xd')]){_0x3058d6[_0x2953('0x7')](_[_0x2953('0xa')]({'app':'Authenticate','appdata':_0x3f89d9['password'],'priority':_0xd41242++},_0x5dceda));}_0x3058d6[_0x2953('0x7')](_[_0x2953('0xa')]({'app':'ChanSpy','appdata':util[_0x2953('0x5')]('SIP/%s,%s',_0xabd12e['name'],_0x3f89d9['options']?_0x3f89d9['options'][_0x2953('0xe')](''):''),'priority':_0xd41242++},_0x5dceda));if(_0x3f89d9[_0x2953('0x9')]){_0x3058d6[_0x2953('0x7')](_[_0x2953('0xa')]({'app':_0x2953('0xf'),'priority':_0xd41242++},_0x5dceda));}return _0x3058d6;};var getChanSpyApplications=function(_0x4b9da7,_0xc374c0){var _0x446918=[];for(var _0x341e73=0x0,_0x1f58fe=0x1;_0x341e73<_0xc374c0[_0x2953('0x10')];_0x341e73++,_0x1f58fe=0x1){_0x446918=_0x446918[_0x2953('0x11')](getUserApplications(_0x4b9da7,_0xc374c0[_0x341e73],_0xc374c0[_0x341e73][_0x2953('0x12')]));if(_0xc374c0[_0x341e73][_0x2953('0x12')]!=_0xc374c0[_0x341e73]['name']){_0x446918=_0x446918[_0x2953('0x11')](getUserApplications(_0x4b9da7,_0xc374c0[_0x341e73],_0xc374c0[_0x341e73][_0x2953('0x13')]));}}return _0x446918;};var getChanSpyPromise=function(_0x9cce01,_0x288d6c){return new BPromise(function(_0x2f303f,_0x43b46a){return _0x9cce01[_0x2953('0x14')][_0x2953('0x15')]({'attributes':['id',_0x2953('0x13'),_0x2953('0x12')],'where':{'role':_0x2953('0x16'),'chanspy':!![]},'raw':!![]})[_0x2953('0x17')](function(_0x258c71){if(_0x258c71){return _0x2f303f(getChanSpyApplications(_0x288d6c,_0x258c71));}return _0x2f303f([]);})[_0x2953('0x18')](function(_0x142beb){_0x43b46a(_0x142beb);});});};module['exports']=function(_0x1a1240,_0x12f128){var _0x5a83ea=_0x1a1240[_0x2953('0x19')];return _0x1a1240[_0x2953('0x1a')](_0x2953('0x1b'),attributes,{'tableName':_0x2953('0x1c'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x3b5666,_0x2ff1eb,_0x1ef000){return getChanSpyPromise(_0x5a83ea,_0x3b5666)[_0x2953('0x17')](function(_0x3a7ae5){if(_0x3a7ae5&&_0x3a7ae5[_0x2953('0x10')]){return _0x5a83ea[_0x2953('0x1d')]['bulkCreate'](_0x3a7ae5);}})[_0x2953('0x17')](function(){_0x1ef000();})['catch'](function(_0x21e221){_0x1ef000(_0x21e221);});},'afterUpdate':function(_0x26ed66,_0x4721af,_0x763403){return _0x5a83ea['VoiceExtension']['destroy']({'where':{'ChanSpyId':_0x26ed66['id']}})[_0x2953('0x17')](function(){return getChanSpyPromise(_0x5a83ea,_0x26ed66);})[_0x2953('0x17')](function(_0x2309c6){if(_0x2309c6&&_0x2309c6[_0x2953('0x10')]){return _0x5a83ea[_0x2953('0x1d')][_0x2953('0x1e')](_0x2309c6);}})[_0x2953('0x17')](function(){_0x763403();})['catch'](function(_0x47a6cb){_0x763403(_0x47a6cb);});},'afterDestroy':function(_0x55916f,_0x5e3cc7,_0x2bfce7){return _0x5a83ea[_0x2953('0x1d')][_0x2953('0x1f')]({'where':{'ChanSpyId':_0x55916f['id']}})['then'](function(){_0x2bfce7();})[_0x2953('0x18')](function(_0x25fb1c){_0x2bfce7(_0x25fb1c);});}}});};