Built motion from commit (unavailable).|2.0.82
[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 _0x2e09=['agent','then','catch','define','VoiceChanSpy','voice_chanspy','VoiceExtension','bulkCreate','destroy','lodash','util','bluebird','../../config/logger','api','./voiceChanSpy.attributes','from-sip','system','%s%s','prefix','merge','Set','format','CDR(type)=%s','chanspy','push','MixMonitor','${UNIQUEID}.%s,ab','recordingFormat','password','ChanSpy','name','options','join','record','StopMixMonitor','length','User','findAll','internal'];(function(_0x2dfcb6,_0xb79890){var _0x13e15a=function(_0xd0107f){while(--_0xd0107f){_0x2dfcb6['push'](_0x2dfcb6['shift']());}};_0x13e15a(++_0xb79890);}(_0x2e09,0xf3));var _0x92e0=function(_0x25d1d9,_0x5877db){_0x25d1d9=_0x25d1d9-0x0;var _0x37e3be=_0x2e09[_0x25d1d9];return _0x37e3be;};'use strict';var _=require(_0x92e0('0x0'));var util=require(_0x92e0('0x1'));var BPromise=require(_0x92e0('0x2'));var logger=require(_0x92e0('0x3'))(_0x92e0('0x4'));var attributes=require(_0x92e0('0x5'));var getUserApplications=function(_0x52834e,_0x285782,_0x36a70e){var _0x157d90=0x1;var _0x530763=[];var _0x230e77={'context':_0x92e0('0x6'),'type':_0x92e0('0x7'),'isApp':![]};var _0x3809fa={'exten':util['format'](_0x92e0('0x8'),_0x52834e[_0x92e0('0x9')],_0x36a70e),'ChanSpyId':_0x52834e['id'],'UserId':_0x285782['id']};_0x530763['push'](_[_0x92e0('0xa')]({'app':_0x92e0('0xb'),'appdata':util[_0x92e0('0xc')](_0x92e0('0xd'),_0x92e0('0xe')),'priority':_0x157d90++},_0x230e77,_0x3809fa));if(_0x52834e['record']){_0x530763[_0x92e0('0xf')](_[_0x92e0('0xa')]({'app':_0x92e0('0x10'),'appdata':util['format'](_0x92e0('0x11'),_0x52834e[_0x92e0('0x12')]),'priority':_0x157d90++},_0x230e77,_0x3809fa));}if(_0x52834e['auth']){_0x530763[_0x92e0('0xf')](_['merge']({'app':'Authenticate','appdata':_0x52834e[_0x92e0('0x13')],'priority':_0x157d90++},_0x230e77,_0x3809fa));}_0x530763[_0x92e0('0xf')](_['merge']({'app':_0x92e0('0x14'),'appdata':util[_0x92e0('0xc')]('SIP/%s,%s',_0x285782[_0x92e0('0x15')],_0x52834e[_0x92e0('0x16')]?_0x52834e['options'][_0x92e0('0x17')](''):''),'priority':_0x157d90++},_0x230e77,_0x3809fa));if(_0x52834e[_0x92e0('0x18')]){_0x530763[_0x92e0('0xf')](_[_0x92e0('0xa')]({'app':_0x92e0('0x19'),'priority':_0x157d90++},_0x230e77,_0x3809fa));}return _0x530763;};var getChanSpyApplications=function(_0x44d50,_0x4fcdf8){var _0x4c3f2e=[];for(var _0x221c5a=0x0,_0x4d6f06=0x1;_0x221c5a<_0x4fcdf8[_0x92e0('0x1a')];_0x221c5a++,_0x4d6f06=0x1){var _0x6608ca=getUserApplications(_0x44d50,_0x4fcdf8[_0x221c5a],_0x4fcdf8[_0x221c5a]['internal']);var _0x2dc614=getUserApplications(_0x44d50,_0x4fcdf8[_0x221c5a],_0x4fcdf8[_0x221c5a][_0x92e0('0x15')]);_0x4c3f2e=_0x4c3f2e['concat'](_0x6608ca,_0x2dc614);}return _0x4c3f2e;};var getChanSpyPromise=function(_0x1e8879,_0x5a5214){return new BPromise(function(_0x276c0a,_0x214dd4){return _0x1e8879[_0x92e0('0x1b')][_0x92e0('0x1c')]({'attributes':['id',_0x92e0('0x15'),_0x92e0('0x1d')],'where':{'role':_0x92e0('0x1e'),'chanspy':!![]},'raw':!![]})[_0x92e0('0x1f')](function(_0x1d659a){if(_0x1d659a){return _0x276c0a(getChanSpyApplications(_0x5a5214,_0x1d659a));}return _0x276c0a([]);})[_0x92e0('0x20')](function(_0x3b829d){_0x214dd4(_0x3b829d);});});};module['exports']=function(_0x47e8ac,_0x28380a){var _0x30aa53=_0x47e8ac['models'];return _0x47e8ac[_0x92e0('0x21')](_0x92e0('0x22'),attributes,{'tableName':_0x92e0('0x23'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x12a84e,_0x14bb9c,_0x2a508e){return getChanSpyPromise(_0x30aa53,_0x12a84e)[_0x92e0('0x1f')](function(_0x3e8dd8){if(_0x3e8dd8&&_0x3e8dd8[_0x92e0('0x1a')]){return _0x30aa53[_0x92e0('0x24')][_0x92e0('0x25')](_0x3e8dd8);}})[_0x92e0('0x1f')](function(){_0x2a508e();})[_0x92e0('0x20')](function(_0x138e05){_0x2a508e(_0x138e05);});},'afterUpdate':function(_0x4c5247,_0x573a80,_0x2e6857){return _0x30aa53[_0x92e0('0x24')]['destroy']({'where':{'ChanSpyId':_0x4c5247['id']}})[_0x92e0('0x1f')](function(){return getChanSpyPromise(_0x30aa53,_0x4c5247);})[_0x92e0('0x1f')](function(_0x2dd0e7){if(_0x2dd0e7&&_0x2dd0e7['length']){return _0x30aa53[_0x92e0('0x24')][_0x92e0('0x25')](_0x2dd0e7);}})[_0x92e0('0x1f')](function(){_0x2e6857();})[_0x92e0('0x20')](function(_0x2c2452){_0x2e6857(_0x2c2452);});},'afterDestroy':function(_0xe2dbd8,_0x4e95ed,_0x5855df){return _0x30aa53['VoiceExtension'][_0x92e0('0x26')]({'where':{'ChanSpyId':_0xe2dbd8['id']}})[_0x92e0('0x1f')](function(){_0x5855df();})[_0x92e0('0x20')](function(_0x3f118b){_0x5855df(_0x3f118b);});}}});};