Built motion from commit (unavailable).|2.5.4
[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 _0x5530=['format','CDR(type)=%s','chanspy','record','merge','MixMonitor','recordingFormat','auth','Authenticate','password','ChanSpy','name','options','join','length','concat','internal','findAll','agent','exports','models','VoiceChanSpy','voice_chanspy','then','VoiceExtension','bulkCreate','catch','lodash','bluebird','./voiceChanSpy.attributes','from-sip','%s%s','prefix','system','push'];(function(_0x97674e,_0x562219){var _0x43fafb=function(_0x4d3366){while(--_0x4d3366){_0x97674e['push'](_0x97674e['shift']());}};_0x43fafb(++_0x562219);}(_0x5530,0xa7));var _0x0553=function(_0x15200e,_0x51b25e){_0x15200e=_0x15200e-0x0;var _0x4e70aa=_0x5530[_0x15200e];return _0x4e70aa;};'use strict';var _=require(_0x0553('0x0'));var util=require('util');var BPromise=require(_0x0553('0x1'));var attributes=require(_0x0553('0x2'));var getUserApplications=function(_0x19a5f3,_0x46b9db,_0x4e3aec){var _0x2c289e=0x1;var _0x5a6597=[];var _0x2368c3={'context':_0x46b9db['context']||_0x0553('0x3'),'exten':util['format'](_0x0553('0x4'),_0x19a5f3[_0x0553('0x5')],_0x4e3aec),'type':_0x0553('0x6'),'isApp':![],'ChanSpyId':_0x19a5f3['id'],'UserId':_0x46b9db['id']};_0x5a6597[_0x0553('0x7')](_['merge']({'app':'Set','appdata':util[_0x0553('0x8')](_0x0553('0x9'),_0x0553('0xa')),'priority':_0x2c289e++},_0x2368c3));if(_0x19a5f3[_0x0553('0xb')]){_0x5a6597[_0x0553('0x7')](_[_0x0553('0xc')]({'app':_0x0553('0xd'),'appdata':util['format']('${UNIQUEID}.%s,a',_0x19a5f3[_0x0553('0xe')]),'priority':_0x2c289e++},_0x2368c3));}if(_0x19a5f3[_0x0553('0xf')]){_0x5a6597[_0x0553('0x7')](_[_0x0553('0xc')]({'app':_0x0553('0x10'),'appdata':_0x19a5f3[_0x0553('0x11')],'priority':_0x2c289e++},_0x2368c3));}_0x5a6597[_0x0553('0x7')](_[_0x0553('0xc')]({'app':_0x0553('0x12'),'appdata':util[_0x0553('0x8')]('SIP/%s,%s',_0x46b9db[_0x0553('0x13')],_0x19a5f3['options']?_0x19a5f3[_0x0553('0x14')][_0x0553('0x15')](''):''),'priority':_0x2c289e++},_0x2368c3));if(_0x19a5f3[_0x0553('0xb')]){_0x5a6597['push'](_[_0x0553('0xc')]({'app':'StopMixMonitor','priority':_0x2c289e++},_0x2368c3));}return _0x5a6597;};var getChanSpyApplications=function(_0x4a8506,_0x1a3863){var _0x46d6ba=[];for(var _0xce8d83=0x0,_0x268b98=0x1;_0xce8d83<_0x1a3863[_0x0553('0x16')];_0xce8d83++,_0x268b98=0x1){_0x46d6ba=_0x46d6ba[_0x0553('0x17')](getUserApplications(_0x4a8506,_0x1a3863[_0xce8d83],_0x1a3863[_0xce8d83][_0x0553('0x18')]));if(_0x1a3863[_0xce8d83]['internal']!=_0x1a3863[_0xce8d83][_0x0553('0x13')]){_0x46d6ba=_0x46d6ba['concat'](getUserApplications(_0x4a8506,_0x1a3863[_0xce8d83],_0x1a3863[_0xce8d83][_0x0553('0x13')]));}}return _0x46d6ba;};var getChanSpyPromise=function(_0x2cc90d,_0x34db96){return new BPromise(function(_0x224498,_0x494e34){return _0x2cc90d['User'][_0x0553('0x19')]({'attributes':['id',_0x0553('0x13'),_0x0553('0x18')],'where':{'role':_0x0553('0x1a'),'chanspy':!![]},'raw':!![]})['then'](function(_0x2e1a90){if(_0x2e1a90){return _0x224498(getChanSpyApplications(_0x34db96,_0x2e1a90));}return _0x224498([]);})['catch'](function(_0x3bde80){_0x494e34(_0x3bde80);});});};module[_0x0553('0x1b')]=function(_0x5f58e0,_0x1d89cb){var _0x22cc5f=_0x5f58e0[_0x0553('0x1c')];return _0x5f58e0['define'](_0x0553('0x1d'),attributes,{'tableName':_0x0553('0x1e'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x3bc9fd,_0x3fd6ae,_0x1e9fc2){return getChanSpyPromise(_0x22cc5f,_0x3bc9fd)[_0x0553('0x1f')](function(_0x1b68dc){if(_0x1b68dc&&_0x1b68dc[_0x0553('0x16')]){return _0x22cc5f[_0x0553('0x20')][_0x0553('0x21')](_0x1b68dc);}})[_0x0553('0x1f')](function(){_0x1e9fc2();})[_0x0553('0x22')](function(_0x58975b){_0x1e9fc2(_0x58975b);});},'afterUpdate':function(_0x30d5a5,_0xf40d1b,_0x3bbdcf){return _0x22cc5f[_0x0553('0x20')]['destroy']({'where':{'ChanSpyId':_0x30d5a5['id']}})['then'](function(){return getChanSpyPromise(_0x22cc5f,_0x30d5a5);})['then'](function(_0x14f389){if(_0x14f389&&_0x14f389['length']){return _0x22cc5f['VoiceExtension']['bulkCreate'](_0x14f389);}})[_0x0553('0x1f')](function(){_0x3bbdcf();})[_0x0553('0x22')](function(_0x122f8e){_0x3bbdcf(_0x122f8e);});},'afterDestroy':function(_0x838e88,_0x353dde,_0x33f4c9){return _0x22cc5f['VoiceExtension']['destroy']({'where':{'ChanSpyId':_0x838e88['id']}})[_0x0553('0x1f')](function(){_0x33f4c9();})[_0x0553('0x22')](function(_0x2c0cc9){_0x33f4c9(_0x2c0cc9);});}}});};