Built motion from commit c1aa34a0.|2.6.28
[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 _0x9ef8=['admin','params','find','lodash','ioredis','api','../../config/environment','../../mysqldb','redis','./user-setting.socket','localhost','status','json','then','sendStatus','error','name','send','user','role'];(function(_0x356e5c,_0x23156b){var _0x459517=function(_0x425042){while(--_0x425042){_0x356e5c['push'](_0x356e5c['shift']());}};_0x459517(++_0x23156b);}(_0x9ef8,0x17f));var _0x89ef=function(_0x3d27ba,_0x2671a3){_0x3d27ba=_0x3d27ba-0x0;var _0xf01885=_0x9ef8[_0x3d27ba];return _0xf01885;};'use strict';var _=require(_0x89ef('0x0'));var Redis=require(_0x89ef('0x1'));var logger=require('../../config/logger')(_0x89ef('0x2'));var config=require(_0x89ef('0x3'));var db=require(_0x89ef('0x4'))['db'];var socket=require('socket.io-emitter')(new Redis(config[_0x89ef('0x5')]));require(_0x89ef('0x6'))['register'](socket);config['redis']=_['defaults'](config[_0x89ef('0x5')],{'host':_0x89ef('0x7'),'port':0x18eb});function respondWithResult(_0x24439e,_0x90b5bf){_0x90b5bf=_0x90b5bf||0xc8;return function(_0x46c0da){if(_0x46c0da){return _0x24439e[_0x89ef('0x8')](_0x90b5bf)[_0x89ef('0x9')](_0x46c0da);}};}function saveUpdates(_0x3d204a){return function(_0xbd0084){if(_0xbd0084){return _0xbd0084['update'](_0x3d204a)[_0x89ef('0xa')](function(_0x4687cb){return _0x4687cb;});}return null;};}function handleEntityNotFound(_0x30c8f4){return function(_0x5c5435){if(!_0x5c5435){_0x30c8f4[_0x89ef('0xb')](0x194);}return _0x5c5435;};}function handleError(_0x7f5df1,_0x1c69aa){_0x1c69aa=_0x1c69aa||0x1f4;return function(_0x4b52dc){logger[_0x89ef('0xc')](_0x4b52dc['stack']);if(_0x4b52dc[_0x89ef('0xd')]){delete _0x4b52dc['name'];}_0x7f5df1[_0x89ef('0x8')](_0x1c69aa)[_0x89ef('0xe')](_0x4b52dc);};}exports['update']=function(_0x21ac0b,_0x269192){if(_0x21ac0b[_0x89ef('0xf')][_0x89ef('0x10')]!==_0x89ef('0x11'))throw new Error('Unauthorized');if(isNaN(Number(_0x21ac0b[_0x89ef('0x12')]['id'])))throw new Error('Invalid\x20user\x20setting\x20id');return db['UserSetting'][_0x89ef('0x13')]({'where':{'id':_0x21ac0b[_0x89ef('0x12')]['id']}})['then'](handleEntityNotFound(_0x269192,null))[_0x89ef('0xa')](saveUpdates(_0x21ac0b['body'],null))[_0x89ef('0xa')](respondWithResult(_0x269192,null))['catch'](handleError(_0x269192,null));};