c89097445f5fd7a3da2d5cd3a7b9d7bf65e244b7
[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 _0x92f0=['defaults','localhost','status','update','error','stack','name','user','role','admin','Unauthorized','params','UserSetting','find','then','catch','ioredis','../../config/logger','../../config/environment','../../mysqldb','./user-setting.socket','register','redis'];(function(_0x4eb425,_0x2755b2){var _0x541919=function(_0xc397f0){while(--_0xc397f0){_0x4eb425['push'](_0x4eb425['shift']());}};_0x541919(++_0x2755b2);}(_0x92f0,0x10d));var _0x092f=function(_0x3f3bad,_0x193f06){_0x3f3bad=_0x3f3bad-0x0;var _0x4f0801=_0x92f0[_0x3f3bad];return _0x4f0801;};'use strict';var _=require('lodash');var Redis=require(_0x092f('0x0'));var logger=require(_0x092f('0x1'))('api');var config=require(_0x092f('0x2'));var db=require(_0x092f('0x3'))['db'];var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x092f('0x4'))[_0x092f('0x5')](socket);config[_0x092f('0x6')]=_[_0x092f('0x7')](config[_0x092f('0x6')],{'host':_0x092f('0x8'),'port':0x18eb});function respondWithResult(_0x5b5741,_0x434211){_0x434211=_0x434211||0xc8;return function(_0x542b99){if(_0x542b99){return _0x5b5741[_0x092f('0x9')](_0x434211)['json'](_0x542b99);}};}function saveUpdates(_0x30c479){return function(_0x513796){if(_0x513796){return _0x513796[_0x092f('0xa')](_0x30c479)['then'](function(_0x2f073a){return _0x2f073a;});}return null;};}function handleEntityNotFound(_0x66b0f5){return function(_0x32bc71){if(!_0x32bc71){_0x66b0f5['sendStatus'](0x194);}return _0x32bc71;};}function handleError(_0xa4585,_0x2569cb){_0x2569cb=_0x2569cb||0x1f4;return function(_0x2f58c5){logger[_0x092f('0xb')](_0x2f58c5[_0x092f('0xc')]);if(_0x2f58c5['name']){delete _0x2f58c5[_0x092f('0xd')];}_0xa4585[_0x092f('0x9')](_0x2569cb)['send'](_0x2f58c5);};}exports[_0x092f('0xa')]=function(_0x1b19fb,_0x33f761){if(_0x1b19fb[_0x092f('0xe')][_0x092f('0xf')]!==_0x092f('0x10'))throw new Error(_0x092f('0x11'));if(isNaN(Number(_0x1b19fb[_0x092f('0x12')]['id'])))throw new Error('Invalid\x20user\x20setting\x20id');return db[_0x092f('0x13')][_0x092f('0x14')]({'where':{'id':_0x1b19fb[_0x092f('0x12')]['id']}})[_0x092f('0x15')](handleEntityNotFound(_0x33f761,null))['then'](saveUpdates(_0x1b19fb['body'],null))[_0x092f('0x15')](respondWithResult(_0x33f761,null))[_0x092f('0x16')](handleError(_0x33f761,null));};