25ad159b6b7d4122a6ce782c96ac9042d8245212
[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 _0x51e1=['VoiceChanSpy','voice_chanspy','VoiceExtension','destroy','lodash','util','context','from-sip','format','%s%s','system','merge','Set','CDR(type)=%s','chanspy','record','push','MixMonitor','${UNIQUEID}.%s,a','recordingFormat','auth','Authenticate','password','ChanSpy','SIP/%s,%s','name','options','join','length','concat','internal','findAll','agent','then','catch','exports','models','define'];(function(_0x5b2681,_0x180b3e){var _0x1b0275=function(_0x2c2338){while(--_0x2c2338){_0x5b2681['push'](_0x5b2681['shift']());}};_0x1b0275(++_0x180b3e);}(_0x51e1,0xe8));var _0x151e=function(_0x2b2b33,_0x56606f){_0x2b2b33=_0x2b2b33-0x0;var _0x229157=_0x51e1[_0x2b2b33];return _0x229157;};'use strict';var _=require(_0x151e('0x0'));var util=require(_0x151e('0x1'));var BPromise=require('bluebird');var attributes=require('./voiceChanSpy.attributes');var getUserApplications=function(_0x4a2c61,_0x185257,_0x1e4e74){var _0x355852=0x1;var _0x1cf8e7=[];var _0x318aad={'context':_0x185257[_0x151e('0x2')]||_0x151e('0x3'),'exten':util[_0x151e('0x4')](_0x151e('0x5'),_0x4a2c61['prefix'],_0x1e4e74),'type':_0x151e('0x6'),'isApp':![],'ChanSpyId':_0x4a2c61['id'],'UserId':_0x185257['id']};_0x1cf8e7['push'](_[_0x151e('0x7')]({'app':_0x151e('0x8'),'appdata':util[_0x151e('0x4')](_0x151e('0x9'),_0x151e('0xa')),'priority':_0x355852++},_0x318aad));if(_0x4a2c61[_0x151e('0xb')]){_0x1cf8e7[_0x151e('0xc')](_[_0x151e('0x7')]({'app':_0x151e('0xd'),'appdata':util[_0x151e('0x4')](_0x151e('0xe'),_0x4a2c61[_0x151e('0xf')]),'priority':_0x355852++},_0x318aad));}if(_0x4a2c61[_0x151e('0x10')]){_0x1cf8e7[_0x151e('0xc')](_[_0x151e('0x7')]({'app':_0x151e('0x11'),'appdata':_0x4a2c61[_0x151e('0x12')],'priority':_0x355852++},_0x318aad));}_0x1cf8e7[_0x151e('0xc')](_['merge']({'app':_0x151e('0x13'),'appdata':util[_0x151e('0x4')](_0x151e('0x14'),_0x185257[_0x151e('0x15')],_0x4a2c61[_0x151e('0x16')]?_0x4a2c61[_0x151e('0x16')][_0x151e('0x17')](''):''),'priority':_0x355852++},_0x318aad));if(_0x4a2c61['record']){_0x1cf8e7['push'](_[_0x151e('0x7')]({'app':'StopMixMonitor','priority':_0x355852++},_0x318aad));}return _0x1cf8e7;};var getChanSpyApplications=function(_0x23891d,_0x2d5204){var _0x4f8b10=[];for(var _0x22b60a=0x0,_0xfd97c0=0x1;_0x22b60a<_0x2d5204[_0x151e('0x18')];_0x22b60a++,_0xfd97c0=0x1){_0x4f8b10=_0x4f8b10[_0x151e('0x19')](getUserApplications(_0x23891d,_0x2d5204[_0x22b60a],_0x2d5204[_0x22b60a]['internal']));if(_0x2d5204[_0x22b60a][_0x151e('0x1a')]!=_0x2d5204[_0x22b60a][_0x151e('0x15')]){_0x4f8b10=_0x4f8b10[_0x151e('0x19')](getUserApplications(_0x23891d,_0x2d5204[_0x22b60a],_0x2d5204[_0x22b60a]['name']));}}return _0x4f8b10;};var getChanSpyPromise=function(_0x5a4202,_0x15216d){return new BPromise(function(_0xee2b51,_0x423e78){return _0x5a4202['User'][_0x151e('0x1b')]({'attributes':['id','name',_0x151e('0x1a')],'where':{'role':_0x151e('0x1c'),'chanspy':!![]},'raw':!![]})[_0x151e('0x1d')](function(_0xb92fa5){if(_0xb92fa5){return _0xee2b51(getChanSpyApplications(_0x15216d,_0xb92fa5));}return _0xee2b51([]);})[_0x151e('0x1e')](function(_0xfa9ee2){_0x423e78(_0xfa9ee2);});});};module[_0x151e('0x1f')]=function(_0x48bcc0,_0xf9f472){var _0x2b8721=_0x48bcc0[_0x151e('0x20')];return _0x48bcc0[_0x151e('0x21')](_0x151e('0x22'),attributes,{'tableName':_0x151e('0x23'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x200808,_0x130a10,_0x323165){return getChanSpyPromise(_0x2b8721,_0x200808)[_0x151e('0x1d')](function(_0x1a282e){if(_0x1a282e&&_0x1a282e[_0x151e('0x18')]){return _0x2b8721[_0x151e('0x24')]['bulkCreate'](_0x1a282e);}})[_0x151e('0x1d')](function(){_0x323165();})[_0x151e('0x1e')](function(_0x440a6e){_0x323165(_0x440a6e);});},'afterUpdate':function(_0xee5bca,_0x5415e4,_0x47a82f){return _0x2b8721['VoiceExtension'][_0x151e('0x25')]({'where':{'ChanSpyId':_0xee5bca['id']}})[_0x151e('0x1d')](function(){return getChanSpyPromise(_0x2b8721,_0xee5bca);})[_0x151e('0x1d')](function(_0x4a7509){if(_0x4a7509&&_0x4a7509[_0x151e('0x18')]){return _0x2b8721[_0x151e('0x24')]['bulkCreate'](_0x4a7509);}})[_0x151e('0x1d')](function(){_0x47a82f();})[_0x151e('0x1e')](function(_0x531d65){_0x47a82f(_0x531d65);});},'afterDestroy':function(_0x1059a8,_0x3c8bc9,_0x368fe9){return _0x2b8721['VoiceExtension'][_0x151e('0x25')]({'where':{'ChanSpyId':_0x1059a8['id']}})[_0x151e('0x1d')](function(){_0x368fe9();})[_0x151e('0x1e')](function(_0x4d9343){_0x368fe9(_0x4d9343);});}}});};