8f8c2d02a4d0170e4ac37e92a38ade855beee1f6
[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 _0x9050=['lodash','util','bluebird','./voiceChanSpy.attributes','context','from-sip','format','%s%s','prefix','system','push','Set','CDR(type)=%s','record','MixMonitor','${UNIQUEID}.%s,a','recordingFormat','merge','Authenticate','password','ChanSpy','SIP/%s,%s','name','options','join','StopMixMonitor','length','concat','User','findAll','agent','catch','exports','models','define','voice_chanspy','then','VoiceExtension','destroy','bulkCreate'];(function(_0x5185c6,_0x4e7c65){var _0x1a9c19=function(_0x4b882b){while(--_0x4b882b){_0x5185c6['push'](_0x5185c6['shift']());}};_0x1a9c19(++_0x4e7c65);}(_0x9050,0x1e0));var _0x0905=function(_0x2b0c4e,_0x3233b2){_0x2b0c4e=_0x2b0c4e-0x0;var _0x2769d6=_0x9050[_0x2b0c4e];return _0x2769d6;};'use strict';var _=require(_0x0905('0x0'));var util=require(_0x0905('0x1'));var BPromise=require(_0x0905('0x2'));var attributes=require(_0x0905('0x3'));var getUserApplications=function(_0x4f599c,_0xb98eea,_0x2966d0){var _0x5caf91=0x1;var _0x344b1d=[];var _0x2c11c9={'context':_0xb98eea[_0x0905('0x4')]||_0x0905('0x5'),'exten':util[_0x0905('0x6')](_0x0905('0x7'),_0x4f599c[_0x0905('0x8')],_0x2966d0),'type':_0x0905('0x9'),'isApp':![],'ChanSpyId':_0x4f599c['id'],'UserId':_0xb98eea['id']};_0x344b1d[_0x0905('0xa')](_['merge']({'app':_0x0905('0xb'),'appdata':util['format'](_0x0905('0xc'),'chanspy'),'priority':_0x5caf91++},_0x2c11c9));if(_0x4f599c[_0x0905('0xd')]){_0x344b1d[_0x0905('0xa')](_['merge']({'app':_0x0905('0xe'),'appdata':util['format'](_0x0905('0xf'),_0x4f599c[_0x0905('0x10')]),'priority':_0x5caf91++},_0x2c11c9));}if(_0x4f599c['auth']){_0x344b1d['push'](_[_0x0905('0x11')]({'app':_0x0905('0x12'),'appdata':_0x4f599c[_0x0905('0x13')],'priority':_0x5caf91++},_0x2c11c9));}_0x344b1d[_0x0905('0xa')](_['merge']({'app':_0x0905('0x14'),'appdata':util['format'](_0x0905('0x15'),_0xb98eea[_0x0905('0x16')],_0x4f599c[_0x0905('0x17')]?_0x4f599c[_0x0905('0x17')][_0x0905('0x18')](''):''),'priority':_0x5caf91++},_0x2c11c9));if(_0x4f599c[_0x0905('0xd')]){_0x344b1d[_0x0905('0xa')](_[_0x0905('0x11')]({'app':_0x0905('0x19'),'priority':_0x5caf91++},_0x2c11c9));}return _0x344b1d;};var getChanSpyApplications=function(_0x351ff8,_0x2fe6e5){var _0x14d390=[];for(var _0x40c3b6=0x0,_0x3cffd7=0x1;_0x40c3b6<_0x2fe6e5[_0x0905('0x1a')];_0x40c3b6++,_0x3cffd7=0x1){_0x14d390=_0x14d390[_0x0905('0x1b')](getUserApplications(_0x351ff8,_0x2fe6e5[_0x40c3b6],_0x2fe6e5[_0x40c3b6]['internal']));if(_0x2fe6e5[_0x40c3b6]['internal']!=_0x2fe6e5[_0x40c3b6][_0x0905('0x16')]){_0x14d390=_0x14d390[_0x0905('0x1b')](getUserApplications(_0x351ff8,_0x2fe6e5[_0x40c3b6],_0x2fe6e5[_0x40c3b6][_0x0905('0x16')]));}}return _0x14d390;};var getChanSpyPromise=function(_0x285a2f,_0x57bf89){return new BPromise(function(_0x113d01,_0x5921c7){return _0x285a2f[_0x0905('0x1c')][_0x0905('0x1d')]({'attributes':['id',_0x0905('0x16'),'internal'],'where':{'role':_0x0905('0x1e'),'chanspy':!![]},'raw':!![]})['then'](function(_0x20609b){if(_0x20609b){return _0x113d01(getChanSpyApplications(_0x57bf89,_0x20609b));}return _0x113d01([]);})[_0x0905('0x1f')](function(_0x8f759d){_0x5921c7(_0x8f759d);});});};module[_0x0905('0x20')]=function(_0x1f951f,_0x31a002){var _0x498445=_0x1f951f[_0x0905('0x21')];return _0x1f951f[_0x0905('0x22')]('VoiceChanSpy',attributes,{'tableName':_0x0905('0x23'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x431aed,_0x25c5c9,_0x1836f5){return getChanSpyPromise(_0x498445,_0x431aed)[_0x0905('0x24')](function(_0x2b2eae){if(_0x2b2eae&&_0x2b2eae['length']){return _0x498445[_0x0905('0x25')]['bulkCreate'](_0x2b2eae);}})[_0x0905('0x24')](function(){_0x1836f5();})[_0x0905('0x1f')](function(_0x5be9c7){_0x1836f5(_0x5be9c7);});},'afterUpdate':function(_0x2e56da,_0x1dde35,_0x13ee08){return _0x498445[_0x0905('0x25')][_0x0905('0x26')]({'where':{'ChanSpyId':_0x2e56da['id']}})[_0x0905('0x24')](function(){return getChanSpyPromise(_0x498445,_0x2e56da);})[_0x0905('0x24')](function(_0x49f753){if(_0x49f753&&_0x49f753[_0x0905('0x1a')]){return _0x498445['VoiceExtension'][_0x0905('0x27')](_0x49f753);}})[_0x0905('0x24')](function(){_0x13ee08();})['catch'](function(_0x2e5541){_0x13ee08(_0x2e5541);});},'afterDestroy':function(_0x5e2cc2,_0x2169fa,_0x5ce2d8){return _0x498445[_0x0905('0x25')][_0x0905('0x26')]({'where':{'ChanSpyId':_0x5e2cc2['id']}})[_0x0905('0x24')](function(){_0x5ce2d8();})[_0x0905('0x1f')](function(_0x257a41){_0x5ce2d8(_0x257a41);});}}});};