Built motion from commit (unavailable).|2.5.26
[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 _0xc1fa=['name','options','join','record','StopMixMonitor','length','concat','internal','User','findAll','agent','then','catch','define','VoiceChanSpy','voice_chanspy','VoiceExtension','destroy','bulkCreate','bluebird','./voiceChanSpy.attributes','from-sip','%s%s','prefix','push','Set','format','CDR(type)=%s','chanspy','merge','MixMonitor','recordingFormat','password','ChanSpy','SIP/%s,%s'];(function(_0x189a72,_0x4ac342){var _0x2b457a=function(_0x151b57){while(--_0x151b57){_0x189a72['push'](_0x189a72['shift']());}};_0x2b457a(++_0x4ac342);}(_0xc1fa,0xe5));var _0xac1f=function(_0x35fabd,_0x825452){_0x35fabd=_0x35fabd-0x0;var _0x61a8ee=_0xc1fa[_0x35fabd];return _0x61a8ee;};'use strict';var _=require('lodash');var util=require('util');var BPromise=require(_0xac1f('0x0'));var attributes=require(_0xac1f('0x1'));var getUserApplications=function(_0x21ad52,_0x53bacc,_0x1eb97d){var _0x490d6d=0x1;var _0x46a4de=[];var _0x2c51bb={'context':_0x53bacc['context']||_0xac1f('0x2'),'exten':util['format'](_0xac1f('0x3'),_0x21ad52[_0xac1f('0x4')],_0x1eb97d),'type':'system','isApp':![],'ChanSpyId':_0x21ad52['id'],'UserId':_0x53bacc['id']};_0x46a4de[_0xac1f('0x5')](_['merge']({'app':_0xac1f('0x6'),'appdata':util[_0xac1f('0x7')](_0xac1f('0x8'),_0xac1f('0x9')),'priority':_0x490d6d++},_0x2c51bb));if(_0x21ad52['record']){_0x46a4de[_0xac1f('0x5')](_[_0xac1f('0xa')]({'app':_0xac1f('0xb'),'appdata':util[_0xac1f('0x7')]('${UNIQUEID}.%s,a',_0x21ad52[_0xac1f('0xc')]),'priority':_0x490d6d++},_0x2c51bb));}if(_0x21ad52['auth']){_0x46a4de[_0xac1f('0x5')](_[_0xac1f('0xa')]({'app':'Authenticate','appdata':_0x21ad52[_0xac1f('0xd')],'priority':_0x490d6d++},_0x2c51bb));}_0x46a4de[_0xac1f('0x5')](_['merge']({'app':_0xac1f('0xe'),'appdata':util[_0xac1f('0x7')](_0xac1f('0xf'),_0x53bacc[_0xac1f('0x10')],_0x21ad52[_0xac1f('0x11')]?_0x21ad52[_0xac1f('0x11')][_0xac1f('0x12')](''):''),'priority':_0x490d6d++},_0x2c51bb));if(_0x21ad52[_0xac1f('0x13')]){_0x46a4de[_0xac1f('0x5')](_['merge']({'app':_0xac1f('0x14'),'priority':_0x490d6d++},_0x2c51bb));}return _0x46a4de;};var getChanSpyApplications=function(_0x5d39bf,_0x2ea5b3){var _0x28f7a0=[];for(var _0x3146b8=0x0,_0x3cfb5d=0x1;_0x3146b8<_0x2ea5b3[_0xac1f('0x15')];_0x3146b8++,_0x3cfb5d=0x1){_0x28f7a0=_0x28f7a0[_0xac1f('0x16')](getUserApplications(_0x5d39bf,_0x2ea5b3[_0x3146b8],_0x2ea5b3[_0x3146b8][_0xac1f('0x17')]));if(_0x2ea5b3[_0x3146b8][_0xac1f('0x17')]!=_0x2ea5b3[_0x3146b8][_0xac1f('0x10')]){_0x28f7a0=_0x28f7a0['concat'](getUserApplications(_0x5d39bf,_0x2ea5b3[_0x3146b8],_0x2ea5b3[_0x3146b8]['name']));}}return _0x28f7a0;};var getChanSpyPromise=function(_0x2894e2,_0x3ea6fe){return new BPromise(function(_0x3c376a,_0xd7496){return _0x2894e2[_0xac1f('0x18')][_0xac1f('0x19')]({'attributes':['id',_0xac1f('0x10'),_0xac1f('0x17')],'where':{'role':_0xac1f('0x1a'),'chanspy':!![]},'raw':!![]})[_0xac1f('0x1b')](function(_0x5940d4){if(_0x5940d4){return _0x3c376a(getChanSpyApplications(_0x3ea6fe,_0x5940d4));}return _0x3c376a([]);})[_0xac1f('0x1c')](function(_0x151ba3){_0xd7496(_0x151ba3);});});};module['exports']=function(_0x25b16c,_0x414871){var _0x17339e=_0x25b16c['models'];return _0x25b16c[_0xac1f('0x1d')](_0xac1f('0x1e'),attributes,{'tableName':_0xac1f('0x1f'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x13081e,_0x33b906,_0x47b630){return getChanSpyPromise(_0x17339e,_0x13081e)[_0xac1f('0x1b')](function(_0x1f60ab){if(_0x1f60ab&&_0x1f60ab[_0xac1f('0x15')]){return _0x17339e[_0xac1f('0x20')]['bulkCreate'](_0x1f60ab);}})['then'](function(){_0x47b630();})[_0xac1f('0x1c')](function(_0xcce02d){_0x47b630(_0xcce02d);});},'afterUpdate':function(_0x2e0420,_0x3bd36c,_0x2b491d){return _0x17339e[_0xac1f('0x20')][_0xac1f('0x21')]({'where':{'ChanSpyId':_0x2e0420['id']}})[_0xac1f('0x1b')](function(){return getChanSpyPromise(_0x17339e,_0x2e0420);})[_0xac1f('0x1b')](function(_0x5678d7){if(_0x5678d7&&_0x5678d7[_0xac1f('0x15')]){return _0x17339e[_0xac1f('0x20')][_0xac1f('0x22')](_0x5678d7);}})[_0xac1f('0x1b')](function(){_0x2b491d();})[_0xac1f('0x1c')](function(_0x9fc682){_0x2b491d(_0x9fc682);});},'afterDestroy':function(_0x2e5c1d,_0xaea3c4,_0x2fc4aa){return _0x17339e[_0xac1f('0x20')][_0xac1f('0x21')]({'where':{'ChanSpyId':_0x2e5c1d['id']}})[_0xac1f('0x1b')](function(){_0x2fc4aa();})[_0xac1f('0x1c')](function(_0x28991f){_0x2fc4aa(_0x28991f);});}}});};