7fae2d1ae01fa70ee63416e8207ba451d4ce4a27
[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 _0xca91=['voice_chanspy','VoiceExtension','destroy','lodash','util','bluebird','./voiceChanSpy.attributes','context','from-sip','format','%s%s','prefix','system','push','merge','Set','CDR(type)=%s','chanspy','record','${UNIQUEID}.%s,a','auth','Authenticate','password','ChanSpy','SIP/%s,%s','name','join','StopMixMonitor','length','internal','User','agent','then','catch','models'];(function(_0x382c73,_0x199cab){var _0x1dd0bf=function(_0x358747){while(--_0x358747){_0x382c73['push'](_0x382c73['shift']());}};_0x1dd0bf(++_0x199cab);}(_0xca91,0x1ca));var _0x1ca9=function(_0x55d829,_0x43f06c){_0x55d829=_0x55d829-0x0;var _0x52163b=_0xca91[_0x55d829];return _0x52163b;};'use strict';var _=require(_0x1ca9('0x0'));var util=require(_0x1ca9('0x1'));var BPromise=require(_0x1ca9('0x2'));var attributes=require(_0x1ca9('0x3'));var getUserApplications=function(_0x39f79e,_0x188a17,_0x14fcca){var _0xfae222=0x1;var _0x5842f7=[];var _0x111612={'context':_0x188a17[_0x1ca9('0x4')]||_0x1ca9('0x5'),'exten':util[_0x1ca9('0x6')](_0x1ca9('0x7'),_0x39f79e[_0x1ca9('0x8')],_0x14fcca),'type':_0x1ca9('0x9'),'isApp':![],'ChanSpyId':_0x39f79e['id'],'UserId':_0x188a17['id']};_0x5842f7[_0x1ca9('0xa')](_[_0x1ca9('0xb')]({'app':_0x1ca9('0xc'),'appdata':util[_0x1ca9('0x6')](_0x1ca9('0xd'),_0x1ca9('0xe')),'priority':_0xfae222++},_0x111612));if(_0x39f79e[_0x1ca9('0xf')]){_0x5842f7[_0x1ca9('0xa')](_[_0x1ca9('0xb')]({'app':'MixMonitor','appdata':util[_0x1ca9('0x6')](_0x1ca9('0x10'),_0x39f79e['recordingFormat']),'priority':_0xfae222++},_0x111612));}if(_0x39f79e[_0x1ca9('0x11')]){_0x5842f7[_0x1ca9('0xa')](_['merge']({'app':_0x1ca9('0x12'),'appdata':_0x39f79e[_0x1ca9('0x13')],'priority':_0xfae222++},_0x111612));}_0x5842f7[_0x1ca9('0xa')](_[_0x1ca9('0xb')]({'app':_0x1ca9('0x14'),'appdata':util['format'](_0x1ca9('0x15'),_0x188a17[_0x1ca9('0x16')],_0x39f79e['options']?_0x39f79e['options'][_0x1ca9('0x17')](''):''),'priority':_0xfae222++},_0x111612));if(_0x39f79e[_0x1ca9('0xf')]){_0x5842f7[_0x1ca9('0xa')](_[_0x1ca9('0xb')]({'app':_0x1ca9('0x18'),'priority':_0xfae222++},_0x111612));}return _0x5842f7;};var getChanSpyApplications=function(_0x1c4d7f,_0x1ab498){var _0x287a2e=[];for(var _0x56cc61=0x0,_0x107a8e=0x1;_0x56cc61<_0x1ab498[_0x1ca9('0x19')];_0x56cc61++,_0x107a8e=0x1){_0x287a2e=_0x287a2e['concat'](getUserApplications(_0x1c4d7f,_0x1ab498[_0x56cc61],_0x1ab498[_0x56cc61]['internal']));if(_0x1ab498[_0x56cc61][_0x1ca9('0x1a')]!=_0x1ab498[_0x56cc61][_0x1ca9('0x16')]){_0x287a2e=_0x287a2e['concat'](getUserApplications(_0x1c4d7f,_0x1ab498[_0x56cc61],_0x1ab498[_0x56cc61][_0x1ca9('0x16')]));}}return _0x287a2e;};var getChanSpyPromise=function(_0x55ac57,_0x402283){return new BPromise(function(_0x29820c,_0x2b92d7){return _0x55ac57[_0x1ca9('0x1b')]['findAll']({'attributes':['id',_0x1ca9('0x16'),_0x1ca9('0x1a')],'where':{'role':_0x1ca9('0x1c'),'chanspy':!![]},'raw':!![]})[_0x1ca9('0x1d')](function(_0x5a7ee5){if(_0x5a7ee5){return _0x29820c(getChanSpyApplications(_0x402283,_0x5a7ee5));}return _0x29820c([]);})[_0x1ca9('0x1e')](function(_0xf12db){_0x2b92d7(_0xf12db);});});};module['exports']=function(_0x263c61,_0x11202d){var _0x4cc184=_0x263c61[_0x1ca9('0x1f')];return _0x263c61['define']('VoiceChanSpy',attributes,{'tableName':_0x1ca9('0x20'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x1b5f60,_0x5a30bb,_0x52d143){return getChanSpyPromise(_0x4cc184,_0x1b5f60)['then'](function(_0x3aea88){if(_0x3aea88&&_0x3aea88[_0x1ca9('0x19')]){return _0x4cc184[_0x1ca9('0x21')]['bulkCreate'](_0x3aea88);}})[_0x1ca9('0x1d')](function(){_0x52d143();})[_0x1ca9('0x1e')](function(_0x41445a){_0x52d143(_0x41445a);});},'afterUpdate':function(_0xe29ae3,_0x1f56a3,_0xf82b3e){return _0x4cc184[_0x1ca9('0x21')]['destroy']({'where':{'ChanSpyId':_0xe29ae3['id']}})[_0x1ca9('0x1d')](function(){return getChanSpyPromise(_0x4cc184,_0xe29ae3);})[_0x1ca9('0x1d')](function(_0x2b9c1f){if(_0x2b9c1f&&_0x2b9c1f[_0x1ca9('0x19')]){return _0x4cc184[_0x1ca9('0x21')]['bulkCreate'](_0x2b9c1f);}})[_0x1ca9('0x1d')](function(){_0xf82b3e();})[_0x1ca9('0x1e')](function(_0x35195f){_0xf82b3e(_0x35195f);});},'afterDestroy':function(_0x420108,_0x3fe8e7,_0x568d20){return _0x4cc184[_0x1ca9('0x21')][_0x1ca9('0x22')]({'where':{'ChanSpyId':_0x420108['id']}})[_0x1ca9('0x1d')](function(){_0x568d20();})[_0x1ca9('0x1e')](function(_0x52bd89){_0x568d20(_0x52bd89);});}}});};