69b7b1a0d8fe8a50b243992b2319034abe66b36b
[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 _0x9efb=['SIP/%s,%s','options','StopMixMonitor','length','internal','concat','name','User','findAll','agent','catch','exports','models','VoiceChanSpy','then','bulkCreate','VoiceExtension','util','bluebird','context','from-sip','format','%s%s','push','CDR(type)=%s','chanspy','record','merge','MixMonitor','${UNIQUEID}.%s,a','auth','Authenticate','password','ChanSpy'];(function(_0x466f03,_0xe3f71d){var _0x1132db=function(_0x338d4b){while(--_0x338d4b){_0x466f03['push'](_0x466f03['shift']());}};_0x1132db(++_0xe3f71d);}(_0x9efb,0x143));var _0xb9ef=function(_0x419e8b,_0xb0e337){_0x419e8b=_0x419e8b-0x0;var _0x4dc318=_0x9efb[_0x419e8b];return _0x4dc318;};'use strict';var _=require('lodash');var util=require(_0xb9ef('0x0'));var BPromise=require(_0xb9ef('0x1'));var attributes=require('./voiceChanSpy.attributes');var getUserApplications=function(_0x22984e,_0x267320,_0x510c60){var _0x9e47ee=0x1;var _0x1e1eeb=[];var _0x33ef5b={'context':_0x267320[_0xb9ef('0x2')]||_0xb9ef('0x3'),'exten':util[_0xb9ef('0x4')](_0xb9ef('0x5'),_0x22984e['prefix'],_0x510c60),'type':'system','isApp':![],'ChanSpyId':_0x22984e['id'],'UserId':_0x267320['id']};_0x1e1eeb[_0xb9ef('0x6')](_['merge']({'app':'Set','appdata':util[_0xb9ef('0x4')](_0xb9ef('0x7'),_0xb9ef('0x8')),'priority':_0x9e47ee++},_0x33ef5b));if(_0x22984e[_0xb9ef('0x9')]){_0x1e1eeb['push'](_[_0xb9ef('0xa')]({'app':_0xb9ef('0xb'),'appdata':util[_0xb9ef('0x4')](_0xb9ef('0xc'),_0x22984e['recordingFormat']),'priority':_0x9e47ee++},_0x33ef5b));}if(_0x22984e[_0xb9ef('0xd')]){_0x1e1eeb[_0xb9ef('0x6')](_[_0xb9ef('0xa')]({'app':_0xb9ef('0xe'),'appdata':_0x22984e[_0xb9ef('0xf')],'priority':_0x9e47ee++},_0x33ef5b));}_0x1e1eeb[_0xb9ef('0x6')](_[_0xb9ef('0xa')]({'app':_0xb9ef('0x10'),'appdata':util[_0xb9ef('0x4')](_0xb9ef('0x11'),_0x267320['name'],_0x22984e[_0xb9ef('0x12')]?_0x22984e[_0xb9ef('0x12')]['join'](''):''),'priority':_0x9e47ee++},_0x33ef5b));if(_0x22984e['record']){_0x1e1eeb[_0xb9ef('0x6')](_[_0xb9ef('0xa')]({'app':_0xb9ef('0x13'),'priority':_0x9e47ee++},_0x33ef5b));}return _0x1e1eeb;};var getChanSpyApplications=function(_0x11fb09,_0x51c9fa){var _0x4bdafc=[];for(var _0x56ef9b=0x0,_0xf155f0=0x1;_0x56ef9b<_0x51c9fa[_0xb9ef('0x14')];_0x56ef9b++,_0xf155f0=0x1){_0x4bdafc=_0x4bdafc['concat'](getUserApplications(_0x11fb09,_0x51c9fa[_0x56ef9b],_0x51c9fa[_0x56ef9b][_0xb9ef('0x15')]));if(_0x51c9fa[_0x56ef9b][_0xb9ef('0x15')]!=_0x51c9fa[_0x56ef9b]['name']){_0x4bdafc=_0x4bdafc[_0xb9ef('0x16')](getUserApplications(_0x11fb09,_0x51c9fa[_0x56ef9b],_0x51c9fa[_0x56ef9b][_0xb9ef('0x17')]));}}return _0x4bdafc;};var getChanSpyPromise=function(_0x294e78,_0x3c4e5c){return new BPromise(function(_0x389602,_0x38def8){return _0x294e78[_0xb9ef('0x18')][_0xb9ef('0x19')]({'attributes':['id','name',_0xb9ef('0x15')],'where':{'role':_0xb9ef('0x1a'),'chanspy':!![]},'raw':!![]})['then'](function(_0x42b88f){if(_0x42b88f){return _0x389602(getChanSpyApplications(_0x3c4e5c,_0x42b88f));}return _0x389602([]);})[_0xb9ef('0x1b')](function(_0x2aa80d){_0x38def8(_0x2aa80d);});});};module[_0xb9ef('0x1c')]=function(_0x56162c,_0x9a6690){var _0x258db1=_0x56162c[_0xb9ef('0x1d')];return _0x56162c['define'](_0xb9ef('0x1e'),attributes,{'tableName':'voice_chanspy','paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x5c5622,_0x545173,_0x3fd6e0){return getChanSpyPromise(_0x258db1,_0x5c5622)[_0xb9ef('0x1f')](function(_0x1cb2a9){if(_0x1cb2a9&&_0x1cb2a9[_0xb9ef('0x14')]){return _0x258db1['VoiceExtension'][_0xb9ef('0x20')](_0x1cb2a9);}})[_0xb9ef('0x1f')](function(){_0x3fd6e0();})['catch'](function(_0x43b6d7){_0x3fd6e0(_0x43b6d7);});},'afterUpdate':function(_0x11d58f,_0x256f49,_0x27e654){return _0x258db1[_0xb9ef('0x21')]['destroy']({'where':{'ChanSpyId':_0x11d58f['id']}})['then'](function(){return getChanSpyPromise(_0x258db1,_0x11d58f);})[_0xb9ef('0x1f')](function(_0x1fc456){if(_0x1fc456&&_0x1fc456[_0xb9ef('0x14')]){return _0x258db1[_0xb9ef('0x21')][_0xb9ef('0x20')](_0x1fc456);}})[_0xb9ef('0x1f')](function(){_0x27e654();})[_0xb9ef('0x1b')](function(_0x124f4f){_0x27e654(_0x124f4f);});},'afterDestroy':function(_0x4d8055,_0x2853ae,_0x43e4eb){return _0x258db1[_0xb9ef('0x21')]['destroy']({'where':{'ChanSpyId':_0x4d8055['id']}})['then'](function(){_0x43e4eb();})[_0xb9ef('0x1b')](function(_0x55dcc6){_0x43e4eb(_0x55dcc6);});}}});};