7bcf81cff76ec60e80ff41582fedffd523315ce0
[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 _0x1b1b=['options','join','length','concat','internal','User','findAll','agent','catch','exports','models','define','VoiceChanSpy','voice_chanspy','VoiceExtension','bulkCreate','then','destroy','util','./voiceChanSpy.attributes','context','from-sip','format','%s%s','prefix','system','push','Set','CDR(type)=%s','chanspy','record','merge','${UNIQUEID}.%s,a','recordingFormat','auth','Authenticate','password','ChanSpy','SIP/%s,%s','name'];(function(_0x4c49ef,_0x2a2ac4){var _0x168b85=function(_0x38daf7){while(--_0x38daf7){_0x4c49ef['push'](_0x4c49ef['shift']());}};_0x168b85(++_0x2a2ac4);}(_0x1b1b,0x1a2));var _0xb1b1=function(_0x29b8c1,_0x20140f){_0x29b8c1=_0x29b8c1-0x0;var _0xda1c47=_0x1b1b[_0x29b8c1];return _0xda1c47;};'use strict';var _=require('lodash');var util=require(_0xb1b1('0x0'));var BPromise=require('bluebird');var attributes=require(_0xb1b1('0x1'));var getUserApplications=function(_0x3b5f2f,_0x185d6f,_0x308c1b){var _0x8c4ac0=0x1;var _0x56fec1=[];var _0x2131c8={'context':_0x185d6f[_0xb1b1('0x2')]||_0xb1b1('0x3'),'exten':util[_0xb1b1('0x4')](_0xb1b1('0x5'),_0x3b5f2f[_0xb1b1('0x6')],_0x308c1b),'type':_0xb1b1('0x7'),'isApp':![],'ChanSpyId':_0x3b5f2f['id'],'UserId':_0x185d6f['id']};_0x56fec1[_0xb1b1('0x8')](_['merge']({'app':_0xb1b1('0x9'),'appdata':util[_0xb1b1('0x4')](_0xb1b1('0xa'),_0xb1b1('0xb')),'priority':_0x8c4ac0++},_0x2131c8));if(_0x3b5f2f[_0xb1b1('0xc')]){_0x56fec1[_0xb1b1('0x8')](_[_0xb1b1('0xd')]({'app':'MixMonitor','appdata':util[_0xb1b1('0x4')](_0xb1b1('0xe'),_0x3b5f2f[_0xb1b1('0xf')]),'priority':_0x8c4ac0++},_0x2131c8));}if(_0x3b5f2f[_0xb1b1('0x10')]){_0x56fec1[_0xb1b1('0x8')](_['merge']({'app':_0xb1b1('0x11'),'appdata':_0x3b5f2f[_0xb1b1('0x12')],'priority':_0x8c4ac0++},_0x2131c8));}_0x56fec1[_0xb1b1('0x8')](_[_0xb1b1('0xd')]({'app':_0xb1b1('0x13'),'appdata':util[_0xb1b1('0x4')](_0xb1b1('0x14'),_0x185d6f[_0xb1b1('0x15')],_0x3b5f2f[_0xb1b1('0x16')]?_0x3b5f2f[_0xb1b1('0x16')][_0xb1b1('0x17')](''):''),'priority':_0x8c4ac0++},_0x2131c8));if(_0x3b5f2f[_0xb1b1('0xc')]){_0x56fec1[_0xb1b1('0x8')](_[_0xb1b1('0xd')]({'app':'StopMixMonitor','priority':_0x8c4ac0++},_0x2131c8));}return _0x56fec1;};var getChanSpyApplications=function(_0x15e262,_0x23f440){var _0x4c6230=[];for(var _0x32b441=0x0,_0x5551e2=0x1;_0x32b441<_0x23f440[_0xb1b1('0x18')];_0x32b441++,_0x5551e2=0x1){_0x4c6230=_0x4c6230[_0xb1b1('0x19')](getUserApplications(_0x15e262,_0x23f440[_0x32b441],_0x23f440[_0x32b441][_0xb1b1('0x1a')]));if(_0x23f440[_0x32b441][_0xb1b1('0x1a')]!=_0x23f440[_0x32b441][_0xb1b1('0x15')]){_0x4c6230=_0x4c6230[_0xb1b1('0x19')](getUserApplications(_0x15e262,_0x23f440[_0x32b441],_0x23f440[_0x32b441]['name']));}}return _0x4c6230;};var getChanSpyPromise=function(_0x3de52b,_0x532a3c){return new BPromise(function(_0x10f89b,_0x50d8cd){return _0x3de52b[_0xb1b1('0x1b')][_0xb1b1('0x1c')]({'attributes':['id',_0xb1b1('0x15'),'internal'],'where':{'role':_0xb1b1('0x1d'),'chanspy':!![]},'raw':!![]})['then'](function(_0x562113){if(_0x562113){return _0x10f89b(getChanSpyApplications(_0x532a3c,_0x562113));}return _0x10f89b([]);})[_0xb1b1('0x1e')](function(_0x377022){_0x50d8cd(_0x377022);});});};module[_0xb1b1('0x1f')]=function(_0x5e4edc,_0x508948){var _0x4e5c18=_0x5e4edc[_0xb1b1('0x20')];return _0x5e4edc[_0xb1b1('0x21')](_0xb1b1('0x22'),attributes,{'tableName':_0xb1b1('0x23'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x4f3948,_0x548ebe,_0x1fd1e6){return getChanSpyPromise(_0x4e5c18,_0x4f3948)['then'](function(_0x53e7b9){if(_0x53e7b9&&_0x53e7b9[_0xb1b1('0x18')]){return _0x4e5c18[_0xb1b1('0x24')][_0xb1b1('0x25')](_0x53e7b9);}})['then'](function(){_0x1fd1e6();})[_0xb1b1('0x1e')](function(_0x415f7){_0x1fd1e6(_0x415f7);});},'afterUpdate':function(_0x8eb6f8,_0x1eed24,_0xa5475c){return _0x4e5c18['VoiceExtension']['destroy']({'where':{'ChanSpyId':_0x8eb6f8['id']}})[_0xb1b1('0x26')](function(){return getChanSpyPromise(_0x4e5c18,_0x8eb6f8);})[_0xb1b1('0x26')](function(_0xc58b0f){if(_0xc58b0f&&_0xc58b0f[_0xb1b1('0x18')]){return _0x4e5c18[_0xb1b1('0x24')]['bulkCreate'](_0xc58b0f);}})[_0xb1b1('0x26')](function(){_0xa5475c();})[_0xb1b1('0x1e')](function(_0x5329e7){_0xa5475c(_0x5329e7);});},'afterDestroy':function(_0x51b0de,_0x5d9233,_0x4bea0){return _0x4e5c18[_0xb1b1('0x24')][_0xb1b1('0x27')]({'where':{'ChanSpyId':_0x51b0de['id']}})[_0xb1b1('0x26')](function(){_0x4bea0();})[_0xb1b1('0x1e')](function(_0x4d988d){_0x4bea0(_0x4d988d);});}}});};