1258a9915b7e8bebc8b52187b7a960756b9a6b26
[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 _0xef38=['recordingFormat','auth','Authenticate','password','ChanSpy','SIP/%s,%s','name','options','record','length','concat','internal','User','findAll','agent','then','catch','exports','models','VoiceChanSpy','voice_chanspy','VoiceExtension','bulkCreate','destroy','util','bluebird','./voiceChanSpy.attributes','context','format','%s%s','system','push','merge','Set','CDR(type)=%s','chanspy','MixMonitor','${UNIQUEID}.%s,a'];(function(_0xf71120,_0x25b7f9){var _0xbe2fd3=function(_0x1acbdd){while(--_0x1acbdd){_0xf71120['push'](_0xf71120['shift']());}};_0xbe2fd3(++_0x25b7f9);}(_0xef38,0x122));var _0x8ef3=function(_0x3f50ba,_0x253f5b){_0x3f50ba=_0x3f50ba-0x0;var _0x3bae0a=_0xef38[_0x3f50ba];return _0x3bae0a;};'use strict';var _=require('lodash');var util=require(_0x8ef3('0x0'));var BPromise=require(_0x8ef3('0x1'));var attributes=require(_0x8ef3('0x2'));var getUserApplications=function(_0x5eab3c,_0x57de8c,_0x16510f){var _0x135551=0x1;var _0x1966e7=[];var _0x38a671={'context':_0x57de8c[_0x8ef3('0x3')]||'from-sip','exten':util[_0x8ef3('0x4')](_0x8ef3('0x5'),_0x5eab3c['prefix'],_0x16510f),'type':_0x8ef3('0x6'),'isApp':![],'ChanSpyId':_0x5eab3c['id'],'UserId':_0x57de8c['id']};_0x1966e7[_0x8ef3('0x7')](_[_0x8ef3('0x8')]({'app':_0x8ef3('0x9'),'appdata':util[_0x8ef3('0x4')](_0x8ef3('0xa'),_0x8ef3('0xb')),'priority':_0x135551++},_0x38a671));if(_0x5eab3c['record']){_0x1966e7[_0x8ef3('0x7')](_[_0x8ef3('0x8')]({'app':_0x8ef3('0xc'),'appdata':util[_0x8ef3('0x4')](_0x8ef3('0xd'),_0x5eab3c[_0x8ef3('0xe')]),'priority':_0x135551++},_0x38a671));}if(_0x5eab3c[_0x8ef3('0xf')]){_0x1966e7[_0x8ef3('0x7')](_[_0x8ef3('0x8')]({'app':_0x8ef3('0x10'),'appdata':_0x5eab3c[_0x8ef3('0x11')],'priority':_0x135551++},_0x38a671));}_0x1966e7[_0x8ef3('0x7')](_[_0x8ef3('0x8')]({'app':_0x8ef3('0x12'),'appdata':util[_0x8ef3('0x4')](_0x8ef3('0x13'),_0x57de8c[_0x8ef3('0x14')],_0x5eab3c[_0x8ef3('0x15')]?_0x5eab3c[_0x8ef3('0x15')]['join'](''):''),'priority':_0x135551++},_0x38a671));if(_0x5eab3c[_0x8ef3('0x16')]){_0x1966e7['push'](_[_0x8ef3('0x8')]({'app':'StopMixMonitor','priority':_0x135551++},_0x38a671));}return _0x1966e7;};var getChanSpyApplications=function(_0x22feec,_0x40739c){var _0x51d134=[];for(var _0x56884c=0x0,_0x171ae4=0x1;_0x56884c<_0x40739c[_0x8ef3('0x17')];_0x56884c++,_0x171ae4=0x1){_0x51d134=_0x51d134[_0x8ef3('0x18')](getUserApplications(_0x22feec,_0x40739c[_0x56884c],_0x40739c[_0x56884c][_0x8ef3('0x19')]));if(_0x40739c[_0x56884c]['internal']!=_0x40739c[_0x56884c]['name']){_0x51d134=_0x51d134[_0x8ef3('0x18')](getUserApplications(_0x22feec,_0x40739c[_0x56884c],_0x40739c[_0x56884c][_0x8ef3('0x14')]));}}return _0x51d134;};var getChanSpyPromise=function(_0x159012,_0x4163a4){return new BPromise(function(_0x489aa6,_0xf6a763){return _0x159012[_0x8ef3('0x1a')][_0x8ef3('0x1b')]({'attributes':['id','name','internal'],'where':{'role':_0x8ef3('0x1c'),'chanspy':!![]},'raw':!![]})[_0x8ef3('0x1d')](function(_0x2daa5a){if(_0x2daa5a){return _0x489aa6(getChanSpyApplications(_0x4163a4,_0x2daa5a));}return _0x489aa6([]);})[_0x8ef3('0x1e')](function(_0x15825e){_0xf6a763(_0x15825e);});});};module[_0x8ef3('0x1f')]=function(_0x1231e8,_0x547e6a){var _0x229a53=_0x1231e8[_0x8ef3('0x20')];return _0x1231e8['define'](_0x8ef3('0x21'),attributes,{'tableName':_0x8ef3('0x22'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x2cd940,_0x2947b9,_0x7d8a6c){return getChanSpyPromise(_0x229a53,_0x2cd940)['then'](function(_0x18ef45){if(_0x18ef45&&_0x18ef45[_0x8ef3('0x17')]){return _0x229a53[_0x8ef3('0x23')][_0x8ef3('0x24')](_0x18ef45);}})['then'](function(){_0x7d8a6c();})[_0x8ef3('0x1e')](function(_0x28637a){_0x7d8a6c(_0x28637a);});},'afterUpdate':function(_0x188b8b,_0x2b4752,_0x20478d){return _0x229a53[_0x8ef3('0x23')][_0x8ef3('0x25')]({'where':{'ChanSpyId':_0x188b8b['id']}})[_0x8ef3('0x1d')](function(){return getChanSpyPromise(_0x229a53,_0x188b8b);})[_0x8ef3('0x1d')](function(_0xe4e2ba){if(_0xe4e2ba&&_0xe4e2ba[_0x8ef3('0x17')]){return _0x229a53['VoiceExtension'][_0x8ef3('0x24')](_0xe4e2ba);}})[_0x8ef3('0x1d')](function(){_0x20478d();})[_0x8ef3('0x1e')](function(_0x2b33af){_0x20478d(_0x2b33af);});},'afterDestroy':function(_0x3b9d3a,_0x451027,_0x2c9780){return _0x229a53['VoiceExtension']['destroy']({'where':{'ChanSpyId':_0x3b9d3a['id']}})[_0x8ef3('0x1d')](function(){_0x2c9780();})['catch'](function(_0x41e68f){_0x2c9780(_0x41e68f);});}}});};