getUserConfig now gets default company and warehouse with dynamic code #632

Merged
joan merged 3 commits from 2923_getUserConfig_default_warehouse_and_company into dev 2021-05-25 09:15:27 +00:00
5 changed files with 29 additions and 14 deletions

View File

@ -13,18 +13,26 @@ module.exports = function(Self) {
}); });
Self.getUserConfig = async ctx => { Self.getUserConfig = async ctx => {
let userConfig = await Self.app.models.UserConfig.findOne({ const models = Self.app.models;
let userConfig = await models.UserConfig.findOne({
where: {userFk: ctx.req.accessToken.userId} 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) { if (!userConfig) {
let newConfig = { let newConfig = {
warehouseFk: 1, warehouseFk: warehouse.id,
companyFk: 442, companyFk: company.id,
userFk: ctx.req.accessToken.userId userFk: ctx.req.accessToken.userId
}; };
userConfig = await Self.app.models.UserConfig.create(newConfig); userConfig = await models.UserConfig.create(newConfig);
} }
return userConfig; return userConfig;
}; };

View File

@ -2,9 +2,9 @@ const app = require('vn-loopback/server/server');
describe('userConfig getUserConfig()', () => { describe('userConfig getUserConfig()', () => {
it(`should return the configuration data of a given user`, async() => { it(`should return the configuration data of a given user`, async() => {
await app.models.UserConfig.getUserConfig({req: {accessToken: {userId: 9}}}) const result = await app.models.UserConfig.getUserConfig({req: {accessToken: {userId: 9}}});
.then(response => {
expect(response.warehouseFk).toEqual(1); expect(result.warehouseFk).toEqual(1);
}); expect(result.companyFk).toEqual(442);
}); });
}); });

View File

@ -16,6 +16,9 @@
"name": { "name": {
"type": "String" "type": "String"
}, },
"code": {
"type": "String"
},
"isInventory": { "isInventory": {
"type": "Number" "type": "Number"
}, },

View File

@ -0,0 +1,4 @@
ALTER TABLE `vn`.`warehouse`
ADD `code` VARCHAR(3) NULL AFTER name;
UPDATE `vn`.`warehouse` SET `code` = 'ALG' WHERE `id` = 60;

View File

@ -125,13 +125,13 @@ INSERT INTO `vn`.`warehouseAlias`(`id`, `name`)
(1, 'Main Warehouse'), (1, 'Main Warehouse'),
(2, 'Silla'); (2, 'Silla');
INSERT INTO `vn`.`warehouse`(`id`, `name`, `isComparative`, `isInventory`, `hasAvailable`, `isManaged`, `hasStowaway`, `hasDms`, `hasComission`, `aliasFk`, `countryFk`) INSERT INTO `vn`.`warehouse`(`id`, `name`, `code`, `isComparative`, `isInventory`, `hasAvailable`, `isManaged`, `hasStowaway`, `hasDms`, `hasComission`, `aliasFk`, `countryFk`)
VALUES VALUES
(1, 'Warehouse One', 1, 1, 1, 1, 1, 1, 1, 2, 1), (1, 'Warehouse One', 'ALG', 1, 1, 1, 1, 1, 1, 1, 2, 1),
(2, 'Warehouse Two', 1, 1, 1, 1, 0, 0, 1, 2, 13), (2, 'Warehouse Two', NULL, 1, 1, 1, 1, 0, 0, 1, 2, 13),
(3, 'Warehouse Three', 1, 1, 1, 1, 0, 0, 0, 2, 1), (3, 'Warehouse Three', NULL, 1, 1, 1, 1, 0, 0, 0, 2, 1),
(4, 'Warehouse Four', 1, 1, 1, 1, 0, 0, 0, 2, 1), (4, 'Warehouse Four', NULL, 1, 1, 1, 1, 0, 0, 0, 2, 1),
(5, 'Warehouse Five', 1, 1, 1, 1, 0, 0, 0, 2, 1); (5, 'Warehouse Five', NULL, 1, 1, 1, 1, 0, 0, 0, 2, 1);
INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `isPreviousPreparedByPacking`, `code`, `pickingPlacement`, `path`) INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `isPreviousPreparedByPacking`, `code`, `pickingPlacement`, `path`)
VALUES VALUES