diff --git a/db/changes/10260-holidays/00-zoneLog.sql b/db/changes/10260-holidays/00-zoneLog.sql new file mode 100644 index 000000000..13d81bc92 --- /dev/null +++ b/db/changes/10260-holidays/00-zoneLog.sql @@ -0,0 +1,18 @@ +CREATE TABLE `vn`.`zoneLog` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `originFk` int(10) NOT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL, + `creationDate` timestamp NULL DEFAULT current_timestamp(), + `description` text CHARACTER SET utf8 DEFAULT NULL, + `changedModel` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + `oldInstance` text COLLATE utf8_unicode_ci DEFAULT NULL, + `newInstance` text COLLATE utf8_unicode_ci DEFAULT NULL, + `changedModelId` int(11) DEFAULT NULL, + `changedModelValue` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `originFk` (`originFk`), + KEY `userFk` (`userFk`), + CONSTRAINT `zoneLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn`.`zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `zoneLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; \ No newline at end of file diff --git a/loopback/common/models/vn-model.js b/loopback/common/models/vn-model.js index f56183df2..cc3eede8e 100644 --- a/loopback/common/models/vn-model.js +++ b/loopback/common/models/vn-model.js @@ -145,9 +145,15 @@ module.exports = function(Self) { rewriteDbError(replaceErrFunc) { function replaceErr(err, replaceErrFunc) { if (Array.isArray(err)) { + const errors = err.filter(error => { + return error != undefined && error != null; + }); let errs = []; - for (let e of err) - errs.push(replaceErrFunc(e)); + for (let e of errors) { + if (!(e instanceof UserError)) + errs.push(replaceErrFunc(e)); + else errs.push(e); + } return errs; } return replaceErrFunc(err); diff --git a/modules/zone/back/model-config.json b/modules/zone/back/model-config.json index f353be088..05da8b2c3 100644 --- a/modules/zone/back/model-config.json +++ b/modules/zone/back/model-config.json @@ -31,5 +31,8 @@ }, "ZoneEstimatedDelivery": { "dataSource": "vn" + }, + "ZoneLog": { + "dataSource": "vn" } } diff --git a/modules/zone/back/models/zone-event.json b/modules/zone/back/models/zone-event.json index 9ac1007b5..54c9c4a7d 100644 --- a/modules/zone/back/models/zone-event.json +++ b/modules/zone/back/models/zone-event.json @@ -1,6 +1,10 @@ { "name": "ZoneEvent", - "base": "VnModel", + "base": "Loggable", + "log": { + "model":"ZoneLog", + "relation": "zone" + }, "options": { "mysql": { "table": "zoneEvent" diff --git a/modules/zone/back/models/zone-included.json b/modules/zone/back/models/zone-included.json index 9f9508824..e462b7a65 100644 --- a/modules/zone/back/models/zone-included.json +++ b/modules/zone/back/models/zone-included.json @@ -1,6 +1,11 @@ { "name": "ZoneIncluded", - "base": "VnModel", + "base": "Loggable", + "log": { + "model": "ZoneLog", + "relation": "zone", + "showField": "isIncluded" + }, "options": { "mysql": { "table": "zoneIncluded" diff --git a/modules/zone/back/models/zone-log.json b/modules/zone/back/models/zone-log.json new file mode 100644 index 000000000..ddca9261b --- /dev/null +++ b/modules/zone/back/models/zone-log.json @@ -0,0 +1,58 @@ +{ + "name": "ZoneLog", + "base": "VnModel", + "options": { + "mysql": { + "table": "zoneLog" + } + }, + "properties": { + "id": { + "id": true, + "type": "Number", + "forceId": false + }, + "originFk": { + "type": "Number", + "required": true + }, + "userFk": { + "type": "Number" + }, + "action": { + "type": "String", + "required": true + }, + "changedModel": { + "type": "String" + }, + "oldInstance": { + "type": "Object" + }, + "newInstance": { + "type": "Object" + }, + "creationDate": { + "type": "Date" + }, + "changedModelId": { + "type": "String" + }, + "changedModelValue": { + "type": "String" + }, + "description": { + "type": "String" + } + }, + "relations": { + "user": { + "type": "belongsTo", + "model": "Account", + "foreignKey": "userFk" + } + }, + "scope": { + "order": ["creationDate DESC", "id DESC"] + } +} diff --git a/modules/zone/back/models/zone-warehouse.json b/modules/zone/back/models/zone-warehouse.json index 14c4e84a4..0f0e43f4a 100644 --- a/modules/zone/back/models/zone-warehouse.json +++ b/modules/zone/back/models/zone-warehouse.json @@ -1,6 +1,10 @@ { "name": "ZoneWarehouse", - "base": "VnModel", + "base": "Loggable", + "log": { + "model":"ZoneLog", + "relation": "zone" + }, "options": { "mysql": { "table": "zoneWarehouse" diff --git a/modules/zone/back/models/zone.json b/modules/zone/back/models/zone.json index e94146946..bafef0a95 100644 --- a/modules/zone/back/models/zone.json +++ b/modules/zone/back/models/zone.json @@ -1,6 +1,10 @@ { "name": "Zone", - "base": "VnModel", + "base": "Loggable", + "log": { + "model":"ZoneLog", + "showField": "name" + }, "options": { "mysql": { "table": "zone" @@ -39,11 +43,6 @@ } }, "relations": { - "geolocations": { - "type": "hasMany", - "model": "ZoneGeo", - "foreignKey": "zoneFk" - }, "agencyMode": { "type": "belongsTo", "model": "AgencyMode", diff --git a/modules/zone/front/index.js b/modules/zone/front/index.js index 26c491709..dc20eea47 100644 --- a/modules/zone/front/index.js +++ b/modules/zone/front/index.js @@ -16,3 +16,4 @@ import './calendar'; import './location'; import './calendar'; import './upcoming-deliveries'; +import './log'; diff --git a/modules/zone/front/log/index.html b/modules/zone/front/log/index.html new file mode 100644 index 000000000..539afda82 --- /dev/null +++ b/modules/zone/front/log/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/modules/zone/front/log/index.js b/modules/zone/front/log/index.js new file mode 100644 index 000000000..8c3be2423 --- /dev/null +++ b/modules/zone/front/log/index.js @@ -0,0 +1,7 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +ngModule.vnComponent('vnZoneLog', { + template: require('./index.html'), + controller: Section, +}); diff --git a/modules/zone/front/routes.json b/modules/zone/front/routes.json index 6c799dcc8..0134c3b78 100644 --- a/modules/zone/front/routes.json +++ b/modules/zone/front/routes.json @@ -14,6 +14,7 @@ {"state": "zone.card.basicData", "icon": "settings"}, {"state": "zone.card.location", "icon": "my_location"}, {"state": "zone.card.warehouses", "icon": "home"}, + {"state": "zone.card.log", "icon": "history"}, {"state": "zone.card.events", "icon": "today"} ] }, @@ -84,6 +85,11 @@ "params": { "zone": "$ctrl.zone" } + }, { + "url" : "/log", + "state": "zone.card.log", + "component": "vn-zone-log", + "description": "Log" } ] } \ No newline at end of file