01f69017fa643a032c3b4f1f71f995233b9de495
[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 _0x5f01=['agent','then','catch','exports','models','define','voice_chanspy','VoiceExtension','bulkCreate','destroy','lodash','util','bluebird','./voiceChanSpy.attributes','format','prefix','system','merge','Set','CDR(type)=%s','record','MixMonitor','recordingFormat','auth','push','Authenticate','password','ChanSpy','options','join','StopMixMonitor','length','concat','internal','name','User','findAll'];(function(_0x2ef644,_0x2ab0ff){var _0x11f00e=function(_0x32983a){while(--_0x32983a){_0x2ef644['push'](_0x2ef644['shift']());}};_0x11f00e(++_0x2ab0ff);}(_0x5f01,0x9e));var _0x15f0=function(_0x240bcd,_0x15564f){_0x240bcd=_0x240bcd-0x0;var _0x4cda5e=_0x5f01[_0x240bcd];return _0x4cda5e;};'use strict';var _=require(_0x15f0('0x0'));var util=require(_0x15f0('0x1'));var BPromise=require(_0x15f0('0x2'));var attributes=require(_0x15f0('0x3'));var getUserApplications=function(_0x4cc67a,_0x450e9a,_0x1e3510){var _0x1ceb2a=0x1;var _0x3f0420=[];var _0x561bf2={'context':_0x450e9a['context']||'from-sip','exten':util[_0x15f0('0x4')]('%s%s',_0x4cc67a[_0x15f0('0x5')],_0x1e3510),'type':_0x15f0('0x6'),'isApp':![],'ChanSpyId':_0x4cc67a['id'],'UserId':_0x450e9a['id']};_0x3f0420['push'](_[_0x15f0('0x7')]({'app':_0x15f0('0x8'),'appdata':util[_0x15f0('0x4')](_0x15f0('0x9'),'chanspy'),'priority':_0x1ceb2a++},_0x561bf2));if(_0x4cc67a[_0x15f0('0xa')]){_0x3f0420['push'](_[_0x15f0('0x7')]({'app':_0x15f0('0xb'),'appdata':util[_0x15f0('0x4')]('${UNIQUEID}.%s,a',_0x4cc67a[_0x15f0('0xc')]),'priority':_0x1ceb2a++},_0x561bf2));}if(_0x4cc67a[_0x15f0('0xd')]){_0x3f0420[_0x15f0('0xe')](_[_0x15f0('0x7')]({'app':_0x15f0('0xf'),'appdata':_0x4cc67a[_0x15f0('0x10')],'priority':_0x1ceb2a++},_0x561bf2));}_0x3f0420[_0x15f0('0xe')](_[_0x15f0('0x7')]({'app':_0x15f0('0x11'),'appdata':util[_0x15f0('0x4')]('SIP/%s,%s',_0x450e9a['name'],_0x4cc67a[_0x15f0('0x12')]?_0x4cc67a[_0x15f0('0x12')][_0x15f0('0x13')](''):''),'priority':_0x1ceb2a++},_0x561bf2));if(_0x4cc67a['record']){_0x3f0420[_0x15f0('0xe')](_[_0x15f0('0x7')]({'app':_0x15f0('0x14'),'priority':_0x1ceb2a++},_0x561bf2));}return _0x3f0420;};var getChanSpyApplications=function(_0x35d95d,_0x56b539){var _0x12661f=[];for(var _0x34fd48=0x0,_0x15c4a2=0x1;_0x34fd48<_0x56b539[_0x15f0('0x15')];_0x34fd48++,_0x15c4a2=0x1){_0x12661f=_0x12661f[_0x15f0('0x16')](getUserApplications(_0x35d95d,_0x56b539[_0x34fd48],_0x56b539[_0x34fd48][_0x15f0('0x17')]));if(_0x56b539[_0x34fd48]['internal']!=_0x56b539[_0x34fd48]['name']){_0x12661f=_0x12661f[_0x15f0('0x16')](getUserApplications(_0x35d95d,_0x56b539[_0x34fd48],_0x56b539[_0x34fd48][_0x15f0('0x18')]));}}return _0x12661f;};var getChanSpyPromise=function(_0x4970cb,_0x58d870){return new BPromise(function(_0x3679c3,_0x20b55a){return _0x4970cb[_0x15f0('0x19')][_0x15f0('0x1a')]({'attributes':['id',_0x15f0('0x18'),'internal'],'where':{'role':_0x15f0('0x1b'),'chanspy':!![]},'raw':!![]})[_0x15f0('0x1c')](function(_0x1e6475){if(_0x1e6475){return _0x3679c3(getChanSpyApplications(_0x58d870,_0x1e6475));}return _0x3679c3([]);})[_0x15f0('0x1d')](function(_0x42e5ea){_0x20b55a(_0x42e5ea);});});};module[_0x15f0('0x1e')]=function(_0x64eb08,_0x1b1417){var _0x30ebf6=_0x64eb08[_0x15f0('0x1f')];return _0x64eb08[_0x15f0('0x20')]('VoiceChanSpy',attributes,{'tableName':_0x15f0('0x21'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x37385c,_0x508400,_0xa2b75a){return getChanSpyPromise(_0x30ebf6,_0x37385c)[_0x15f0('0x1c')](function(_0x183ba0){if(_0x183ba0&&_0x183ba0[_0x15f0('0x15')]){return _0x30ebf6[_0x15f0('0x22')][_0x15f0('0x23')](_0x183ba0);}})['then'](function(){_0xa2b75a();})['catch'](function(_0x201b9b){_0xa2b75a(_0x201b9b);});},'afterUpdate':function(_0x5bef94,_0x435b24,_0xcf8d78){return _0x30ebf6[_0x15f0('0x22')][_0x15f0('0x24')]({'where':{'ChanSpyId':_0x5bef94['id']}})[_0x15f0('0x1c')](function(){return getChanSpyPromise(_0x30ebf6,_0x5bef94);})[_0x15f0('0x1c')](function(_0x19ac04){if(_0x19ac04&&_0x19ac04[_0x15f0('0x15')]){return _0x30ebf6[_0x15f0('0x22')]['bulkCreate'](_0x19ac04);}})[_0x15f0('0x1c')](function(){_0xcf8d78();})['catch'](function(_0x303948){_0xcf8d78(_0x303948);});},'afterDestroy':function(_0x582b2c,_0x211652,_0x5e1625){return _0x30ebf6['VoiceExtension'][_0x15f0('0x24')]({'where':{'ChanSpyId':_0x582b2c['id']}})[_0x15f0('0x1c')](function(){_0x5e1625();})[_0x15f0('0x1d')](function(_0x3764d8){_0x5e1625(_0x3764d8);});}}});};