Built motion from commit b5413ace.|2.6.9
[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 _0xdb13=['UserSetting','find','body','catch','ioredis','../../config/logger','api','../../config/environment','../../mysqldb','socket.io-emitter','./user-setting.socket','register','redis','defaults','status','json','update','then','error','name','send','Unauthorized','params','Invalid\x20user\x20setting\x20id'];(function(_0x4e1d03,_0x786f3a){var _0x362d4b=function(_0x1924d2){while(--_0x1924d2){_0x4e1d03['push'](_0x4e1d03['shift']());}};_0x362d4b(++_0x786f3a);}(_0xdb13,0x10c));var _0x3db1=function(_0x2303ce,_0x3945e5){_0x2303ce=_0x2303ce-0x0;var _0x546fc4=_0xdb13[_0x2303ce];return _0x546fc4;};'use strict';var _=require('lodash');var Redis=require(_0x3db1('0x0'));var logger=require(_0x3db1('0x1'))(_0x3db1('0x2'));var config=require(_0x3db1('0x3'));var db=require(_0x3db1('0x4'))['db'];var socket=require(_0x3db1('0x5'))(new Redis(config['redis']));require(_0x3db1('0x6'))[_0x3db1('0x7')](socket);config[_0x3db1('0x8')]=_[_0x3db1('0x9')](config[_0x3db1('0x8')],{'host':'localhost','port':0x18eb});function respondWithResult(_0x37ae52,_0x2e1935){_0x2e1935=_0x2e1935||0xc8;return function(_0x28e7b6){if(_0x28e7b6){return _0x37ae52[_0x3db1('0xa')](_0x2e1935)[_0x3db1('0xb')](_0x28e7b6);}};}function saveUpdates(_0x3e6e60){return function(_0x3ac94a){if(_0x3ac94a){return _0x3ac94a[_0x3db1('0xc')](_0x3e6e60)[_0x3db1('0xd')](function(_0xe67f4b){return _0xe67f4b;});}return null;};}function handleEntityNotFound(_0x46f340){return function(_0xfd358f){if(!_0xfd358f){_0x46f340['sendStatus'](0x194);}return _0xfd358f;};}function handleError(_0x68961e,_0xad7eab){_0xad7eab=_0xad7eab||0x1f4;return function(_0x2bab87){logger[_0x3db1('0xe')](_0x2bab87['stack']);if(_0x2bab87['name']){delete _0x2bab87[_0x3db1('0xf')];}_0x68961e[_0x3db1('0xa')](_0xad7eab)[_0x3db1('0x10')](_0x2bab87);};}exports[_0x3db1('0xc')]=function(_0x420188,_0x51e446){if(_0x420188['user']['role']!=='admin')throw new Error(_0x3db1('0x11'));if(isNaN(Number(_0x420188[_0x3db1('0x12')]['id'])))throw new Error(_0x3db1('0x13'));return db[_0x3db1('0x14')][_0x3db1('0x15')]({'where':{'id':_0x420188[_0x3db1('0x12')]['id']}})['then'](handleEntityNotFound(_0x51e446,null))[_0x3db1('0xd')](saveUpdates(_0x420188[_0x3db1('0x16')],null))['then'](respondWithResult(_0x51e446,null))[_0x3db1('0x17')](handleError(_0x51e446,null));};