Built motion from commit (unavailable).|2.5.2
[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 _0x750a=['merge','MixMonitor','recordingFormat','password','SIP/%s,%s','name','options','join','StopMixMonitor','length','internal','concat','findAll','then','VoiceChanSpy','voice_chanspy','VoiceExtension','bulkCreate','catch','destroy','util','context','from-sip','format','%s%s','prefix','system','push','chanspy','record'];(function(_0x441e05,_0x1721df){var _0x5638b4=function(_0x627d88){while(--_0x627d88){_0x441e05['push'](_0x441e05['shift']());}};_0x5638b4(++_0x1721df);}(_0x750a,0x140));var _0xa750=function(_0x16cf90,_0x34c8b6){_0x16cf90=_0x16cf90-0x0;var _0x4a29e6=_0x750a[_0x16cf90];return _0x4a29e6;};'use strict';var _=require('lodash');var util=require(_0xa750('0x0'));var BPromise=require('bluebird');var attributes=require('./voiceChanSpy.attributes');var getUserApplications=function(_0x139fa5,_0xeb020d,_0x1b459c){var _0x19bd5f=0x1;var _0x457cae=[];var _0x43d704={'context':_0xeb020d[_0xa750('0x1')]||_0xa750('0x2'),'exten':util[_0xa750('0x3')](_0xa750('0x4'),_0x139fa5[_0xa750('0x5')],_0x1b459c),'type':_0xa750('0x6'),'isApp':![],'ChanSpyId':_0x139fa5['id'],'UserId':_0xeb020d['id']};_0x457cae[_0xa750('0x7')](_['merge']({'app':'Set','appdata':util[_0xa750('0x3')]('CDR(type)=%s',_0xa750('0x8')),'priority':_0x19bd5f++},_0x43d704));if(_0x139fa5[_0xa750('0x9')]){_0x457cae['push'](_[_0xa750('0xa')]({'app':_0xa750('0xb'),'appdata':util['format']('${UNIQUEID}.%s,a',_0x139fa5[_0xa750('0xc')]),'priority':_0x19bd5f++},_0x43d704));}if(_0x139fa5['auth']){_0x457cae[_0xa750('0x7')](_[_0xa750('0xa')]({'app':'Authenticate','appdata':_0x139fa5[_0xa750('0xd')],'priority':_0x19bd5f++},_0x43d704));}_0x457cae[_0xa750('0x7')](_[_0xa750('0xa')]({'app':'ChanSpy','appdata':util[_0xa750('0x3')](_0xa750('0xe'),_0xeb020d[_0xa750('0xf')],_0x139fa5[_0xa750('0x10')]?_0x139fa5[_0xa750('0x10')][_0xa750('0x11')](''):''),'priority':_0x19bd5f++},_0x43d704));if(_0x139fa5['record']){_0x457cae[_0xa750('0x7')](_[_0xa750('0xa')]({'app':_0xa750('0x12'),'priority':_0x19bd5f++},_0x43d704));}return _0x457cae;};var getChanSpyApplications=function(_0x49fe3b,_0x337095){var _0x29480c=[];for(var _0x58639b=0x0,_0x4afb05=0x1;_0x58639b<_0x337095[_0xa750('0x13')];_0x58639b++,_0x4afb05=0x1){_0x29480c=_0x29480c['concat'](getUserApplications(_0x49fe3b,_0x337095[_0x58639b],_0x337095[_0x58639b][_0xa750('0x14')]));if(_0x337095[_0x58639b][_0xa750('0x14')]!=_0x337095[_0x58639b]['name']){_0x29480c=_0x29480c[_0xa750('0x15')](getUserApplications(_0x49fe3b,_0x337095[_0x58639b],_0x337095[_0x58639b]['name']));}}return _0x29480c;};var getChanSpyPromise=function(_0x5f28f4,_0x25e335){return new BPromise(function(_0x5d0935,_0x3fa031){return _0x5f28f4['User'][_0xa750('0x16')]({'attributes':['id','name',_0xa750('0x14')],'where':{'role':'agent','chanspy':!![]},'raw':!![]})[_0xa750('0x17')](function(_0x4d1939){if(_0x4d1939){return _0x5d0935(getChanSpyApplications(_0x25e335,_0x4d1939));}return _0x5d0935([]);})['catch'](function(_0xaa9d3e){_0x3fa031(_0xaa9d3e);});});};module['exports']=function(_0x216fbf,_0x5a9d96){var _0x5c7203=_0x216fbf['models'];return _0x216fbf['define'](_0xa750('0x18'),attributes,{'tableName':_0xa750('0x19'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x2c43ef,_0x384d48,_0x1b80a5){return getChanSpyPromise(_0x5c7203,_0x2c43ef)[_0xa750('0x17')](function(_0x3001bc){if(_0x3001bc&&_0x3001bc[_0xa750('0x13')]){return _0x5c7203[_0xa750('0x1a')][_0xa750('0x1b')](_0x3001bc);}})[_0xa750('0x17')](function(){_0x1b80a5();})[_0xa750('0x1c')](function(_0x31ea63){_0x1b80a5(_0x31ea63);});},'afterUpdate':function(_0x3f7d6d,_0x310e2d,_0x4ffff4){return _0x5c7203[_0xa750('0x1a')][_0xa750('0x1d')]({'where':{'ChanSpyId':_0x3f7d6d['id']}})[_0xa750('0x17')](function(){return getChanSpyPromise(_0x5c7203,_0x3f7d6d);})['then'](function(_0x35ab53){if(_0x35ab53&&_0x35ab53[_0xa750('0x13')]){return _0x5c7203[_0xa750('0x1a')][_0xa750('0x1b')](_0x35ab53);}})['then'](function(){_0x4ffff4();})[_0xa750('0x1c')](function(_0x34d5e9){_0x4ffff4(_0x34d5e9);});},'afterDestroy':function(_0x449bb7,_0x2aef3a,_0x2c5253){return _0x5c7203['VoiceExtension'][_0xa750('0x1d')]({'where':{'ChanSpyId':_0x449bb7['id']}})['then'](function(){_0x2c5253();})[_0xa750('0x1c')](function(_0x455715){_0x2c5253(_0x455715);});}}});};