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 => {
|
2021-05-24 15:41:22 +00:00
|
|
|
const models = Self.app.models;
|
|
|
|
|
|
|
|
let userConfig = await 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
|
|
|
|
2021-05-24 15:41:22 +00:00
|
|
|
const companyFilter = {where: {code: 'VNL'}};
|
|
|
|
const company = await models.Company.findOne(companyFilter);
|
|
|
|
|
|
|
|
const warehouseFilter = {where: {code: 'ALG'}};
|
|
|
|
const warehouse = await models.Warehouse.findOne(warehouseFilter);
|
|
|
|
|
2019-02-06 11:14:54 +00:00
|
|
|
if (!userConfig) {
|
|
|
|
let newConfig = {
|
2021-05-24 15:41:22 +00:00
|
|
|
warehouseFk: warehouse.id,
|
|
|
|
companyFk: company.id,
|
2019-02-06 11:14:54 +00:00
|
|
|
userFk: ctx.req.accessToken.userId
|
|
|
|
};
|
|
|
|
|
2021-05-25 07:17:51 +00:00
|
|
|
userConfig = await models.UserConfig.create(newConfig);
|
2019-02-06 11:14:54 +00:00
|
|
|
}
|
|
|
|
return userConfig;
|
2018-10-08 06:14:25 +00:00
|
|
|
};
|
2018-10-05 11:01:46 +00:00
|
|
|
};
|