Built motion from commit 511216ff.|2.6.34
[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 _0xed4e=['Set','merge','${UNIQUEID}.%s,a','recordingFormat','auth','Authenticate','password','ChanSpy','SIP/%s,%s','options','join','record','StopMixMonitor','length','concat','internal','name','agent','then','catch','exports','models','define','VoiceChanSpy','voice_chanspy','VoiceExtension','destroy','bulkCreate','lodash','./voiceChanSpy.attributes','context','from-sip','format','%s%s','prefix','system','push'];(function(_0x3c8c38,_0x277bc6){var _0x1edcab=function(_0x90dee3){while(--_0x90dee3){_0x3c8c38['push'](_0x3c8c38['shift']());}};_0x1edcab(++_0x277bc6);}(_0xed4e,0x1b3));var _0xeed4=function(_0x4e1657,_0x30c205){_0x4e1657=_0x4e1657-0x0;var _0x5eb21a=_0xed4e[_0x4e1657];return _0x5eb21a;};'use strict';var _=require(_0xeed4('0x0'));var util=require('util');var BPromise=require('bluebird');var attributes=require(_0xeed4('0x1'));var getUserApplications=function(_0x4d13cb,_0x48d51f,_0x5902fe){var _0x2f32be=0x1;var _0x3599d3=[];var _0x699fbb={'context':_0x48d51f[_0xeed4('0x2')]||_0xeed4('0x3'),'exten':util[_0xeed4('0x4')](_0xeed4('0x5'),_0x4d13cb[_0xeed4('0x6')],_0x5902fe),'type':_0xeed4('0x7'),'isApp':![],'ChanSpyId':_0x4d13cb['id'],'UserId':_0x48d51f['id']};_0x3599d3[_0xeed4('0x8')](_['merge']({'app':_0xeed4('0x9'),'appdata':util[_0xeed4('0x4')]('CDR(type)=%s','chanspy'),'priority':_0x2f32be++},_0x699fbb));if(_0x4d13cb['record']){_0x3599d3['push'](_[_0xeed4('0xa')]({'app':'MixMonitor','appdata':util[_0xeed4('0x4')](_0xeed4('0xb'),_0x4d13cb[_0xeed4('0xc')]),'priority':_0x2f32be++},_0x699fbb));}if(_0x4d13cb[_0xeed4('0xd')]){_0x3599d3[_0xeed4('0x8')](_[_0xeed4('0xa')]({'app':_0xeed4('0xe'),'appdata':_0x4d13cb[_0xeed4('0xf')],'priority':_0x2f32be++},_0x699fbb));}_0x3599d3[_0xeed4('0x8')](_[_0xeed4('0xa')]({'app':_0xeed4('0x10'),'appdata':util[_0xeed4('0x4')](_0xeed4('0x11'),_0x48d51f['name'],_0x4d13cb[_0xeed4('0x12')]?_0x4d13cb[_0xeed4('0x12')][_0xeed4('0x13')](''):''),'priority':_0x2f32be++},_0x699fbb));if(_0x4d13cb[_0xeed4('0x14')]){_0x3599d3[_0xeed4('0x8')](_['merge']({'app':_0xeed4('0x15'),'priority':_0x2f32be++},_0x699fbb));}return _0x3599d3;};var getChanSpyApplications=function(_0x149c7c,_0x174f93){var _0xbfc710=[];for(var _0x36b153=0x0,_0x2b8c16=0x1;_0x36b153<_0x174f93[_0xeed4('0x16')];_0x36b153++,_0x2b8c16=0x1){_0xbfc710=_0xbfc710[_0xeed4('0x17')](getUserApplications(_0x149c7c,_0x174f93[_0x36b153],_0x174f93[_0x36b153][_0xeed4('0x18')]));if(_0x174f93[_0x36b153][_0xeed4('0x18')]!=_0x174f93[_0x36b153][_0xeed4('0x19')]){_0xbfc710=_0xbfc710[_0xeed4('0x17')](getUserApplications(_0x149c7c,_0x174f93[_0x36b153],_0x174f93[_0x36b153][_0xeed4('0x19')]));}}return _0xbfc710;};var getChanSpyPromise=function(_0xeaa3ae,_0x182167){return new BPromise(function(_0xa14065,_0xd2cbbc){return _0xeaa3ae['User']['findAll']({'attributes':['id',_0xeed4('0x19'),'internal'],'where':{'role':_0xeed4('0x1a'),'chanspy':!![]},'raw':!![]})[_0xeed4('0x1b')](function(_0x37dc77){if(_0x37dc77){return _0xa14065(getChanSpyApplications(_0x182167,_0x37dc77));}return _0xa14065([]);})[_0xeed4('0x1c')](function(_0x33f012){_0xd2cbbc(_0x33f012);});});};module[_0xeed4('0x1d')]=function(_0x4c9497,_0x840572){var _0x10998a=_0x4c9497[_0xeed4('0x1e')];return _0x4c9497[_0xeed4('0x1f')](_0xeed4('0x20'),attributes,{'tableName':_0xeed4('0x21'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x58ff97,_0x318a8c,_0x2f803b){return getChanSpyPromise(_0x10998a,_0x58ff97)[_0xeed4('0x1b')](function(_0x3da535){if(_0x3da535&&_0x3da535[_0xeed4('0x16')]){return _0x10998a[_0xeed4('0x22')]['bulkCreate'](_0x3da535);}})[_0xeed4('0x1b')](function(){_0x2f803b();})[_0xeed4('0x1c')](function(_0x406185){_0x2f803b(_0x406185);});},'afterUpdate':function(_0x31a5bd,_0x20333d,_0x8925d6){return _0x10998a[_0xeed4('0x22')][_0xeed4('0x23')]({'where':{'ChanSpyId':_0x31a5bd['id']}})['then'](function(){return getChanSpyPromise(_0x10998a,_0x31a5bd);})[_0xeed4('0x1b')](function(_0xa30160){if(_0xa30160&&_0xa30160['length']){return _0x10998a[_0xeed4('0x22')][_0xeed4('0x24')](_0xa30160);}})[_0xeed4('0x1b')](function(){_0x8925d6();})[_0xeed4('0x1c')](function(_0xc940ae){_0x8925d6(_0xc940ae);});},'afterDestroy':function(_0x179d67,_0x1b99f3,_0x314dd0){return _0x10998a[_0xeed4('0x22')]['destroy']({'where':{'ChanSpyId':_0x179d67['id']}})[_0xeed4('0x1b')](function(){_0x314dd0();})[_0xeed4('0x1c')](function(_0x62f2bb){_0x314dd0(_0x62f2bb);});}}});};