Built motion from commit 00bf23f6.|2.6.16
[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 _0x919e=['sendStatus','name','status','role','admin','Unauthorized','params','Invalid\x20user\x20setting\x20id','UserSetting','find','catch','lodash','ioredis','../../config/logger','../../config/environment','redis','./user-setting.socket','register','defaults','localhost','json','update','then'];(function(_0x4202ca,_0x1a7d3b){var _0x59af57=function(_0x5f04fe){while(--_0x5f04fe){_0x4202ca['push'](_0x4202ca['shift']());}};_0x59af57(++_0x1a7d3b);}(_0x919e,0x1d7));var _0xe919=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x919e[_0x3dd15e];return _0x231fd0;};'use strict';var _=require(_0xe919('0x0'));var Redis=require(_0xe919('0x1'));var logger=require(_0xe919('0x2'))('api');var config=require(_0xe919('0x3'));var db=require('../../mysqldb')['db'];var socket=require('socket.io-emitter')(new Redis(config[_0xe919('0x4')]));require(_0xe919('0x5'))[_0xe919('0x6')](socket);config[_0xe919('0x4')]=_[_0xe919('0x7')](config[_0xe919('0x4')],{'host':_0xe919('0x8'),'port':0x18eb});function respondWithResult(_0x493b47,_0x7c1fa4){_0x7c1fa4=_0x7c1fa4||0xc8;return function(_0x2ceb41){if(_0x2ceb41){return _0x493b47['status'](_0x7c1fa4)[_0xe919('0x9')](_0x2ceb41);}};}function saveUpdates(_0x5c4129){return function(_0x1715db){if(_0x1715db){return _0x1715db[_0xe919('0xa')](_0x5c4129)[_0xe919('0xb')](function(_0x58a7a7){return _0x58a7a7;});}return null;};}function handleEntityNotFound(_0x83759d){return function(_0x34e59e){if(!_0x34e59e){_0x83759d[_0xe919('0xc')](0x194);}return _0x34e59e;};}function handleError(_0x53ab97,_0x12098d){_0x12098d=_0x12098d||0x1f4;return function(_0x50c6ff){logger['error'](_0x50c6ff['stack']);if(_0x50c6ff[_0xe919('0xd')]){delete _0x50c6ff[_0xe919('0xd')];}_0x53ab97[_0xe919('0xe')](_0x12098d)['send'](_0x50c6ff);};}exports['update']=function(_0x203b79,_0x26fc06){if(_0x203b79['user'][_0xe919('0xf')]!==_0xe919('0x10'))throw new Error(_0xe919('0x11'));if(isNaN(Number(_0x203b79[_0xe919('0x12')]['id'])))throw new Error(_0xe919('0x13'));return db[_0xe919('0x14')][_0xe919('0x15')]({'where':{'id':_0x203b79['params']['id']}})[_0xe919('0xb')](handleEntityNotFound(_0x26fc06,null))['then'](saveUpdates(_0x203b79['body'],null))[_0xe919('0xb')](respondWithResult(_0x26fc06,null))[_0xe919('0x16')](handleError(_0x26fc06,null));};