Built motion from commit 91ed41ac.|2.5.44
[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 _0xf053=['voice_chanspy','then','VoiceExtension','bulkCreate','catch','length','lodash','util','./voiceChanSpy.attributes','context','from-sip','format','%s%s','push','Set','CDR(type)=%s','record','merge','MixMonitor','${UNIQUEID}.%s,a','recordingFormat','Authenticate','password','ChanSpy','name','options','join','StopMixMonitor','concat','internal','User','agent','exports','define'];(function(_0xe02729,_0x324e08){var _0x910ce4=function(_0x36ea7d){while(--_0x36ea7d){_0xe02729['push'](_0xe02729['shift']());}};_0x910ce4(++_0x324e08);}(_0xf053,0xb0));var _0x3f05=function(_0x1914d2,_0x5cf4ee){_0x1914d2=_0x1914d2-0x0;var _0x281199=_0xf053[_0x1914d2];return _0x281199;};'use strict';var _=require(_0x3f05('0x0'));var util=require(_0x3f05('0x1'));var BPromise=require('bluebird');var attributes=require(_0x3f05('0x2'));var getUserApplications=function(_0x57ce72,_0x5ec272,_0x5839bc){var _0x2599ab=0x1;var _0x39abbd=[];var _0x44c650={'context':_0x5ec272[_0x3f05('0x3')]||_0x3f05('0x4'),'exten':util[_0x3f05('0x5')](_0x3f05('0x6'),_0x57ce72['prefix'],_0x5839bc),'type':'system','isApp':![],'ChanSpyId':_0x57ce72['id'],'UserId':_0x5ec272['id']};_0x39abbd[_0x3f05('0x7')](_['merge']({'app':_0x3f05('0x8'),'appdata':util[_0x3f05('0x5')](_0x3f05('0x9'),'chanspy'),'priority':_0x2599ab++},_0x44c650));if(_0x57ce72[_0x3f05('0xa')]){_0x39abbd['push'](_[_0x3f05('0xb')]({'app':_0x3f05('0xc'),'appdata':util[_0x3f05('0x5')](_0x3f05('0xd'),_0x57ce72[_0x3f05('0xe')]),'priority':_0x2599ab++},_0x44c650));}if(_0x57ce72['auth']){_0x39abbd[_0x3f05('0x7')](_[_0x3f05('0xb')]({'app':_0x3f05('0xf'),'appdata':_0x57ce72[_0x3f05('0x10')],'priority':_0x2599ab++},_0x44c650));}_0x39abbd['push'](_[_0x3f05('0xb')]({'app':_0x3f05('0x11'),'appdata':util['format']('SIP/%s,%s',_0x5ec272[_0x3f05('0x12')],_0x57ce72[_0x3f05('0x13')]?_0x57ce72['options'][_0x3f05('0x14')](''):''),'priority':_0x2599ab++},_0x44c650));if(_0x57ce72[_0x3f05('0xa')]){_0x39abbd[_0x3f05('0x7')](_[_0x3f05('0xb')]({'app':_0x3f05('0x15'),'priority':_0x2599ab++},_0x44c650));}return _0x39abbd;};var getChanSpyApplications=function(_0x1711ff,_0x271658){var _0x386c2b=[];for(var _0x419a0e=0x0,_0x581e71=0x1;_0x419a0e<_0x271658['length'];_0x419a0e++,_0x581e71=0x1){_0x386c2b=_0x386c2b[_0x3f05('0x16')](getUserApplications(_0x1711ff,_0x271658[_0x419a0e],_0x271658[_0x419a0e][_0x3f05('0x17')]));if(_0x271658[_0x419a0e][_0x3f05('0x17')]!=_0x271658[_0x419a0e][_0x3f05('0x12')]){_0x386c2b=_0x386c2b[_0x3f05('0x16')](getUserApplications(_0x1711ff,_0x271658[_0x419a0e],_0x271658[_0x419a0e][_0x3f05('0x12')]));}}return _0x386c2b;};var getChanSpyPromise=function(_0x338e0e,_0x2b4c74){return new BPromise(function(_0x5dfa54,_0x5674c8){return _0x338e0e[_0x3f05('0x18')]['findAll']({'attributes':['id',_0x3f05('0x12'),_0x3f05('0x17')],'where':{'role':_0x3f05('0x19'),'chanspy':!![]},'raw':!![]})['then'](function(_0x2d1f99){if(_0x2d1f99){return _0x5dfa54(getChanSpyApplications(_0x2b4c74,_0x2d1f99));}return _0x5dfa54([]);})['catch'](function(_0x9d83ff){_0x5674c8(_0x9d83ff);});});};module[_0x3f05('0x1a')]=function(_0x4d6463,_0x207bbb){var _0x452e88=_0x4d6463['models'];return _0x4d6463[_0x3f05('0x1b')]('VoiceChanSpy',attributes,{'tableName':_0x3f05('0x1c'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x62f078,_0x3e4d09,_0x15e40c){return getChanSpyPromise(_0x452e88,_0x62f078)[_0x3f05('0x1d')](function(_0x304b3c){if(_0x304b3c&&_0x304b3c['length']){return _0x452e88[_0x3f05('0x1e')][_0x3f05('0x1f')](_0x304b3c);}})[_0x3f05('0x1d')](function(){_0x15e40c();})[_0x3f05('0x20')](function(_0x8bc6d){_0x15e40c(_0x8bc6d);});},'afterUpdate':function(_0x565a47,_0x3cf073,_0x492634){return _0x452e88['VoiceExtension']['destroy']({'where':{'ChanSpyId':_0x565a47['id']}})[_0x3f05('0x1d')](function(){return getChanSpyPromise(_0x452e88,_0x565a47);})[_0x3f05('0x1d')](function(_0x2771a7){if(_0x2771a7&&_0x2771a7[_0x3f05('0x21')]){return _0x452e88[_0x3f05('0x1e')][_0x3f05('0x1f')](_0x2771a7);}})['then'](function(){_0x492634();})['catch'](function(_0x1bc27f){_0x492634(_0x1bc27f);});},'afterDestroy':function(_0x5d940c,_0xb3d7f7,_0x1cff64){return _0x452e88[_0x3f05('0x1e')]['destroy']({'where':{'ChanSpyId':_0x5d940c['id']}})[_0x3f05('0x1d')](function(){_0x1cff64();})[_0x3f05('0x20')](function(_0x478cc5){_0x1cff64(_0x478cc5);});}}});};