Built motion from commit 1fd437e9.|2.6.19
[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 _0x393b=['push','merge','Set','CDR(type)=%s','chanspy','record','MixMonitor','${UNIQUEID}.%s,a','recordingFormat','auth','Authenticate','password','ChanSpy','SIP/%s,%s','name','options','join','concat','internal','User','findAll','then','catch','exports','models','define','VoiceChanSpy','voice_chanspy','VoiceExtension','bulkCreate','destroy','length','lodash','util','bluebird','./voiceChanSpy.attributes','from-sip','format','%s%s','prefix','system'];(function(_0x2d86f2,_0x5e1b5c){var _0x4d2124=function(_0x4b6c2f){while(--_0x4b6c2f){_0x2d86f2['push'](_0x2d86f2['shift']());}};_0x4d2124(++_0x5e1b5c);}(_0x393b,0xed));var _0xb393=function(_0x1416fc,_0x72e155){_0x1416fc=_0x1416fc-0x0;var _0x3a4b34=_0x393b[_0x1416fc];return _0x3a4b34;};'use strict';var _=require(_0xb393('0x0'));var util=require(_0xb393('0x1'));var BPromise=require(_0xb393('0x2'));var attributes=require(_0xb393('0x3'));var getUserApplications=function(_0x561d0f,_0x10d45e,_0xe9144b){var _0x1cb6ed=0x1;var _0x568266=[];var _0x3ea1c0={'context':_0x10d45e['context']||_0xb393('0x4'),'exten':util[_0xb393('0x5')](_0xb393('0x6'),_0x561d0f[_0xb393('0x7')],_0xe9144b),'type':_0xb393('0x8'),'isApp':![],'ChanSpyId':_0x561d0f['id'],'UserId':_0x10d45e['id']};_0x568266[_0xb393('0x9')](_[_0xb393('0xa')]({'app':_0xb393('0xb'),'appdata':util[_0xb393('0x5')](_0xb393('0xc'),_0xb393('0xd')),'priority':_0x1cb6ed++},_0x3ea1c0));if(_0x561d0f[_0xb393('0xe')]){_0x568266['push'](_[_0xb393('0xa')]({'app':_0xb393('0xf'),'appdata':util[_0xb393('0x5')](_0xb393('0x10'),_0x561d0f[_0xb393('0x11')]),'priority':_0x1cb6ed++},_0x3ea1c0));}if(_0x561d0f[_0xb393('0x12')]){_0x568266[_0xb393('0x9')](_['merge']({'app':_0xb393('0x13'),'appdata':_0x561d0f[_0xb393('0x14')],'priority':_0x1cb6ed++},_0x3ea1c0));}_0x568266[_0xb393('0x9')](_[_0xb393('0xa')]({'app':_0xb393('0x15'),'appdata':util['format'](_0xb393('0x16'),_0x10d45e[_0xb393('0x17')],_0x561d0f['options']?_0x561d0f[_0xb393('0x18')][_0xb393('0x19')](''):''),'priority':_0x1cb6ed++},_0x3ea1c0));if(_0x561d0f['record']){_0x568266[_0xb393('0x9')](_[_0xb393('0xa')]({'app':'StopMixMonitor','priority':_0x1cb6ed++},_0x3ea1c0));}return _0x568266;};var getChanSpyApplications=function(_0x5d230b,_0x167551){var _0x52ca03=[];for(var _0x206b88=0x0,_0x12e1df=0x1;_0x206b88<_0x167551['length'];_0x206b88++,_0x12e1df=0x1){_0x52ca03=_0x52ca03[_0xb393('0x1a')](getUserApplications(_0x5d230b,_0x167551[_0x206b88],_0x167551[_0x206b88][_0xb393('0x1b')]));if(_0x167551[_0x206b88][_0xb393('0x1b')]!=_0x167551[_0x206b88][_0xb393('0x17')]){_0x52ca03=_0x52ca03[_0xb393('0x1a')](getUserApplications(_0x5d230b,_0x167551[_0x206b88],_0x167551[_0x206b88]['name']));}}return _0x52ca03;};var getChanSpyPromise=function(_0x49f713,_0x1919fc){return new BPromise(function(_0x153f55,_0x4fb89c){return _0x49f713[_0xb393('0x1c')][_0xb393('0x1d')]({'attributes':['id',_0xb393('0x17'),_0xb393('0x1b')],'where':{'role':'agent','chanspy':!![]},'raw':!![]})[_0xb393('0x1e')](function(_0x2aadbe){if(_0x2aadbe){return _0x153f55(getChanSpyApplications(_0x1919fc,_0x2aadbe));}return _0x153f55([]);})[_0xb393('0x1f')](function(_0x3dbb4f){_0x4fb89c(_0x3dbb4f);});});};module[_0xb393('0x20')]=function(_0x1c5a6b,_0x5e51a3){var _0x3fdb71=_0x1c5a6b[_0xb393('0x21')];return _0x1c5a6b[_0xb393('0x22')](_0xb393('0x23'),attributes,{'tableName':_0xb393('0x24'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x3add5c,_0x7532f,_0x405721){return getChanSpyPromise(_0x3fdb71,_0x3add5c)[_0xb393('0x1e')](function(_0x28e3c8){if(_0x28e3c8&&_0x28e3c8['length']){return _0x3fdb71[_0xb393('0x25')][_0xb393('0x26')](_0x28e3c8);}})['then'](function(){_0x405721();})['catch'](function(_0x4557d8){_0x405721(_0x4557d8);});},'afterUpdate':function(_0x510908,_0x3c5f6b,_0x366215){return _0x3fdb71['VoiceExtension'][_0xb393('0x27')]({'where':{'ChanSpyId':_0x510908['id']}})[_0xb393('0x1e')](function(){return getChanSpyPromise(_0x3fdb71,_0x510908);})[_0xb393('0x1e')](function(_0x4527df){if(_0x4527df&&_0x4527df[_0xb393('0x28')]){return _0x3fdb71[_0xb393('0x25')][_0xb393('0x26')](_0x4527df);}})[_0xb393('0x1e')](function(){_0x366215();})[_0xb393('0x1f')](function(_0x232a5f){_0x366215(_0x232a5f);});},'afterDestroy':function(_0x452d84,_0x377cad,_0xd2f568){return _0x3fdb71[_0xb393('0x25')]['destroy']({'where':{'ChanSpyId':_0x452d84['id']}})['then'](function(){_0xd2f568();})[_0xb393('0x1f')](function(_0x68978){_0xd2f568(_0x68978);});}}});};