a9f599a2a66ec6afbdeb061b64047f5278ebcd57
[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 _0x0cfa=['find','params','body','lodash','ioredis','../../config/logger','api','redis','register','defaults','json','update','then','error','name','status','send','role','admin','Unauthorized','Invalid\x20user\x20setting\x20id','UserSetting'];(function(_0x123c8b,_0x15fbfb){var _0x504004=function(_0x134087){while(--_0x134087){_0x123c8b['push'](_0x123c8b['shift']());}};_0x504004(++_0x15fbfb);}(_0x0cfa,0x18f));var _0xa0cf=function(_0x12c6ec,_0x4e5895){_0x12c6ec=_0x12c6ec-0x0;var _0x5a23f5=_0x0cfa[_0x12c6ec];return _0x5a23f5;};'use strict';var _=require(_0xa0cf('0x0'));var Redis=require(_0xa0cf('0x1'));var logger=require(_0xa0cf('0x2'))(_0xa0cf('0x3'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];var socket=require('socket.io-emitter')(new Redis(config[_0xa0cf('0x4')]));require('./user-setting.socket')[_0xa0cf('0x5')](socket);config[_0xa0cf('0x4')]=_[_0xa0cf('0x6')](config[_0xa0cf('0x4')],{'host':'localhost','port':0x18eb});function respondWithResult(_0x27eb15,_0x5d9035){_0x5d9035=_0x5d9035||0xc8;return function(_0x232245){if(_0x232245){return _0x27eb15['status'](_0x5d9035)[_0xa0cf('0x7')](_0x232245);}};}function saveUpdates(_0x4855d0){return function(_0xaf0993){if(_0xaf0993){return _0xaf0993[_0xa0cf('0x8')](_0x4855d0)[_0xa0cf('0x9')](function(_0x544364){return _0x544364;});}return null;};}function handleEntityNotFound(_0x318f36){return function(_0x327033){if(!_0x327033){_0x318f36['sendStatus'](0x194);}return _0x327033;};}function handleError(_0x47fef5,_0xe98d2a){_0xe98d2a=_0xe98d2a||0x1f4;return function(_0x31f6a7){logger[_0xa0cf('0xa')](_0x31f6a7['stack']);if(_0x31f6a7[_0xa0cf('0xb')]){delete _0x31f6a7[_0xa0cf('0xb')];}_0x47fef5[_0xa0cf('0xc')](_0xe98d2a)[_0xa0cf('0xd')](_0x31f6a7);};}exports[_0xa0cf('0x8')]=function(_0x30c045,_0x235c2f){if(_0x30c045['user'][_0xa0cf('0xe')]!==_0xa0cf('0xf'))throw new Error(_0xa0cf('0x10'));if(isNaN(Number(_0x30c045['params']['id'])))throw new Error(_0xa0cf('0x11'));return db[_0xa0cf('0x12')][_0xa0cf('0x13')]({'where':{'id':_0x30c045[_0xa0cf('0x14')]['id']}})[_0xa0cf('0x9')](handleEntityNotFound(_0x235c2f,null))['then'](saveUpdates(_0x30c045[_0xa0cf('0x15')],null))[_0xa0cf('0x9')](respondWithResult(_0x235c2f,null))['catch'](handleError(_0x235c2f,null));};