a4075163d6e62f7259a28fb3c35199b7e65a23f4
[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 _0x6026=['options','join','StopMixMonitor','length','concat','findAll','then','catch','exports','define','VoiceChanSpy','voice_chanspy','VoiceExtension','bulkCreate','destroy','lodash','bluebird','./voiceChanSpy.attributes','context','from-sip','%s%s','prefix','system','merge','Set','format','CDR(type)=%s','chanspy','record','${UNIQUEID}.%s,a','recordingFormat','auth','password','push','ChanSpy','SIP/%s,%s','name'];(function(_0x551223,_0x4c84ed){var _0x12cf16=function(_0x2fe771){while(--_0x2fe771){_0x551223['push'](_0x551223['shift']());}};_0x12cf16(++_0x4c84ed);}(_0x6026,0x7e));var _0x6602=function(_0x4956d2,_0x12cf69){_0x4956d2=_0x4956d2-0x0;var _0x27d60c=_0x6026[_0x4956d2];return _0x27d60c;};'use strict';var _=require(_0x6602('0x0'));var util=require('util');var BPromise=require(_0x6602('0x1'));var attributes=require(_0x6602('0x2'));var getUserApplications=function(_0xc7a631,_0x1f72c6,_0x2d29e9){var _0x29afed=0x1;var _0x32a2ce=[];var _0x53ceb0={'context':_0x1f72c6[_0x6602('0x3')]||_0x6602('0x4'),'exten':util['format'](_0x6602('0x5'),_0xc7a631[_0x6602('0x6')],_0x2d29e9),'type':_0x6602('0x7'),'isApp':![],'ChanSpyId':_0xc7a631['id'],'UserId':_0x1f72c6['id']};_0x32a2ce['push'](_[_0x6602('0x8')]({'app':_0x6602('0x9'),'appdata':util[_0x6602('0xa')](_0x6602('0xb'),_0x6602('0xc')),'priority':_0x29afed++},_0x53ceb0));if(_0xc7a631[_0x6602('0xd')]){_0x32a2ce['push'](_['merge']({'app':'MixMonitor','appdata':util['format'](_0x6602('0xe'),_0xc7a631[_0x6602('0xf')]),'priority':_0x29afed++},_0x53ceb0));}if(_0xc7a631[_0x6602('0x10')]){_0x32a2ce['push'](_[_0x6602('0x8')]({'app':'Authenticate','appdata':_0xc7a631[_0x6602('0x11')],'priority':_0x29afed++},_0x53ceb0));}_0x32a2ce[_0x6602('0x12')](_['merge']({'app':_0x6602('0x13'),'appdata':util[_0x6602('0xa')](_0x6602('0x14'),_0x1f72c6[_0x6602('0x15')],_0xc7a631[_0x6602('0x16')]?_0xc7a631[_0x6602('0x16')][_0x6602('0x17')](''):''),'priority':_0x29afed++},_0x53ceb0));if(_0xc7a631[_0x6602('0xd')]){_0x32a2ce[_0x6602('0x12')](_['merge']({'app':_0x6602('0x18'),'priority':_0x29afed++},_0x53ceb0));}return _0x32a2ce;};var getChanSpyApplications=function(_0x2a2ce8,_0x349565){var _0x286442=[];for(var _0xc3e0dc=0x0,_0x30b217=0x1;_0xc3e0dc<_0x349565[_0x6602('0x19')];_0xc3e0dc++,_0x30b217=0x1){_0x286442=_0x286442['concat'](getUserApplications(_0x2a2ce8,_0x349565[_0xc3e0dc],_0x349565[_0xc3e0dc]['internal']));if(_0x349565[_0xc3e0dc]['internal']!=_0x349565[_0xc3e0dc][_0x6602('0x15')]){_0x286442=_0x286442[_0x6602('0x1a')](getUserApplications(_0x2a2ce8,_0x349565[_0xc3e0dc],_0x349565[_0xc3e0dc][_0x6602('0x15')]));}}return _0x286442;};var getChanSpyPromise=function(_0x359750,_0x39516f){return new BPromise(function(_0x5cf47e,_0x1348e7){return _0x359750['User'][_0x6602('0x1b')]({'attributes':['id','name','internal'],'where':{'role':'agent','chanspy':!![]},'raw':!![]})[_0x6602('0x1c')](function(_0x77e714){if(_0x77e714){return _0x5cf47e(getChanSpyApplications(_0x39516f,_0x77e714));}return _0x5cf47e([]);})[_0x6602('0x1d')](function(_0x577777){_0x1348e7(_0x577777);});});};module[_0x6602('0x1e')]=function(_0x16b96f,_0x28cceb){var _0x29c187=_0x16b96f['models'];return _0x16b96f[_0x6602('0x1f')](_0x6602('0x20'),attributes,{'tableName':_0x6602('0x21'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x53634d,_0x3e27fb,_0x113c57){return getChanSpyPromise(_0x29c187,_0x53634d)[_0x6602('0x1c')](function(_0x4857ba){if(_0x4857ba&&_0x4857ba[_0x6602('0x19')]){return _0x29c187[_0x6602('0x22')]['bulkCreate'](_0x4857ba);}})['then'](function(){_0x113c57();})[_0x6602('0x1d')](function(_0x57624d){_0x113c57(_0x57624d);});},'afterUpdate':function(_0x55425e,_0x431b7b,_0x4e17ea){return _0x29c187['VoiceExtension']['destroy']({'where':{'ChanSpyId':_0x55425e['id']}})[_0x6602('0x1c')](function(){return getChanSpyPromise(_0x29c187,_0x55425e);})[_0x6602('0x1c')](function(_0xd30d6d){if(_0xd30d6d&&_0xd30d6d[_0x6602('0x19')]){return _0x29c187[_0x6602('0x22')][_0x6602('0x23')](_0xd30d6d);}})['then'](function(){_0x4e17ea();})[_0x6602('0x1d')](function(_0x1f1b95){_0x4e17ea(_0x1f1b95);});},'afterDestroy':function(_0x3f8003,_0x1cbeea,_0x494b18){return _0x29c187[_0x6602('0x22')][_0x6602('0x24')]({'where':{'ChanSpyId':_0x3f8003['id']}})[_0x6602('0x1c')](function(){_0x494b18();})[_0x6602('0x1d')](function(_0x3f3604){_0x494b18(_0x3f3604);});}}});};