2018-10-05 11:01:46 +00:00
|
|
|
module.exports = function(Self) {
|
|
|
|
Self.remoteMethodCtx('getUserConfig', {
|
|
|
|
description: 'returns the information from UserConfig model for the active user',
|
|
|
|
accepts: [],
|
|
|
|
returns: {
|
2018-10-08 06:14:25 +00:00
|
|
|
type: 'object',
|
|
|
|
root: true
|
2018-10-05 11:01:46 +00:00
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/getUserConfig`,
|
|
|
|
verb: 'get'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-10-08 06:14:25 +00:00
|
|
|
Self.getUserConfig = async ctx => {
|
2019-02-06 11:14:54 +00:00
|
|
|
let userConfig = await Self.app.models.UserConfig.findOne({
|
2019-01-24 14:50:21 +00:00
|
|
|
where: {userFk: ctx.req.accessToken.userId}
|
|
|
|
});
|
2019-02-06 11:14:54 +00:00
|
|
|
|
|
|
|
if (!userConfig) {
|
|
|
|
let newConfig = {
|
|
|
|
warehouseFk: 1,
|
|
|
|
companyFk: 442,
|
|
|
|
userFk: ctx.req.accessToken.userId
|
|
|
|
};
|
|
|
|
|
|
|
|
userConfig = await Self.app.models.UserConfig.create(newConfig);
|
|
|
|
}
|
|
|
|
return userConfig;
|
2018-10-08 06:14:25 +00:00
|
|
|
};
|
2018-10-05 11:01:46 +00:00
|
|
|
};
|