Built motion from commit 192134f6.|2.6.25
[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 _0xdc70=['password','SIP/%s,%s','name','options','join','StopMixMonitor','concat','internal','User','findAll','agent','then','catch','exports','models','define','voice_chanspy','length','VoiceExtension','bulkCreate','bluebird','./voiceChanSpy.attributes','%s%s','prefix','system','merge','CDR(type)=%s','chanspy','record','push','MixMonitor','format','${UNIQUEID}.%s,a','recordingFormat','auth','Authenticate'];(function(_0x32aae5,_0x90b20d){var _0x5de8b9=function(_0x4f69f4){while(--_0x4f69f4){_0x32aae5['push'](_0x32aae5['shift']());}};_0x5de8b9(++_0x90b20d);}(_0xdc70,0xec));var _0x0dc7=function(_0x33c14b,_0x4179ed){_0x33c14b=_0x33c14b-0x0;var _0x2ca50d=_0xdc70[_0x33c14b];return _0x2ca50d;};'use strict';var _=require('lodash');var util=require('util');var BPromise=require(_0x0dc7('0x0'));var attributes=require(_0x0dc7('0x1'));var getUserApplications=function(_0x13c141,_0x5b56f9,_0x5e4ab5){var _0x53ac0b=0x1;var _0x4e2df0=[];var _0x71bd15={'context':_0x5b56f9['context']||'from-sip','exten':util['format'](_0x0dc7('0x2'),_0x13c141[_0x0dc7('0x3')],_0x5e4ab5),'type':_0x0dc7('0x4'),'isApp':![],'ChanSpyId':_0x13c141['id'],'UserId':_0x5b56f9['id']};_0x4e2df0['push'](_[_0x0dc7('0x5')]({'app':'Set','appdata':util['format'](_0x0dc7('0x6'),_0x0dc7('0x7')),'priority':_0x53ac0b++},_0x71bd15));if(_0x13c141[_0x0dc7('0x8')]){_0x4e2df0[_0x0dc7('0x9')](_[_0x0dc7('0x5')]({'app':_0x0dc7('0xa'),'appdata':util[_0x0dc7('0xb')](_0x0dc7('0xc'),_0x13c141[_0x0dc7('0xd')]),'priority':_0x53ac0b++},_0x71bd15));}if(_0x13c141[_0x0dc7('0xe')]){_0x4e2df0[_0x0dc7('0x9')](_[_0x0dc7('0x5')]({'app':_0x0dc7('0xf'),'appdata':_0x13c141[_0x0dc7('0x10')],'priority':_0x53ac0b++},_0x71bd15));}_0x4e2df0[_0x0dc7('0x9')](_[_0x0dc7('0x5')]({'app':'ChanSpy','appdata':util[_0x0dc7('0xb')](_0x0dc7('0x11'),_0x5b56f9[_0x0dc7('0x12')],_0x13c141[_0x0dc7('0x13')]?_0x13c141[_0x0dc7('0x13')][_0x0dc7('0x14')](''):''),'priority':_0x53ac0b++},_0x71bd15));if(_0x13c141[_0x0dc7('0x8')]){_0x4e2df0[_0x0dc7('0x9')](_[_0x0dc7('0x5')]({'app':_0x0dc7('0x15'),'priority':_0x53ac0b++},_0x71bd15));}return _0x4e2df0;};var getChanSpyApplications=function(_0x247663,_0x492a8b){var _0x55813b=[];for(var _0x4bea86=0x0,_0x124570=0x1;_0x4bea86<_0x492a8b['length'];_0x4bea86++,_0x124570=0x1){_0x55813b=_0x55813b[_0x0dc7('0x16')](getUserApplications(_0x247663,_0x492a8b[_0x4bea86],_0x492a8b[_0x4bea86][_0x0dc7('0x17')]));if(_0x492a8b[_0x4bea86]['internal']!=_0x492a8b[_0x4bea86][_0x0dc7('0x12')]){_0x55813b=_0x55813b[_0x0dc7('0x16')](getUserApplications(_0x247663,_0x492a8b[_0x4bea86],_0x492a8b[_0x4bea86]['name']));}}return _0x55813b;};var getChanSpyPromise=function(_0x54a2a8,_0x2ff90d){return new BPromise(function(_0x9e946d,_0xd4950d){return _0x54a2a8[_0x0dc7('0x18')][_0x0dc7('0x19')]({'attributes':['id',_0x0dc7('0x12'),'internal'],'where':{'role':_0x0dc7('0x1a'),'chanspy':!![]},'raw':!![]})[_0x0dc7('0x1b')](function(_0x4a9f4b){if(_0x4a9f4b){return _0x9e946d(getChanSpyApplications(_0x2ff90d,_0x4a9f4b));}return _0x9e946d([]);})[_0x0dc7('0x1c')](function(_0x2d1c0c){_0xd4950d(_0x2d1c0c);});});};module[_0x0dc7('0x1d')]=function(_0x4cc1ee,_0x511a89){var _0x3e99b5=_0x4cc1ee[_0x0dc7('0x1e')];return _0x4cc1ee[_0x0dc7('0x1f')]('VoiceChanSpy',attributes,{'tableName':_0x0dc7('0x20'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x2dd157,_0x539923,_0x4dc606){return getChanSpyPromise(_0x3e99b5,_0x2dd157)[_0x0dc7('0x1b')](function(_0x2c0998){if(_0x2c0998&&_0x2c0998[_0x0dc7('0x21')]){return _0x3e99b5['VoiceExtension']['bulkCreate'](_0x2c0998);}})[_0x0dc7('0x1b')](function(){_0x4dc606();})[_0x0dc7('0x1c')](function(_0x30ec8b){_0x4dc606(_0x30ec8b);});},'afterUpdate':function(_0x56d779,_0x5ade27,_0x2d3cce){return _0x3e99b5['VoiceExtension']['destroy']({'where':{'ChanSpyId':_0x56d779['id']}})['then'](function(){return getChanSpyPromise(_0x3e99b5,_0x56d779);})['then'](function(_0x513eb5){if(_0x513eb5&&_0x513eb5[_0x0dc7('0x21')]){return _0x3e99b5[_0x0dc7('0x22')][_0x0dc7('0x23')](_0x513eb5);}})[_0x0dc7('0x1b')](function(){_0x2d3cce();})[_0x0dc7('0x1c')](function(_0xbd0478){_0x2d3cce(_0xbd0478);});},'afterDestroy':function(_0x50ed16,_0x3533d7,_0x554499){return _0x3e99b5['VoiceExtension']['destroy']({'where':{'ChanSpyId':_0x50ed16['id']}})[_0x0dc7('0x1b')](function(){_0x554499();})['catch'](function(_0x8b6863){_0x554499(_0x8b6863);});}}});};