Built motion from commit e02f907f.|2.6.14
[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 _0xb6d5=['then','catch','exports','models','VoiceChanSpy','voice_chanspy','length','VoiceExtension','bulkCreate','destroy','bluebird','from-sip','format','push','merge','Set','record','MixMonitor','auth','Authenticate','options','StopMixMonitor','name','concat','User','findAll','internal'];(function(_0x2156ce,_0x528261){var _0x5ef999=function(_0x57306c){while(--_0x57306c){_0x2156ce['push'](_0x2156ce['shift']());}};_0x5ef999(++_0x528261);}(_0xb6d5,0x133));var _0x5b6d=function(_0x36cb22,_0x340b23){_0x36cb22=_0x36cb22-0x0;var _0x5f8af7=_0xb6d5[_0x36cb22];return _0x5f8af7;};'use strict';var _=require('lodash');var util=require('util');var BPromise=require(_0x5b6d('0x0'));var attributes=require('./voiceChanSpy.attributes');var getUserApplications=function(_0x3e5a9e,_0x4a463c,_0x5f4bce){var _0x441748=0x1;var _0x32027b=[];var _0x1a474e={'context':_0x4a463c['context']||_0x5b6d('0x1'),'exten':util[_0x5b6d('0x2')]('%s%s',_0x3e5a9e['prefix'],_0x5f4bce),'type':'system','isApp':![],'ChanSpyId':_0x3e5a9e['id'],'UserId':_0x4a463c['id']};_0x32027b[_0x5b6d('0x3')](_[_0x5b6d('0x4')]({'app':_0x5b6d('0x5'),'appdata':util[_0x5b6d('0x2')]('CDR(type)=%s','chanspy'),'priority':_0x441748++},_0x1a474e));if(_0x3e5a9e[_0x5b6d('0x6')]){_0x32027b['push'](_[_0x5b6d('0x4')]({'app':_0x5b6d('0x7'),'appdata':util['format']('${UNIQUEID}.%s,a',_0x3e5a9e['recordingFormat']),'priority':_0x441748++},_0x1a474e));}if(_0x3e5a9e[_0x5b6d('0x8')]){_0x32027b[_0x5b6d('0x3')](_[_0x5b6d('0x4')]({'app':_0x5b6d('0x9'),'appdata':_0x3e5a9e['password'],'priority':_0x441748++},_0x1a474e));}_0x32027b['push'](_['merge']({'app':'ChanSpy','appdata':util[_0x5b6d('0x2')]('SIP/%s,%s',_0x4a463c['name'],_0x3e5a9e[_0x5b6d('0xa')]?_0x3e5a9e[_0x5b6d('0xa')]['join'](''):''),'priority':_0x441748++},_0x1a474e));if(_0x3e5a9e[_0x5b6d('0x6')]){_0x32027b[_0x5b6d('0x3')](_[_0x5b6d('0x4')]({'app':_0x5b6d('0xb'),'priority':_0x441748++},_0x1a474e));}return _0x32027b;};var getChanSpyApplications=function(_0x1385cf,_0x4756b2){var _0x19d726=[];for(var _0x32c9b8=0x0,_0x6078d7=0x1;_0x32c9b8<_0x4756b2['length'];_0x32c9b8++,_0x6078d7=0x1){_0x19d726=_0x19d726['concat'](getUserApplications(_0x1385cf,_0x4756b2[_0x32c9b8],_0x4756b2[_0x32c9b8]['internal']));if(_0x4756b2[_0x32c9b8]['internal']!=_0x4756b2[_0x32c9b8][_0x5b6d('0xc')]){_0x19d726=_0x19d726[_0x5b6d('0xd')](getUserApplications(_0x1385cf,_0x4756b2[_0x32c9b8],_0x4756b2[_0x32c9b8][_0x5b6d('0xc')]));}}return _0x19d726;};var getChanSpyPromise=function(_0x172a1d,_0x4c587a){return new BPromise(function(_0x29c318,_0x14ee81){return _0x172a1d[_0x5b6d('0xe')][_0x5b6d('0xf')]({'attributes':['id',_0x5b6d('0xc'),_0x5b6d('0x10')],'where':{'role':'agent','chanspy':!![]},'raw':!![]})[_0x5b6d('0x11')](function(_0x175369){if(_0x175369){return _0x29c318(getChanSpyApplications(_0x4c587a,_0x175369));}return _0x29c318([]);})[_0x5b6d('0x12')](function(_0x51b16b){_0x14ee81(_0x51b16b);});});};module[_0x5b6d('0x13')]=function(_0x5c9746,_0x166fe2){var _0x143d07=_0x5c9746[_0x5b6d('0x14')];return _0x5c9746['define'](_0x5b6d('0x15'),attributes,{'tableName':_0x5b6d('0x16'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x19f6e4,_0x27f51a,_0x27aee8){return getChanSpyPromise(_0x143d07,_0x19f6e4)[_0x5b6d('0x11')](function(_0x4d74d8){if(_0x4d74d8&&_0x4d74d8[_0x5b6d('0x17')]){return _0x143d07[_0x5b6d('0x18')][_0x5b6d('0x19')](_0x4d74d8);}})[_0x5b6d('0x11')](function(){_0x27aee8();})['catch'](function(_0x4995ca){_0x27aee8(_0x4995ca);});},'afterUpdate':function(_0x15cf24,_0x3e4d41,_0x498f75){return _0x143d07[_0x5b6d('0x18')][_0x5b6d('0x1a')]({'where':{'ChanSpyId':_0x15cf24['id']}})[_0x5b6d('0x11')](function(){return getChanSpyPromise(_0x143d07,_0x15cf24);})[_0x5b6d('0x11')](function(_0x3b954a){if(_0x3b954a&&_0x3b954a[_0x5b6d('0x17')]){return _0x143d07['VoiceExtension'][_0x5b6d('0x19')](_0x3b954a);}})[_0x5b6d('0x11')](function(){_0x498f75();})[_0x5b6d('0x12')](function(_0x3ac882){_0x498f75(_0x3ac882);});},'afterDestroy':function(_0x4296eb,_0x1c4d64,_0x52e3b5){return _0x143d07[_0x5b6d('0x18')]['destroy']({'where':{'ChanSpyId':_0x4296eb['id']}})['then'](function(){_0x52e3b5();})[_0x5b6d('0x12')](function(_0xd3ba11){_0x52e3b5(_0xd3ba11);});}}});};