refactor(thermograph): empty fields handler added and correct usage of thermograph.code

This commit is contained in:
Carlos Jimenez Ruiz 2021-10-19 10:58:58 +02:00
parent 909fb368ce
commit e3942c0bb9
2 changed files with 13 additions and 3 deletions

View File

@ -2232,8 +2232,8 @@ INSERT IGNORE INTO `vn`.`greugeConfig` (`id`, `freightPickUpPrice`) VALUES ('1',
INSERT INTO `vn`.`temperature`(`code`, `name`, `description`) INSERT INTO `vn`.`temperature`(`code`, `name`, `description`)
VALUES VALUES
('WARM', 'Warm', 'Warm'), ('warm', 'Warm', 'Warm'),
('COOL', 'Cool', 'Cool'); ('cool', 'Cool', 'Cool');
INSERT INTO `vn`.`thermograph`(`id`, `model`) INSERT INTO `vn`.`thermograph`(`id`, `model`)
VALUES VALUES

View File

@ -1,5 +1,6 @@
import ngModule from '../../module'; import ngModule from '../../module';
import Section from 'salix/components/section'; import Section from 'salix/components/section';
import UserError from 'core/lib/user-error';
class Controller extends Section { class Controller extends Section {
constructor($element, $) { constructor($element, $) {
@ -56,7 +57,7 @@ class Controller extends Section {
} }
onAddThermographClick(event) { onAddThermographClick(event) {
const defaultTemperature = 'COOL'; const defaultTemperature = 'cool';
const defaultModel = 'DISPOSABLE'; const defaultModel = 'DISPOSABLE';
event.preventDefault(); event.preventDefault();
@ -72,6 +73,15 @@ class Controller extends Section {
} }
onNewThermographAccept() { 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) return this.$http.post(`Thermographs/createThermograph`, this.newThermograph)
.then(res => this.dms.thermographId = res.data.id); .then(res => this.dms.thermographId = res.data.id);
} }