Built motion from commit e6806ed6.|2.6.0
[motion2.git] / server / api / user-setting / user-setting.controller.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 _0x4b84=['../../config/environment','redis','./user-setting.socket','register','localhost','status','update','then','sendStatus','error','name','send','role','params','Invalid\x20user\x20setting\x20id','UserSetting','find','body','catch','lodash','ioredis'];(function(_0x5cf82,_0x9bc857){var _0x48f983=function(_0x10ea7b){while(--_0x10ea7b){_0x5cf82['push'](_0x5cf82['shift']());}};_0x48f983(++_0x9bc857);}(_0x4b84,0x1cc));var _0x44b8=function(_0x912d27,_0x28e0e3){_0x912d27=_0x912d27-0x0;var _0x31b918=_0x4b84[_0x912d27];return _0x31b918;};'use strict';var _=require(_0x44b8('0x0'));var Redis=require(_0x44b8('0x1'));var logger=require('../../config/logger')('api');var config=require(_0x44b8('0x2'));var db=require('../../mysqldb')['db'];var socket=require('socket.io-emitter')(new Redis(config[_0x44b8('0x3')]));require(_0x44b8('0x4'))[_0x44b8('0x5')](socket);config['redis']=_['defaults'](config['redis'],{'host':_0x44b8('0x6'),'port':0x18eb});function respondWithResult(_0x54274b,_0x327f59){_0x327f59=_0x327f59||0xc8;return function(_0x5947f7){if(_0x5947f7){return _0x54274b[_0x44b8('0x7')](_0x327f59)['json'](_0x5947f7);}};}function saveUpdates(_0x5034b6){return function(_0x41d515){if(_0x41d515){return _0x41d515[_0x44b8('0x8')](_0x5034b6)[_0x44b8('0x9')](function(_0x48a371){return _0x48a371;});}return null;};}function handleEntityNotFound(_0xc650ec){return function(_0x2cc74b){if(!_0x2cc74b){_0xc650ec[_0x44b8('0xa')](0x194);}return _0x2cc74b;};}function handleError(_0x9b6048,_0x24dd10){_0x24dd10=_0x24dd10||0x1f4;return function(_0x37e471){logger[_0x44b8('0xb')](_0x37e471['stack']);if(_0x37e471[_0x44b8('0xc')]){delete _0x37e471[_0x44b8('0xc')];}_0x9b6048['status'](_0x24dd10)[_0x44b8('0xd')](_0x37e471);};}exports['update']=function(_0x833ea3,_0x18d642){if(_0x833ea3['user'][_0x44b8('0xe')]!=='admin')throw new Error('Unauthorized');if(isNaN(Number(_0x833ea3[_0x44b8('0xf')]['id'])))throw new Error(_0x44b8('0x10'));return db[_0x44b8('0x11')][_0x44b8('0x12')]({'where':{'id':_0x833ea3['params']['id']}})['then'](handleEntityNotFound(_0x18d642,null))['then'](saveUpdates(_0x833ea3[_0x44b8('0x13')],null))['then'](respondWithResult(_0x18d642,null))[_0x44b8('0x14')](handleError(_0x18d642,null));};