e707380059e1a25b1c584b02f0fbbf36ad73c9ff
[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 _0x2c38=['prefix','push','Set','chanspy','record','merge','${UNIQUEID}.%s,a','recordingFormat','auth','Authenticate','password','ChanSpy','SIP/%s,%s','name','options','StopMixMonitor','concat','internal','findAll','agent','catch','exports','define','VoiceChanSpy','voice_chanspy','then','VoiceExtension','destroy','length','lodash','bluebird','./voiceChanSpy.attributes','from-sip','format','%s%s'];(function(_0x30c28e,_0x33b898){var _0x4e9795=function(_0xb0b7ad){while(--_0xb0b7ad){_0x30c28e['push'](_0x30c28e['shift']());}};_0x4e9795(++_0x33b898);}(_0x2c38,0x112));var _0x82c3=function(_0x5ad3d3,_0x2d400c){_0x5ad3d3=_0x5ad3d3-0x0;var _0x4344e7=_0x2c38[_0x5ad3d3];return _0x4344e7;};'use strict';var _=require(_0x82c3('0x0'));var util=require('util');var BPromise=require(_0x82c3('0x1'));var attributes=require(_0x82c3('0x2'));var getUserApplications=function(_0x582d8b,_0x5bffe3,_0x1e2e3e){var _0x1b18f4=0x1;var _0x962ab1=[];var _0x484a58={'context':_0x5bffe3['context']||_0x82c3('0x3'),'exten':util[_0x82c3('0x4')](_0x82c3('0x5'),_0x582d8b[_0x82c3('0x6')],_0x1e2e3e),'type':'system','isApp':![],'ChanSpyId':_0x582d8b['id'],'UserId':_0x5bffe3['id']};_0x962ab1[_0x82c3('0x7')](_['merge']({'app':_0x82c3('0x8'),'appdata':util['format']('CDR(type)=%s',_0x82c3('0x9')),'priority':_0x1b18f4++},_0x484a58));if(_0x582d8b[_0x82c3('0xa')]){_0x962ab1[_0x82c3('0x7')](_[_0x82c3('0xb')]({'app':'MixMonitor','appdata':util['format'](_0x82c3('0xc'),_0x582d8b[_0x82c3('0xd')]),'priority':_0x1b18f4++},_0x484a58));}if(_0x582d8b[_0x82c3('0xe')]){_0x962ab1[_0x82c3('0x7')](_['merge']({'app':_0x82c3('0xf'),'appdata':_0x582d8b[_0x82c3('0x10')],'priority':_0x1b18f4++},_0x484a58));}_0x962ab1[_0x82c3('0x7')](_['merge']({'app':_0x82c3('0x11'),'appdata':util['format'](_0x82c3('0x12'),_0x5bffe3[_0x82c3('0x13')],_0x582d8b[_0x82c3('0x14')]?_0x582d8b[_0x82c3('0x14')]['join'](''):''),'priority':_0x1b18f4++},_0x484a58));if(_0x582d8b[_0x82c3('0xa')]){_0x962ab1[_0x82c3('0x7')](_[_0x82c3('0xb')]({'app':_0x82c3('0x15'),'priority':_0x1b18f4++},_0x484a58));}return _0x962ab1;};var getChanSpyApplications=function(_0x17d2f4,_0x4e7c13){var _0x39dd09=[];for(var _0x522a2c=0x0,_0x3ca38f=0x1;_0x522a2c<_0x4e7c13['length'];_0x522a2c++,_0x3ca38f=0x1){_0x39dd09=_0x39dd09[_0x82c3('0x16')](getUserApplications(_0x17d2f4,_0x4e7c13[_0x522a2c],_0x4e7c13[_0x522a2c][_0x82c3('0x17')]));if(_0x4e7c13[_0x522a2c][_0x82c3('0x17')]!=_0x4e7c13[_0x522a2c]['name']){_0x39dd09=_0x39dd09[_0x82c3('0x16')](getUserApplications(_0x17d2f4,_0x4e7c13[_0x522a2c],_0x4e7c13[_0x522a2c][_0x82c3('0x13')]));}}return _0x39dd09;};var getChanSpyPromise=function(_0x2deb06,_0x1dcfc1){return new BPromise(function(_0x279995,_0x53d5a2){return _0x2deb06['User'][_0x82c3('0x18')]({'attributes':['id','name','internal'],'where':{'role':_0x82c3('0x19'),'chanspy':!![]},'raw':!![]})['then'](function(_0x2ca01b){if(_0x2ca01b){return _0x279995(getChanSpyApplications(_0x1dcfc1,_0x2ca01b));}return _0x279995([]);})[_0x82c3('0x1a')](function(_0x24ebe1){_0x53d5a2(_0x24ebe1);});});};module[_0x82c3('0x1b')]=function(_0xceb851,_0x1dafa5){var _0x12cad0=_0xceb851['models'];return _0xceb851[_0x82c3('0x1c')](_0x82c3('0x1d'),attributes,{'tableName':_0x82c3('0x1e'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x17843c,_0x127daf,_0x126628){return getChanSpyPromise(_0x12cad0,_0x17843c)[_0x82c3('0x1f')](function(_0x465fd0){if(_0x465fd0&&_0x465fd0['length']){return _0x12cad0[_0x82c3('0x20')]['bulkCreate'](_0x465fd0);}})['then'](function(){_0x126628();})['catch'](function(_0x4e12c8){_0x126628(_0x4e12c8);});},'afterUpdate':function(_0x551388,_0x5bbdac,_0x342611){return _0x12cad0[_0x82c3('0x20')][_0x82c3('0x21')]({'where':{'ChanSpyId':_0x551388['id']}})[_0x82c3('0x1f')](function(){return getChanSpyPromise(_0x12cad0,_0x551388);})[_0x82c3('0x1f')](function(_0x13de01){if(_0x13de01&&_0x13de01[_0x82c3('0x22')]){return _0x12cad0[_0x82c3('0x20')]['bulkCreate'](_0x13de01);}})[_0x82c3('0x1f')](function(){_0x342611();})[_0x82c3('0x1a')](function(_0x5234e7){_0x342611(_0x5234e7);});},'afterDestroy':function(_0x1d4cbf,_0x2bf691,_0x1ff34d){return _0x12cad0[_0x82c3('0x20')][_0x82c3('0x21')]({'where':{'ChanSpyId':_0x1d4cbf['id']}})[_0x82c3('0x1f')](function(){_0x1ff34d();})[_0x82c3('0x1a')](function(_0x10bdc1){_0x1ff34d(_0x10bdc1);});}}});};