f43d70ddd0dc9d64207d8639931965d5bfed44ff
[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 _0x76fb=['agent','catch','VoiceChanSpy','voice_chanspy','then','length','VoiceExtension','bulkCreate','destroy','lodash','bluebird','./voiceChanSpy.attributes','context','from-sip','format','%s%s','system','push','Set','chanspy','record','merge','MixMonitor','${UNIQUEID}.%s,ab','auth','Authenticate','password','SIP/%s,%s','options','join','StopMixMonitor','concat','name','User','findAll','internal'];(function(_0x478700,_0x37977d){var _0x5398a0=function(_0x1d5308){while(--_0x1d5308){_0x478700['push'](_0x478700['shift']());}};_0x5398a0(++_0x37977d);}(_0x76fb,0x129));var _0xb76f=function(_0x520afd,_0x3376d7){_0x520afd=_0x520afd-0x0;var _0x563942=_0x76fb[_0x520afd];return _0x563942;};'use strict';var _=require(_0xb76f('0x0'));var util=require('util');var BPromise=require(_0xb76f('0x1'));var attributes=require(_0xb76f('0x2'));var getUserApplications=function(_0x2cdaec,_0x5c3930,_0x2bd0ce){var _0x2d933f=0x1;var _0x49586a=[];var _0x47e007={'context':_0x5c3930[_0xb76f('0x3')]||_0xb76f('0x4'),'exten':util[_0xb76f('0x5')](_0xb76f('0x6'),_0x2cdaec['prefix'],_0x2bd0ce),'type':_0xb76f('0x7'),'isApp':![],'ChanSpyId':_0x2cdaec['id'],'UserId':_0x5c3930['id']};_0x49586a[_0xb76f('0x8')](_['merge']({'app':_0xb76f('0x9'),'appdata':util[_0xb76f('0x5')]('CDR(type)=%s',_0xb76f('0xa')),'priority':_0x2d933f++},_0x47e007));if(_0x2cdaec[_0xb76f('0xb')]){_0x49586a[_0xb76f('0x8')](_[_0xb76f('0xc')]({'app':_0xb76f('0xd'),'appdata':util[_0xb76f('0x5')](_0xb76f('0xe'),_0x2cdaec['recordingFormat']),'priority':_0x2d933f++},_0x47e007));}if(_0x2cdaec[_0xb76f('0xf')]){_0x49586a[_0xb76f('0x8')](_['merge']({'app':_0xb76f('0x10'),'appdata':_0x2cdaec[_0xb76f('0x11')],'priority':_0x2d933f++},_0x47e007));}_0x49586a[_0xb76f('0x8')](_['merge']({'app':'ChanSpy','appdata':util[_0xb76f('0x5')](_0xb76f('0x12'),_0x5c3930['name'],_0x2cdaec[_0xb76f('0x13')]?_0x2cdaec[_0xb76f('0x13')][_0xb76f('0x14')](''):''),'priority':_0x2d933f++},_0x47e007));if(_0x2cdaec[_0xb76f('0xb')]){_0x49586a['push'](_[_0xb76f('0xc')]({'app':_0xb76f('0x15'),'priority':_0x2d933f++},_0x47e007));}return _0x49586a;};var getChanSpyApplications=function(_0x4975d9,_0x50ed9a){var _0x106339=[];for(var _0x4e7929=0x0,_0x497143=0x1;_0x4e7929<_0x50ed9a['length'];_0x4e7929++,_0x497143=0x1){_0x106339=_0x106339[_0xb76f('0x16')](getUserApplications(_0x4975d9,_0x50ed9a[_0x4e7929],_0x50ed9a[_0x4e7929]['internal']));if(_0x50ed9a[_0x4e7929]['internal']!=_0x50ed9a[_0x4e7929][_0xb76f('0x17')]){_0x106339=_0x106339[_0xb76f('0x16')](getUserApplications(_0x4975d9,_0x50ed9a[_0x4e7929],_0x50ed9a[_0x4e7929][_0xb76f('0x17')]));}}return _0x106339;};var getChanSpyPromise=function(_0x223145,_0x131c32){return new BPromise(function(_0x471fe9,_0x202f0a){return _0x223145[_0xb76f('0x18')][_0xb76f('0x19')]({'attributes':['id',_0xb76f('0x17'),_0xb76f('0x1a')],'where':{'role':_0xb76f('0x1b'),'chanspy':!![]},'raw':!![]})['then'](function(_0x55b756){if(_0x55b756){return _0x471fe9(getChanSpyApplications(_0x131c32,_0x55b756));}return _0x471fe9([]);})[_0xb76f('0x1c')](function(_0x2187eb){_0x202f0a(_0x2187eb);});});};module['exports']=function(_0xde7462,_0x3d6412){var _0x5756e7=_0xde7462['models'];return _0xde7462['define'](_0xb76f('0x1d'),attributes,{'tableName':_0xb76f('0x1e'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x437564,_0x1cb253,_0x13e29a){return getChanSpyPromise(_0x5756e7,_0x437564)[_0xb76f('0x1f')](function(_0x431fca){if(_0x431fca&&_0x431fca[_0xb76f('0x20')]){return _0x5756e7[_0xb76f('0x21')][_0xb76f('0x22')](_0x431fca);}})[_0xb76f('0x1f')](function(){_0x13e29a();})['catch'](function(_0x21f7a7){_0x13e29a(_0x21f7a7);});},'afterUpdate':function(_0x2ef73b,_0x5324c3,_0x3b7f5e){return _0x5756e7[_0xb76f('0x21')][_0xb76f('0x23')]({'where':{'ChanSpyId':_0x2ef73b['id']}})[_0xb76f('0x1f')](function(){return getChanSpyPromise(_0x5756e7,_0x2ef73b);})[_0xb76f('0x1f')](function(_0xe0acdd){if(_0xe0acdd&&_0xe0acdd[_0xb76f('0x20')]){return _0x5756e7['VoiceExtension'][_0xb76f('0x22')](_0xe0acdd);}})['then'](function(){_0x3b7f5e();})[_0xb76f('0x1c')](function(_0x599d3f){_0x3b7f5e(_0x599d3f);});},'afterDestroy':function(_0x566e7a,_0x36149b,_0x3e4e63){return _0x5756e7[_0xb76f('0x21')]['destroy']({'where':{'ChanSpyId':_0x566e7a['id']}})['then'](function(){_0x3e4e63();})[_0xb76f('0x1c')](function(_0x51d5f4){_0x3e4e63(_0x51d5f4);});}}});};