36f59966d3b07b71d32539bd4e668b85d8af4685
[motion2.git] / server / config / utils.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 _0xa1b9=['role','agent','User','count','then','agents','catch','lodash','bluebird','../mysqldb','voice','mail','chat','fax','openchannel','toLowerCase','includes','clearBlockUser','isUndefined','getLicense'];(function(_0x3cf4d3,_0x48065e){var _0x4e547b=function(_0x28f85a){while(--_0x28f85a){_0x3cf4d3['push'](_0x3cf4d3['shift']());}};_0x4e547b(++_0x48065e);}(_0xa1b9,0x15b));var _0x9a1b=function(_0x2f5ac5,_0x1ee939){_0x2f5ac5=_0x2f5ac5-0x0;var _0x37c9a8=_0xa1b9[_0x2f5ac5];return _0x37c9a8;};'use strict';var _=require(_0x9a1b('0x0'));var BPromise=require(_0x9a1b('0x1'));var db=require(_0x9a1b('0x2'))['db'];var util=require('./license/util');var channels=[_0x9a1b('0x3'),_0x9a1b('0x4'),_0x9a1b('0x5'),_0x9a1b('0x6'),'sms','whatsapp',_0x9a1b('0x7')];exports['getChannels']=function(){return channels;};exports['isValidChannel']=function(_0x3ab67c){_0x3ab67c=_0x3ab67c[_0x9a1b('0x8')]();return _[_0x9a1b('0x9')](channels,_0x3ab67c);};exports[_0x9a1b('0xa')]=function(_0x36ad20,_0x342053,_0x4128c7,_0x3dcd41){var _0x233f1e={'loginAttempts':_0x342053,'blocked':_0x4128c7};if(!_[_0x9a1b('0xb')](_0x3dcd41)){_0x233f1e['blockedAt']=_0x3dcd41;}return _0x36ad20['updateAttributes'](_0x233f1e);};exports[_0x9a1b('0xc')]=function(_0x568e57){return new BPromise(function(_0x351fe5,_0x193b22){var _0x3ec526=0x0;if(_0x568e57[_0x9a1b('0xd')]!==_0x9a1b('0xe')){_0x351fe5(_0x568e57);}db[_0x9a1b('0xf')][_0x9a1b('0x10')]({'where':{'role':_0x9a1b('0xe'),'online':!![],'id':{'$ne':_0x568e57['id']}}})[_0x9a1b('0x11')](function(_0x1af560){_0x3ec526=_0x1af560;return util['getLicense']();})['then'](function(_0x1e4e14){if(_0x1e4e14&&_0x1e4e14['agents']&&_0x3ec526>=_0x1e4e14[_0x9a1b('0x12')]){throw Error('Maximum\x20login\x20has\x20been\x20reached');}_0x351fe5(_0x568e57);})[_0x9a1b('0x13')](function(_0x582882){_0x193b22(_0x582882);});});};