Built motion from commit (unavailable).|2.5.1
[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 _0x923c=['destroy','lodash','bluebird','./voiceChanSpy.attributes','context','format','%s%s','prefix','system','push','merge','Set','CDR(type)=%s','record','${UNIQUEID}.%s,a','recordingFormat','auth','Authenticate','ChanSpy','SIP/%s,%s','options','join','concat','internal','name','User','findAll','agent','then','catch','exports','models','define','voice_chanspy','length','VoiceExtension','bulkCreate'];(function(_0xdaf736,_0xd8c667){var _0x1090b3=function(_0x2eab2e){while(--_0x2eab2e){_0xdaf736['push'](_0xdaf736['shift']());}};_0x1090b3(++_0xd8c667);}(_0x923c,0x198));var _0xc923=function(_0x4042d2,_0x59eaab){_0x4042d2=_0x4042d2-0x0;var _0x4c1d22=_0x923c[_0x4042d2];return _0x4c1d22;};'use strict';var _=require(_0xc923('0x0'));var util=require('util');var BPromise=require(_0xc923('0x1'));var attributes=require(_0xc923('0x2'));var getUserApplications=function(_0x5e9cd8,_0x5aa456,_0x2adbf3){var _0x5d7572=0x1;var _0x5c3205=[];var _0x2274de={'context':_0x5aa456[_0xc923('0x3')]||'from-sip','exten':util[_0xc923('0x4')](_0xc923('0x5'),_0x5e9cd8[_0xc923('0x6')],_0x2adbf3),'type':_0xc923('0x7'),'isApp':![],'ChanSpyId':_0x5e9cd8['id'],'UserId':_0x5aa456['id']};_0x5c3205[_0xc923('0x8')](_[_0xc923('0x9')]({'app':_0xc923('0xa'),'appdata':util[_0xc923('0x4')](_0xc923('0xb'),'chanspy'),'priority':_0x5d7572++},_0x2274de));if(_0x5e9cd8[_0xc923('0xc')]){_0x5c3205[_0xc923('0x8')](_[_0xc923('0x9')]({'app':'MixMonitor','appdata':util[_0xc923('0x4')](_0xc923('0xd'),_0x5e9cd8[_0xc923('0xe')]),'priority':_0x5d7572++},_0x2274de));}if(_0x5e9cd8[_0xc923('0xf')]){_0x5c3205['push'](_[_0xc923('0x9')]({'app':_0xc923('0x10'),'appdata':_0x5e9cd8['password'],'priority':_0x5d7572++},_0x2274de));}_0x5c3205[_0xc923('0x8')](_[_0xc923('0x9')]({'app':_0xc923('0x11'),'appdata':util[_0xc923('0x4')](_0xc923('0x12'),_0x5aa456['name'],_0x5e9cd8[_0xc923('0x13')]?_0x5e9cd8[_0xc923('0x13')][_0xc923('0x14')](''):''),'priority':_0x5d7572++},_0x2274de));if(_0x5e9cd8[_0xc923('0xc')]){_0x5c3205[_0xc923('0x8')](_['merge']({'app':'StopMixMonitor','priority':_0x5d7572++},_0x2274de));}return _0x5c3205;};var getChanSpyApplications=function(_0x52ea65,_0x1055d9){var _0xbc1d98=[];for(var _0x16da76=0x0,_0x119e8d=0x1;_0x16da76<_0x1055d9['length'];_0x16da76++,_0x119e8d=0x1){_0xbc1d98=_0xbc1d98[_0xc923('0x15')](getUserApplications(_0x52ea65,_0x1055d9[_0x16da76],_0x1055d9[_0x16da76][_0xc923('0x16')]));if(_0x1055d9[_0x16da76][_0xc923('0x16')]!=_0x1055d9[_0x16da76][_0xc923('0x17')]){_0xbc1d98=_0xbc1d98[_0xc923('0x15')](getUserApplications(_0x52ea65,_0x1055d9[_0x16da76],_0x1055d9[_0x16da76][_0xc923('0x17')]));}}return _0xbc1d98;};var getChanSpyPromise=function(_0x2749a2,_0x497258){return new BPromise(function(_0x4401bd,_0x323d57){return _0x2749a2[_0xc923('0x18')][_0xc923('0x19')]({'attributes':['id',_0xc923('0x17'),_0xc923('0x16')],'where':{'role':_0xc923('0x1a'),'chanspy':!![]},'raw':!![]})[_0xc923('0x1b')](function(_0x375c3e){if(_0x375c3e){return _0x4401bd(getChanSpyApplications(_0x497258,_0x375c3e));}return _0x4401bd([]);})[_0xc923('0x1c')](function(_0x357247){_0x323d57(_0x357247);});});};module[_0xc923('0x1d')]=function(_0x2af037,_0x4b1409){var _0x13873f=_0x2af037[_0xc923('0x1e')];return _0x2af037[_0xc923('0x1f')]('VoiceChanSpy',attributes,{'tableName':_0xc923('0x20'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x22e878,_0x44c92b,_0xaabfb7){return getChanSpyPromise(_0x13873f,_0x22e878)['then'](function(_0x59323e){if(_0x59323e&&_0x59323e[_0xc923('0x21')]){return _0x13873f[_0xc923('0x22')][_0xc923('0x23')](_0x59323e);}})[_0xc923('0x1b')](function(){_0xaabfb7();})[_0xc923('0x1c')](function(_0x5e7156){_0xaabfb7(_0x5e7156);});},'afterUpdate':function(_0x22884c,_0x4e3c90,_0x4224e8){return _0x13873f['VoiceExtension'][_0xc923('0x24')]({'where':{'ChanSpyId':_0x22884c['id']}})[_0xc923('0x1b')](function(){return getChanSpyPromise(_0x13873f,_0x22884c);})[_0xc923('0x1b')](function(_0x362fdd){if(_0x362fdd&&_0x362fdd[_0xc923('0x21')]){return _0x13873f[_0xc923('0x22')][_0xc923('0x23')](_0x362fdd);}})['then'](function(){_0x4224e8();})[_0xc923('0x1c')](function(_0x2d5435){_0x4224e8(_0x2d5435);});},'afterDestroy':function(_0x4eb21d,_0x14f109,_0x47fe4f){return _0x13873f[_0xc923('0x22')][_0xc923('0x24')]({'where':{'ChanSpyId':_0x4eb21d['id']}})[_0xc923('0x1b')](function(){_0x47fe4f();})[_0xc923('0x1c')](function(_0x539b4f){_0x47fe4f(_0x539b4f);});}}});};