Built motion from commit (unavailable).|2.5.14
[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 _0x51f4=['MixMonitor','${UNIQUEID}.%s,a','recordingFormat','auth','merge','password','SIP/%s,%s','name','options','join','concat','agent','catch','models','VoiceChanSpy','voice_chanspy','then','bulkCreate','VoiceExtension','destroy','length','lodash','util','bluebird','context','from-sip','format','prefix','system','push','Set','CDR(type)=%s','chanspy'];(function(_0x31b287,_0xdc3071){var _0x12f98d=function(_0x5cf48e){while(--_0x5cf48e){_0x31b287['push'](_0x31b287['shift']());}};_0x12f98d(++_0xdc3071);}(_0x51f4,0x1c2));var _0x451f=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x51f4[_0x3dd15e];return _0x231fd0;};'use strict';var _=require(_0x451f('0x0'));var util=require(_0x451f('0x1'));var BPromise=require(_0x451f('0x2'));var attributes=require('./voiceChanSpy.attributes');var getUserApplications=function(_0xace018,_0x444171,_0x1e75d1){var _0x48f14d=0x1;var _0x2e4ede=[];var _0x4dcf23={'context':_0x444171[_0x451f('0x3')]||_0x451f('0x4'),'exten':util[_0x451f('0x5')]('%s%s',_0xace018[_0x451f('0x6')],_0x1e75d1),'type':_0x451f('0x7'),'isApp':![],'ChanSpyId':_0xace018['id'],'UserId':_0x444171['id']};_0x2e4ede[_0x451f('0x8')](_['merge']({'app':_0x451f('0x9'),'appdata':util[_0x451f('0x5')](_0x451f('0xa'),_0x451f('0xb')),'priority':_0x48f14d++},_0x4dcf23));if(_0xace018['record']){_0x2e4ede[_0x451f('0x8')](_['merge']({'app':_0x451f('0xc'),'appdata':util[_0x451f('0x5')](_0x451f('0xd'),_0xace018[_0x451f('0xe')]),'priority':_0x48f14d++},_0x4dcf23));}if(_0xace018[_0x451f('0xf')]){_0x2e4ede[_0x451f('0x8')](_[_0x451f('0x10')]({'app':'Authenticate','appdata':_0xace018[_0x451f('0x11')],'priority':_0x48f14d++},_0x4dcf23));}_0x2e4ede[_0x451f('0x8')](_[_0x451f('0x10')]({'app':'ChanSpy','appdata':util[_0x451f('0x5')](_0x451f('0x12'),_0x444171[_0x451f('0x13')],_0xace018[_0x451f('0x14')]?_0xace018['options'][_0x451f('0x15')](''):''),'priority':_0x48f14d++},_0x4dcf23));if(_0xace018['record']){_0x2e4ede[_0x451f('0x8')](_['merge']({'app':'StopMixMonitor','priority':_0x48f14d++},_0x4dcf23));}return _0x2e4ede;};var getChanSpyApplications=function(_0x242390,_0x522b9c){var _0x18ca77=[];for(var _0x53b34a=0x0,_0x5a6605=0x1;_0x53b34a<_0x522b9c['length'];_0x53b34a++,_0x5a6605=0x1){_0x18ca77=_0x18ca77[_0x451f('0x16')](getUserApplications(_0x242390,_0x522b9c[_0x53b34a],_0x522b9c[_0x53b34a]['internal']));if(_0x522b9c[_0x53b34a]['internal']!=_0x522b9c[_0x53b34a][_0x451f('0x13')]){_0x18ca77=_0x18ca77[_0x451f('0x16')](getUserApplications(_0x242390,_0x522b9c[_0x53b34a],_0x522b9c[_0x53b34a][_0x451f('0x13')]));}}return _0x18ca77;};var getChanSpyPromise=function(_0x54774e,_0x15896f){return new BPromise(function(_0x2d6281,_0x29ad73){return _0x54774e['User']['findAll']({'attributes':['id','name','internal'],'where':{'role':_0x451f('0x17'),'chanspy':!![]},'raw':!![]})['then'](function(_0x2182a3){if(_0x2182a3){return _0x2d6281(getChanSpyApplications(_0x15896f,_0x2182a3));}return _0x2d6281([]);})[_0x451f('0x18')](function(_0x5b762b){_0x29ad73(_0x5b762b);});});};module['exports']=function(_0x5f5589,_0x4b051b){var _0x74fe04=_0x5f5589[_0x451f('0x19')];return _0x5f5589['define'](_0x451f('0x1a'),attributes,{'tableName':_0x451f('0x1b'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0xd8ce4,_0x2f2d45,_0x2fcb00){return getChanSpyPromise(_0x74fe04,_0xd8ce4)[_0x451f('0x1c')](function(_0x2e85e1){if(_0x2e85e1&&_0x2e85e1['length']){return _0x74fe04['VoiceExtension'][_0x451f('0x1d')](_0x2e85e1);}})[_0x451f('0x1c')](function(){_0x2fcb00();})[_0x451f('0x18')](function(_0x5a215a){_0x2fcb00(_0x5a215a);});},'afterUpdate':function(_0x12d19f,_0x53bf4a,_0x4492e0){return _0x74fe04[_0x451f('0x1e')][_0x451f('0x1f')]({'where':{'ChanSpyId':_0x12d19f['id']}})[_0x451f('0x1c')](function(){return getChanSpyPromise(_0x74fe04,_0x12d19f);})[_0x451f('0x1c')](function(_0x4d4071){if(_0x4d4071&&_0x4d4071[_0x451f('0x20')]){return _0x74fe04[_0x451f('0x1e')][_0x451f('0x1d')](_0x4d4071);}})[_0x451f('0x1c')](function(){_0x4492e0();})[_0x451f('0x18')](function(_0xd40efe){_0x4492e0(_0xd40efe);});},'afterDestroy':function(_0x154ce1,_0x3dcd93,_0x1eb65d){return _0x74fe04[_0x451f('0x1e')][_0x451f('0x1f')]({'where':{'ChanSpyId':_0x154ce1['id']}})[_0x451f('0x1c')](function(){_0x1eb65d();})[_0x451f('0x18')](function(_0x5c2bfd){_0x1eb65d(_0x5c2bfd);});}}});};