Built motion from commit 47436d59.|2.6.7
[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 _0x90f7=['format','%s%s','prefix','system','merge','Set','CDR(type)=%s','record','push','MixMonitor','${UNIQUEID}.%s,a','recordingFormat','auth','Authenticate','password','ChanSpy','SIP/%s,%s','name','options','join','StopMixMonitor','length','internal','findAll','agent','then','catch','exports','models','define','voice_chanspy','VoiceExtension','bulkCreate','destroy','lodash','./voiceChanSpy.attributes','context','from-sip'];(function(_0x4197ad,_0x1d252e){var _0x24a66a=function(_0x3ed1c5){while(--_0x3ed1c5){_0x4197ad['push'](_0x4197ad['shift']());}};_0x24a66a(++_0x1d252e);}(_0x90f7,0xba));var _0x790f=function(_0x49cee9,_0x28e9de){_0x49cee9=_0x49cee9-0x0;var _0x5c896d=_0x90f7[_0x49cee9];return _0x5c896d;};'use strict';var _=require(_0x790f('0x0'));var util=require('util');var BPromise=require('bluebird');var attributes=require(_0x790f('0x1'));var getUserApplications=function(_0x165015,_0x2041f4,_0x3195a0){var _0xf51350=0x1;var _0x4fbff=[];var _0x11da23={'context':_0x2041f4[_0x790f('0x2')]||_0x790f('0x3'),'exten':util[_0x790f('0x4')](_0x790f('0x5'),_0x165015[_0x790f('0x6')],_0x3195a0),'type':_0x790f('0x7'),'isApp':![],'ChanSpyId':_0x165015['id'],'UserId':_0x2041f4['id']};_0x4fbff['push'](_[_0x790f('0x8')]({'app':_0x790f('0x9'),'appdata':util[_0x790f('0x4')](_0x790f('0xa'),'chanspy'),'priority':_0xf51350++},_0x11da23));if(_0x165015[_0x790f('0xb')]){_0x4fbff[_0x790f('0xc')](_[_0x790f('0x8')]({'app':_0x790f('0xd'),'appdata':util['format'](_0x790f('0xe'),_0x165015[_0x790f('0xf')]),'priority':_0xf51350++},_0x11da23));}if(_0x165015[_0x790f('0x10')]){_0x4fbff[_0x790f('0xc')](_[_0x790f('0x8')]({'app':_0x790f('0x11'),'appdata':_0x165015[_0x790f('0x12')],'priority':_0xf51350++},_0x11da23));}_0x4fbff[_0x790f('0xc')](_[_0x790f('0x8')]({'app':_0x790f('0x13'),'appdata':util[_0x790f('0x4')](_0x790f('0x14'),_0x2041f4[_0x790f('0x15')],_0x165015[_0x790f('0x16')]?_0x165015['options'][_0x790f('0x17')](''):''),'priority':_0xf51350++},_0x11da23));if(_0x165015[_0x790f('0xb')]){_0x4fbff[_0x790f('0xc')](_[_0x790f('0x8')]({'app':_0x790f('0x18'),'priority':_0xf51350++},_0x11da23));}return _0x4fbff;};var getChanSpyApplications=function(_0x4fc000,_0x59ba5d){var _0x1fa417=[];for(var _0x17d59c=0x0,_0x5c3db3=0x1;_0x17d59c<_0x59ba5d[_0x790f('0x19')];_0x17d59c++,_0x5c3db3=0x1){_0x1fa417=_0x1fa417['concat'](getUserApplications(_0x4fc000,_0x59ba5d[_0x17d59c],_0x59ba5d[_0x17d59c][_0x790f('0x1a')]));if(_0x59ba5d[_0x17d59c]['internal']!=_0x59ba5d[_0x17d59c][_0x790f('0x15')]){_0x1fa417=_0x1fa417['concat'](getUserApplications(_0x4fc000,_0x59ba5d[_0x17d59c],_0x59ba5d[_0x17d59c][_0x790f('0x15')]));}}return _0x1fa417;};var getChanSpyPromise=function(_0x5dd652,_0x51c2d2){return new BPromise(function(_0x330134,_0x336943){return _0x5dd652['User'][_0x790f('0x1b')]({'attributes':['id',_0x790f('0x15'),_0x790f('0x1a')],'where':{'role':_0x790f('0x1c'),'chanspy':!![]},'raw':!![]})[_0x790f('0x1d')](function(_0x478e8e){if(_0x478e8e){return _0x330134(getChanSpyApplications(_0x51c2d2,_0x478e8e));}return _0x330134([]);})[_0x790f('0x1e')](function(_0x578092){_0x336943(_0x578092);});});};module[_0x790f('0x1f')]=function(_0x1c8306,_0x1645de){var _0x5e74f2=_0x1c8306[_0x790f('0x20')];return _0x1c8306[_0x790f('0x21')]('VoiceChanSpy',attributes,{'tableName':_0x790f('0x22'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0xf00736,_0x28d46c,_0x42b471){return getChanSpyPromise(_0x5e74f2,_0xf00736)[_0x790f('0x1d')](function(_0x30924b){if(_0x30924b&&_0x30924b[_0x790f('0x19')]){return _0x5e74f2[_0x790f('0x23')][_0x790f('0x24')](_0x30924b);}})[_0x790f('0x1d')](function(){_0x42b471();})[_0x790f('0x1e')](function(_0x17522e){_0x42b471(_0x17522e);});},'afterUpdate':function(_0x56b722,_0x1cb69a,_0x1a341a){return _0x5e74f2[_0x790f('0x23')][_0x790f('0x25')]({'where':{'ChanSpyId':_0x56b722['id']}})[_0x790f('0x1d')](function(){return getChanSpyPromise(_0x5e74f2,_0x56b722);})[_0x790f('0x1d')](function(_0x2c1e01){if(_0x2c1e01&&_0x2c1e01[_0x790f('0x19')]){return _0x5e74f2[_0x790f('0x23')]['bulkCreate'](_0x2c1e01);}})[_0x790f('0x1d')](function(){_0x1a341a();})[_0x790f('0x1e')](function(_0x2b9a8e){_0x1a341a(_0x2b9a8e);});},'afterDestroy':function(_0x4bd57b,_0xaf08a5,_0x18c976){return _0x5e74f2[_0x790f('0x23')][_0x790f('0x25')]({'where':{'ChanSpyId':_0x4bd57b['id']}})['then'](function(){_0x18c976();})['catch'](function(_0x1af4f4){_0x18c976(_0x1af4f4);});}}});};