From e3942c0bb9280c76ae7e5e2906610e7e92cedaa3 Mon Sep 17 00:00:00 2001 From: carlosjr Date: Tue, 19 Oct 2021 10:58:58 +0200 Subject: [PATCH] refactor(thermograph): empty fields handler added and correct usage of thermograph.code --- db/dump/fixtures.sql | 4 ++-- modules/travel/front/thermograph/create/index.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 66bd821cf..008434dd6 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2232,8 +2232,8 @@ INSERT IGNORE INTO `vn`.`greugeConfig` (`id`, `freightPickUpPrice`) VALUES ('1', INSERT INTO `vn`.`temperature`(`code`, `name`, `description`) VALUES - ('WARM', 'Warm', 'Warm'), - ('COOL', 'Cool', 'Cool'); + ('warm', 'Warm', 'Warm'), + ('cool', 'Cool', 'Cool'); INSERT INTO `vn`.`thermograph`(`id`, `model`) VALUES diff --git a/modules/travel/front/thermograph/create/index.js b/modules/travel/front/thermograph/create/index.js index b6d78fc50..fa2c1261a 100644 --- a/modules/travel/front/thermograph/create/index.js +++ b/modules/travel/front/thermograph/create/index.js @@ -1,5 +1,6 @@ import ngModule from '../../module'; import Section from 'salix/components/section'; +import UserError from 'core/lib/user-error'; class Controller extends Section { constructor($element, $) { @@ -56,7 +57,7 @@ class Controller extends Section { } onAddThermographClick(event) { - const defaultTemperature = 'COOL'; + const defaultTemperature = 'cool'; const defaultModel = 'DISPOSABLE'; event.preventDefault(); @@ -72,6 +73,15 @@ class Controller extends Section { } onNewThermographAccept() { + const hasMissingField = + !this.newThermograph.thermographId || + !this.newThermograph.warehouseId || + !this.newThermograph.temperatureFk || + !this.newThermograph.model; + + if (hasMissingField) + throw new UserError(`Some fields are invalid`); + return this.$http.post(`Thermographs/createThermograph`, this.newThermograph) .then(res => this.dms.thermographId = res.data.id); }