190810338ec4d84a6990278224d985e2fa7e110e
[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 _0x3ac8=['system','push','Set','CDR(type)=%s','chanspy','merge','${UNIQUEID}.%s,a','ChanSpy','name','options','record','StopMixMonitor','length','concat','internal','findAll','agent','then','models','define','VoiceChanSpy','voice_chanspy','VoiceExtension','bulkCreate','catch','lodash','util','bluebird','./voiceChanSpy.attributes','context','from-sip','format','%s%s','prefix'];(function(_0x3d42d8,_0x4cffaa){var _0x27fc41=function(_0x3a363b){while(--_0x3a363b){_0x3d42d8['push'](_0x3d42d8['shift']());}};_0x27fc41(++_0x4cffaa);}(_0x3ac8,0x18f));var _0x83ac=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x3ac8[_0x3dd15e];return _0x231fd0;};'use strict';var _=require(_0x83ac('0x0'));var util=require(_0x83ac('0x1'));var BPromise=require(_0x83ac('0x2'));var attributes=require(_0x83ac('0x3'));var getUserApplications=function(_0x1db75e,_0x330d15,_0x387bac){var _0x4213c0=0x1;var _0x37d704=[];var _0x3e33bc={'context':_0x330d15[_0x83ac('0x4')]||_0x83ac('0x5'),'exten':util[_0x83ac('0x6')](_0x83ac('0x7'),_0x1db75e[_0x83ac('0x8')],_0x387bac),'type':_0x83ac('0x9'),'isApp':![],'ChanSpyId':_0x1db75e['id'],'UserId':_0x330d15['id']};_0x37d704[_0x83ac('0xa')](_['merge']({'app':_0x83ac('0xb'),'appdata':util[_0x83ac('0x6')](_0x83ac('0xc'),_0x83ac('0xd')),'priority':_0x4213c0++},_0x3e33bc));if(_0x1db75e['record']){_0x37d704[_0x83ac('0xa')](_[_0x83ac('0xe')]({'app':'MixMonitor','appdata':util[_0x83ac('0x6')](_0x83ac('0xf'),_0x1db75e['recordingFormat']),'priority':_0x4213c0++},_0x3e33bc));}if(_0x1db75e['auth']){_0x37d704[_0x83ac('0xa')](_[_0x83ac('0xe')]({'app':'Authenticate','appdata':_0x1db75e['password'],'priority':_0x4213c0++},_0x3e33bc));}_0x37d704[_0x83ac('0xa')](_[_0x83ac('0xe')]({'app':_0x83ac('0x10'),'appdata':util[_0x83ac('0x6')]('SIP/%s,%s',_0x330d15[_0x83ac('0x11')],_0x1db75e[_0x83ac('0x12')]?_0x1db75e[_0x83ac('0x12')]['join'](''):''),'priority':_0x4213c0++},_0x3e33bc));if(_0x1db75e[_0x83ac('0x13')]){_0x37d704['push'](_['merge']({'app':_0x83ac('0x14'),'priority':_0x4213c0++},_0x3e33bc));}return _0x37d704;};var getChanSpyApplications=function(_0x3bca57,_0x4a9fa6){var _0x5b1881=[];for(var _0xc8f298=0x0,_0x35dcd2=0x1;_0xc8f298<_0x4a9fa6[_0x83ac('0x15')];_0xc8f298++,_0x35dcd2=0x1){_0x5b1881=_0x5b1881[_0x83ac('0x16')](getUserApplications(_0x3bca57,_0x4a9fa6[_0xc8f298],_0x4a9fa6[_0xc8f298][_0x83ac('0x17')]));if(_0x4a9fa6[_0xc8f298]['internal']!=_0x4a9fa6[_0xc8f298]['name']){_0x5b1881=_0x5b1881['concat'](getUserApplications(_0x3bca57,_0x4a9fa6[_0xc8f298],_0x4a9fa6[_0xc8f298]['name']));}}return _0x5b1881;};var getChanSpyPromise=function(_0xfdd7ae,_0x3e33cf){return new BPromise(function(_0x4f40d4,_0x1047dd){return _0xfdd7ae['User'][_0x83ac('0x18')]({'attributes':['id',_0x83ac('0x11'),_0x83ac('0x17')],'where':{'role':_0x83ac('0x19'),'chanspy':!![]},'raw':!![]})[_0x83ac('0x1a')](function(_0x5d2284){if(_0x5d2284){return _0x4f40d4(getChanSpyApplications(_0x3e33cf,_0x5d2284));}return _0x4f40d4([]);})['catch'](function(_0x12d94c){_0x1047dd(_0x12d94c);});});};module['exports']=function(_0x50741e,_0xf8e28){var _0x32bd87=_0x50741e[_0x83ac('0x1b')];return _0x50741e[_0x83ac('0x1c')](_0x83ac('0x1d'),attributes,{'tableName':_0x83ac('0x1e'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x5c843b,_0x147c58,_0x1289c5){return getChanSpyPromise(_0x32bd87,_0x5c843b)[_0x83ac('0x1a')](function(_0x1622d7){if(_0x1622d7&&_0x1622d7['length']){return _0x32bd87[_0x83ac('0x1f')][_0x83ac('0x20')](_0x1622d7);}})[_0x83ac('0x1a')](function(){_0x1289c5();})[_0x83ac('0x21')](function(_0x12026e){_0x1289c5(_0x12026e);});},'afterUpdate':function(_0x4d3bde,_0x25eaa6,_0xc60011){return _0x32bd87[_0x83ac('0x1f')]['destroy']({'where':{'ChanSpyId':_0x4d3bde['id']}})[_0x83ac('0x1a')](function(){return getChanSpyPromise(_0x32bd87,_0x4d3bde);})[_0x83ac('0x1a')](function(_0x2398d1){if(_0x2398d1&&_0x2398d1[_0x83ac('0x15')]){return _0x32bd87[_0x83ac('0x1f')][_0x83ac('0x20')](_0x2398d1);}})[_0x83ac('0x1a')](function(){_0xc60011();})['catch'](function(_0x9b35c0){_0xc60011(_0x9b35c0);});},'afterDestroy':function(_0x25f558,_0x2320bd,_0x598055){return _0x32bd87[_0x83ac('0x1f')]['destroy']({'where':{'ChanSpyId':_0x25f558['id']}})[_0x83ac('0x1a')](function(){_0x598055();})[_0x83ac('0x21')](function(_0x20751b){_0x598055(_0x20751b);});}}});};