From d440a631c8bcb2a80f3e8fc2501246448a4a3569 Mon Sep 17 00:00:00 2001 From: carlosjr Date: Mon, 24 May 2021 17:41:22 +0200 Subject: [PATCH 1/3] getUserConfig now gets default company and warehouse with dynamic code --- back/methods/user-config/getUserConfig.js | 14 +++++++++++--- back/models/warehouse.json | 3 +++ db/changes/10320-monitors/01-warehouse.sql | 4 ++++ db/dump/fixtures.sql | 12 ++++++------ 4 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 db/changes/10320-monitors/01-warehouse.sql diff --git a/back/methods/user-config/getUserConfig.js b/back/methods/user-config/getUserConfig.js index 192d973c2..550f03e44 100644 --- a/back/methods/user-config/getUserConfig.js +++ b/back/methods/user-config/getUserConfig.js @@ -13,14 +13,22 @@ module.exports = function(Self) { }); 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} }); + 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: 1, - companyFk: 442, + warehouseFk: warehouse.id, + companyFk: company.id, userFk: ctx.req.accessToken.userId }; diff --git a/back/models/warehouse.json b/back/models/warehouse.json index fc6baacbc..1d8ca44e3 100644 --- a/back/models/warehouse.json +++ b/back/models/warehouse.json @@ -16,6 +16,9 @@ "name": { "type": "String" }, + "code": { + "type": "String" + }, "isInventory": { "type": "Number" }, diff --git a/db/changes/10320-monitors/01-warehouse.sql b/db/changes/10320-monitors/01-warehouse.sql new file mode 100644 index 000000000..45e1c0c56 --- /dev/null +++ b/db/changes/10320-monitors/01-warehouse.sql @@ -0,0 +1,4 @@ +ALTER TABLE `vn`.`warehouse` + ADD `code` VARCHAR(3) NULL AFTER name; + +UPDATE `vn`.`warehouse` SET `code` = 'ALG' WHERE `id` = 60; \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index f34386676..3fda27212 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -125,13 +125,13 @@ INSERT INTO `vn`.`warehouseAlias`(`id`, `name`) (1, 'Main Warehouse'), (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 - (1, 'Warehouse One', 1, 1, 1, 1, 1, 1, 1, 2, 1), - (2, 'Warehouse Two', 1, 1, 1, 1, 0, 0, 1, 2, 13), - (3, 'Warehouse Three', 1, 1, 1, 1, 0, 0, 0, 2, 1), - (4, 'Warehouse Four', 1, 1, 1, 1, 0, 0, 0, 2, 1), - (5, 'Warehouse Five', 1, 1, 1, 1, 0, 0, 0, 2, 1); + (1, 'Warehouse One', 'ALG', 1, 1, 1, 1, 1, 1, 1, 2, 1), + (2, 'Warehouse Two', NULL, 1, 1, 1, 1, 0, 0, 1, 2, 13), + (3, 'Warehouse Three', NULL, 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', NULL, 1, 1, 1, 1, 0, 0, 0, 2, 1); INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `isPreviousPreparedByPacking`, `code`, `pickingPlacement`, `path`) VALUES From 18f22fa350febb42e3a94f209def7fa2fb5715dc Mon Sep 17 00:00:00 2001 From: carlosjr Date: Tue, 25 May 2021 09:17:51 +0200 Subject: [PATCH 2/3] minor refactor --- back/methods/user-config/getUserConfig.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/user-config/getUserConfig.js b/back/methods/user-config/getUserConfig.js index 550f03e44..663ef71b4 100644 --- a/back/methods/user-config/getUserConfig.js +++ b/back/methods/user-config/getUserConfig.js @@ -32,7 +32,7 @@ module.exports = function(Self) { userFk: ctx.req.accessToken.userId }; - userConfig = await Self.app.models.UserConfig.create(newConfig); + userConfig = await models.UserConfig.create(newConfig); } return userConfig; }; From ec86e908e17c204a56705dc0dcf4d8354e134b77 Mon Sep 17 00:00:00 2001 From: carlosjr Date: Tue, 25 May 2021 09:25:22 +0200 Subject: [PATCH 3/3] get user config test updated --- back/methods/user-config/specs/getUserConfig.spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/back/methods/user-config/specs/getUserConfig.spec.js b/back/methods/user-config/specs/getUserConfig.spec.js index da3fc958f..c86f3e0f2 100644 --- a/back/methods/user-config/specs/getUserConfig.spec.js +++ b/back/methods/user-config/specs/getUserConfig.spec.js @@ -2,9 +2,9 @@ const app = require('vn-loopback/server/server'); describe('userConfig getUserConfig()', () => { it(`should return the configuration data of a given user`, async() => { - await app.models.UserConfig.getUserConfig({req: {accessToken: {userId: 9}}}) - .then(response => { - expect(response.warehouseFk).toEqual(1); - }); + const result = await app.models.UserConfig.getUserConfig({req: {accessToken: {userId: 9}}}); + + expect(result.warehouseFk).toEqual(1); + expect(result.companyFk).toEqual(442); }); });