userConfig fix

This commit is contained in:
Joan Sanchez 2018-10-08 08:14:25 +02:00
parent ec3a448396
commit 300c7a3cfe
2 changed files with 13 additions and 13 deletions

View File

@ -1,5 +1,5 @@
import ngModule from '../../module'; import ngModule from '../../module';
import './style.scss' import './style.scss';
class Controller { class Controller {
constructor($scope, $http, $state, vnApp, $translate) { constructor($scope, $http, $state, vnApp, $translate) {
@ -8,7 +8,7 @@ class Controller {
this.$state = $state; this.$state = $state;
this.vnApp = vnApp; this.vnApp = vnApp;
this.$translate = $translate; this.$translate = $translate;
this.getUserConfig() this.getUserConfig();
} }
set localBank(value) { set localBank(value) {
@ -43,7 +43,7 @@ class Controller {
this.setUserConfig('warehouseFk'); this.setUserConfig('warehouseFk');
} }
get warehouseFk () { get warehouseFk() {
return this.warehouse; return this.warehouse;
} }
@ -52,7 +52,7 @@ class Controller {
this.setUserConfig('companyFk'); this.setUserConfig('companyFk');
} }
get companyFk () { get companyFk() {
return this.company; return this.company;
} }
@ -63,11 +63,11 @@ class Controller {
getUserConfig() { getUserConfig() {
this.$http.get('/api/UserConfigs/getUserConfig') this.$http.get('/api/UserConfigs/getUserConfig')
.then(res => { .then(res => {
if (res.data.response.warehouseFk) if (res.data && res.data.warehouseFk)
this.warehouse = res.data.response.warehouseFk; this.warehouse = res.data.warehouseFk;
if (res.data.response.companyFk) if (res.data && res.data.companyFk)
this.company = res.data.response.companyFk; this.company = res.data.companyFk;
}); });
} }

View File

@ -3,8 +3,8 @@ module.exports = function(Self) {
description: 'returns the information from UserConfig model for the active user', description: 'returns the information from UserConfig model for the active user',
accepts: [], accepts: [],
returns: { returns: {
arg: 'response', type: 'object',
type: 'object' root: true
}, },
http: { http: {
path: `/getUserConfig`, path: `/getUserConfig`,
@ -12,10 +12,10 @@ module.exports = function(Self) {
} }
}); });
Self.getUserConfig = async(ctx) => { Self.getUserConfig = async ctx => {
let token = ctx.req.accessToken; let token = ctx.req.accessToken;
let currentUserId = token && token.userId; let currentUserId = token && token.userId;
return await Self.app.models.UserConfig.findOne({userFk: currentUserId}); return await Self.findOne({userFk: currentUserId});
} };
}; };