0d024b896873af5e4e8799bf49915fbea0340f88
[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 _0x63eb=['context','from-sip','format','%s%s','prefix','system','push','merge','Set','CDR(type)=%s','record','MixMonitor','recordingFormat','auth','password','SIP/%s,%s','name','options','join','StopMixMonitor','length','concat','internal','findAll','then','catch','exports','define','VoiceChanSpy','voice_chanspy','bulkCreate','VoiceExtension','destroy','lodash','util','bluebird','./voiceChanSpy.attributes'];(function(_0x226ad1,_0x2858e2){var _0x16b625=function(_0x4dc555){while(--_0x4dc555){_0x226ad1['push'](_0x226ad1['shift']());}};_0x16b625(++_0x2858e2);}(_0x63eb,0x90));var _0xb63e=function(_0x2b0973,_0xc46bce){_0x2b0973=_0x2b0973-0x0;var _0x45dac4=_0x63eb[_0x2b0973];return _0x45dac4;};'use strict';var _=require(_0xb63e('0x0'));var util=require(_0xb63e('0x1'));var BPromise=require(_0xb63e('0x2'));var attributes=require(_0xb63e('0x3'));var getUserApplications=function(_0x3aa2dc,_0x2968ac,_0x4e6d10){var _0x1b68cc=0x1;var _0x341ff1=[];var _0x3a40f6={'context':_0x2968ac[_0xb63e('0x4')]||_0xb63e('0x5'),'exten':util[_0xb63e('0x6')](_0xb63e('0x7'),_0x3aa2dc[_0xb63e('0x8')],_0x4e6d10),'type':_0xb63e('0x9'),'isApp':![],'ChanSpyId':_0x3aa2dc['id'],'UserId':_0x2968ac['id']};_0x341ff1[_0xb63e('0xa')](_[_0xb63e('0xb')]({'app':_0xb63e('0xc'),'appdata':util[_0xb63e('0x6')](_0xb63e('0xd'),'chanspy'),'priority':_0x1b68cc++},_0x3a40f6));if(_0x3aa2dc[_0xb63e('0xe')]){_0x341ff1['push'](_[_0xb63e('0xb')]({'app':_0xb63e('0xf'),'appdata':util[_0xb63e('0x6')]('${UNIQUEID}.%s,a',_0x3aa2dc[_0xb63e('0x10')]),'priority':_0x1b68cc++},_0x3a40f6));}if(_0x3aa2dc[_0xb63e('0x11')]){_0x341ff1[_0xb63e('0xa')](_[_0xb63e('0xb')]({'app':'Authenticate','appdata':_0x3aa2dc[_0xb63e('0x12')],'priority':_0x1b68cc++},_0x3a40f6));}_0x341ff1[_0xb63e('0xa')](_[_0xb63e('0xb')]({'app':'ChanSpy','appdata':util[_0xb63e('0x6')](_0xb63e('0x13'),_0x2968ac[_0xb63e('0x14')],_0x3aa2dc[_0xb63e('0x15')]?_0x3aa2dc['options'][_0xb63e('0x16')](''):''),'priority':_0x1b68cc++},_0x3a40f6));if(_0x3aa2dc[_0xb63e('0xe')]){_0x341ff1[_0xb63e('0xa')](_[_0xb63e('0xb')]({'app':_0xb63e('0x17'),'priority':_0x1b68cc++},_0x3a40f6));}return _0x341ff1;};var getChanSpyApplications=function(_0x52c5c7,_0xcfe001){var _0x45d6de=[];for(var _0x2221d9=0x0,_0x398544=0x1;_0x2221d9<_0xcfe001[_0xb63e('0x18')];_0x2221d9++,_0x398544=0x1){_0x45d6de=_0x45d6de[_0xb63e('0x19')](getUserApplications(_0x52c5c7,_0xcfe001[_0x2221d9],_0xcfe001[_0x2221d9]['internal']));if(_0xcfe001[_0x2221d9][_0xb63e('0x1a')]!=_0xcfe001[_0x2221d9][_0xb63e('0x14')]){_0x45d6de=_0x45d6de[_0xb63e('0x19')](getUserApplications(_0x52c5c7,_0xcfe001[_0x2221d9],_0xcfe001[_0x2221d9]['name']));}}return _0x45d6de;};var getChanSpyPromise=function(_0x43580e,_0x5bbcc3){return new BPromise(function(_0x5ac51e,_0x3210f2){return _0x43580e['User'][_0xb63e('0x1b')]({'attributes':['id',_0xb63e('0x14'),_0xb63e('0x1a')],'where':{'role':'agent','chanspy':!![]},'raw':!![]})[_0xb63e('0x1c')](function(_0x2d5ce6){if(_0x2d5ce6){return _0x5ac51e(getChanSpyApplications(_0x5bbcc3,_0x2d5ce6));}return _0x5ac51e([]);})[_0xb63e('0x1d')](function(_0x193d21){_0x3210f2(_0x193d21);});});};module[_0xb63e('0x1e')]=function(_0x580e8a,_0xc6cf48){var _0x4f4907=_0x580e8a['models'];return _0x580e8a[_0xb63e('0x1f')](_0xb63e('0x20'),attributes,{'tableName':_0xb63e('0x21'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x210ef4,_0x4eae0e,_0x261dbb){return getChanSpyPromise(_0x4f4907,_0x210ef4)['then'](function(_0x5abd5a){if(_0x5abd5a&&_0x5abd5a[_0xb63e('0x18')]){return _0x4f4907['VoiceExtension'][_0xb63e('0x22')](_0x5abd5a);}})[_0xb63e('0x1c')](function(){_0x261dbb();})['catch'](function(_0x2df49d){_0x261dbb(_0x2df49d);});},'afterUpdate':function(_0x3fd788,_0x5c82aa,_0x27b0ea){return _0x4f4907[_0xb63e('0x23')]['destroy']({'where':{'ChanSpyId':_0x3fd788['id']}})[_0xb63e('0x1c')](function(){return getChanSpyPromise(_0x4f4907,_0x3fd788);})['then'](function(_0x1f4171){if(_0x1f4171&&_0x1f4171[_0xb63e('0x18')]){return _0x4f4907['VoiceExtension'][_0xb63e('0x22')](_0x1f4171);}})[_0xb63e('0x1c')](function(){_0x27b0ea();})['catch'](function(_0x57fa8b){_0x27b0ea(_0x57fa8b);});},'afterDestroy':function(_0x293faf,_0x24452d,_0x250588){return _0x4f4907[_0xb63e('0x23')][_0xb63e('0x24')]({'where':{'ChanSpyId':_0x293faf['id']}})[_0xb63e('0x1c')](function(){_0x250588();})[_0xb63e('0x1d')](function(_0x507564){_0x250588(_0x507564);});}}});};