55740831897ff5650bba8a183c710a28bbee56e9
[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 _0x252b=['Authenticate','ChanSpy','SIP/%s,%s','name','options','join','StopMixMonitor','length','concat','internal','User','findAll','then','catch','exports','models','define','VoiceChanSpy','VoiceExtension','bulkCreate','lodash','util','bluebird','context','%s%s','prefix','system','push','merge','Set','format','CDR(type)=%s','chanspy','record','MixMonitor','${UNIQUEID}.%s,a','auth'];(function(_0x593d89,_0x45145f){var _0x4aa403=function(_0x21f674){while(--_0x21f674){_0x593d89['push'](_0x593d89['shift']());}};_0x4aa403(++_0x45145f);}(_0x252b,0x117));var _0xb252=function(_0x1fd8b3,_0x3bd29a){_0x1fd8b3=_0x1fd8b3-0x0;var _0x1f461f=_0x252b[_0x1fd8b3];return _0x1f461f;};'use strict';var _=require(_0xb252('0x0'));var util=require(_0xb252('0x1'));var BPromise=require(_0xb252('0x2'));var attributes=require('./voiceChanSpy.attributes');var getUserApplications=function(_0x18267a,_0x26e43d,_0x5f545b){var _0x441e74=0x1;var _0x43947d=[];var _0x2519fa={'context':_0x26e43d[_0xb252('0x3')]||'from-sip','exten':util['format'](_0xb252('0x4'),_0x18267a[_0xb252('0x5')],_0x5f545b),'type':_0xb252('0x6'),'isApp':![],'ChanSpyId':_0x18267a['id'],'UserId':_0x26e43d['id']};_0x43947d[_0xb252('0x7')](_[_0xb252('0x8')]({'app':_0xb252('0x9'),'appdata':util[_0xb252('0xa')](_0xb252('0xb'),_0xb252('0xc')),'priority':_0x441e74++},_0x2519fa));if(_0x18267a[_0xb252('0xd')]){_0x43947d[_0xb252('0x7')](_[_0xb252('0x8')]({'app':_0xb252('0xe'),'appdata':util[_0xb252('0xa')](_0xb252('0xf'),_0x18267a['recordingFormat']),'priority':_0x441e74++},_0x2519fa));}if(_0x18267a[_0xb252('0x10')]){_0x43947d[_0xb252('0x7')](_['merge']({'app':_0xb252('0x11'),'appdata':_0x18267a['password'],'priority':_0x441e74++},_0x2519fa));}_0x43947d[_0xb252('0x7')](_['merge']({'app':_0xb252('0x12'),'appdata':util[_0xb252('0xa')](_0xb252('0x13'),_0x26e43d[_0xb252('0x14')],_0x18267a[_0xb252('0x15')]?_0x18267a[_0xb252('0x15')][_0xb252('0x16')](''):''),'priority':_0x441e74++},_0x2519fa));if(_0x18267a[_0xb252('0xd')]){_0x43947d[_0xb252('0x7')](_[_0xb252('0x8')]({'app':_0xb252('0x17'),'priority':_0x441e74++},_0x2519fa));}return _0x43947d;};var getChanSpyApplications=function(_0x1ea9d6,_0x386e0b){var _0x37d992=[];for(var _0x4d5977=0x0,_0xcc2aa6=0x1;_0x4d5977<_0x386e0b[_0xb252('0x18')];_0x4d5977++,_0xcc2aa6=0x1){_0x37d992=_0x37d992[_0xb252('0x19')](getUserApplications(_0x1ea9d6,_0x386e0b[_0x4d5977],_0x386e0b[_0x4d5977][_0xb252('0x1a')]));if(_0x386e0b[_0x4d5977][_0xb252('0x1a')]!=_0x386e0b[_0x4d5977]['name']){_0x37d992=_0x37d992[_0xb252('0x19')](getUserApplications(_0x1ea9d6,_0x386e0b[_0x4d5977],_0x386e0b[_0x4d5977]['name']));}}return _0x37d992;};var getChanSpyPromise=function(_0x5defed,_0x4c493b){return new BPromise(function(_0x566558,_0x40cfc2){return _0x5defed[_0xb252('0x1b')][_0xb252('0x1c')]({'attributes':['id',_0xb252('0x14'),_0xb252('0x1a')],'where':{'role':'agent','chanspy':!![]},'raw':!![]})[_0xb252('0x1d')](function(_0x163e8b){if(_0x163e8b){return _0x566558(getChanSpyApplications(_0x4c493b,_0x163e8b));}return _0x566558([]);})[_0xb252('0x1e')](function(_0x53c0a1){_0x40cfc2(_0x53c0a1);});});};module[_0xb252('0x1f')]=function(_0x1c65b6,_0x923f18){var _0x3d6bd7=_0x1c65b6[_0xb252('0x20')];return _0x1c65b6[_0xb252('0x21')](_0xb252('0x22'),attributes,{'tableName':'voice_chanspy','paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x4faa76,_0x3ed70c,_0x57d5e6){return getChanSpyPromise(_0x3d6bd7,_0x4faa76)['then'](function(_0x3e5cde){if(_0x3e5cde&&_0x3e5cde[_0xb252('0x18')]){return _0x3d6bd7[_0xb252('0x23')]['bulkCreate'](_0x3e5cde);}})[_0xb252('0x1d')](function(){_0x57d5e6();})[_0xb252('0x1e')](function(_0x53599c){_0x57d5e6(_0x53599c);});},'afterUpdate':function(_0x113644,_0x1031f8,_0x1110d9){return _0x3d6bd7[_0xb252('0x23')]['destroy']({'where':{'ChanSpyId':_0x113644['id']}})[_0xb252('0x1d')](function(){return getChanSpyPromise(_0x3d6bd7,_0x113644);})['then'](function(_0x324448){if(_0x324448&&_0x324448[_0xb252('0x18')]){return _0x3d6bd7[_0xb252('0x23')][_0xb252('0x24')](_0x324448);}})[_0xb252('0x1d')](function(){_0x1110d9();})['catch'](function(_0xc293ce){_0x1110d9(_0xc293ce);});},'afterDestroy':function(_0x50bd3e,_0x14f565,_0x3e464c){return _0x3d6bd7['VoiceExtension']['destroy']({'where':{'ChanSpyId':_0x50bd3e['id']}})[_0xb252('0x1d')](function(){_0x3e464c();})[_0xb252('0x1e')](function(_0x564c6d){_0x3e464c(_0x564c6d);});}}});};