salix/back/methods/user-config/getUserConfig.js

32 lines
854 B
JavaScript

module.exports = function(Self) {
Self.remoteMethodCtx('getUserConfig', {
description: 'returns the information from UserConfig model for the active user',
accepts: [],
returns: {
type: 'object',
root: true
},
http: {
path: `/getUserConfig`,
verb: 'get'
}
});
Self.getUserConfig = async ctx => {
let userConfig = await Self.app.models.UserConfig.findOne({
where: {userFk: ctx.req.accessToken.userId}
});
if (!userConfig) {
let newConfig = {
warehouseFk: 1,
companyFk: 442,
userFk: ctx.req.accessToken.userId
};
userConfig = await Self.app.models.UserConfig.create(newConfig);
}
return userConfig;
};
};