a9bf2d80658d7dc0ae7ce0d491ddd9a453d78b64
[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 _0x342b=['error','stack','name','status','user','role','admin','Unauthorized','params','Invalid\x20user\x20setting\x20id','UserSetting','catch','lodash','../../config/logger','api','../../config/environment','register','redis','defaults','localhost','then','sendStatus'];(function(_0x3226ad,_0x397095){var _0x4637f9=function(_0x4e12c3){while(--_0x4e12c3){_0x3226ad['push'](_0x3226ad['shift']());}};_0x4637f9(++_0x397095);}(_0x342b,0xbc));var _0xb342=function(_0x29bc35,_0x4072eb){_0x29bc35=_0x29bc35-0x0;var _0xd61d48=_0x342b[_0x29bc35];return _0xd61d48;};'use strict';var _=require(_0xb342('0x0'));var Redis=require('ioredis');var logger=require(_0xb342('0x1'))(_0xb342('0x2'));var config=require(_0xb342('0x3'));var db=require('../../mysqldb')['db'];var socket=require('socket.io-emitter')(new Redis(config['redis']));require('./user-setting.socket')[_0xb342('0x4')](socket);config[_0xb342('0x5')]=_[_0xb342('0x6')](config[_0xb342('0x5')],{'host':_0xb342('0x7'),'port':0x18eb});function respondWithResult(_0x2f6281,_0x30106f){_0x30106f=_0x30106f||0xc8;return function(_0x3c7ac7){if(_0x3c7ac7){return _0x2f6281['status'](_0x30106f)['json'](_0x3c7ac7);}};}function saveUpdates(_0x320a07){return function(_0x195587){if(_0x195587){return _0x195587['update'](_0x320a07)[_0xb342('0x8')](function(_0x3fc499){return _0x3fc499;});}return null;};}function handleEntityNotFound(_0x385ef1){return function(_0xdf3923){if(!_0xdf3923){_0x385ef1[_0xb342('0x9')](0x194);}return _0xdf3923;};}function handleError(_0x1cf06c,_0x207a00){_0x207a00=_0x207a00||0x1f4;return function(_0x6c54f3){logger[_0xb342('0xa')](_0x6c54f3[_0xb342('0xb')]);if(_0x6c54f3[_0xb342('0xc')]){delete _0x6c54f3['name'];}_0x1cf06c[_0xb342('0xd')](_0x207a00)['send'](_0x6c54f3);};}exports['update']=function(_0x5171dc,_0x486d98){if(_0x5171dc[_0xb342('0xe')][_0xb342('0xf')]!==_0xb342('0x10'))throw new Error(_0xb342('0x11'));if(isNaN(Number(_0x5171dc[_0xb342('0x12')]['id'])))throw new Error(_0xb342('0x13'));return db[_0xb342('0x14')]['find']({'where':{'id':_0x5171dc[_0xb342('0x12')]['id']}})[_0xb342('0x8')](handleEntityNotFound(_0x486d98,null))['then'](saveUpdates(_0x5171dc['body'],null))['then'](respondWithResult(_0x486d98,null))[_0xb342('0x15')](handleError(_0x486d98,null));};