40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
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 => {
|
|
const models = Self.app.models;
|
|
|
|
let userConfig = await models.UserConfig.findOne({
|
|
where: {userFk: ctx.req.accessToken.userId}
|
|
});
|
|
|
|
const companyFilter = {where: {code: 'VNL'}};
|
|
const company = await models.Company.findOne(companyFilter);
|
|
|
|
const warehouseFilter = {where: {code: 'ALG'}};
|
|
const warehouse = await models.Warehouse.findOne(warehouseFilter);
|
|
|
|
if (!userConfig) {
|
|
let newConfig = {
|
|
warehouseFk: warehouse.id,
|
|
companyFk: company.id,
|
|
userFk: ctx.req.accessToken.userId
|
|
};
|
|
|
|
userConfig = await Self.app.models.UserConfig.create(newConfig);
|
|
}
|
|
return userConfig;
|
|
};
|
|
};
|