From c68c78cc5b80fb7f935e86862e52d0c5479a344f Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 24 Mar 2023 12:11:42 +0100 Subject: [PATCH] refs #5250 solucion error WorkerObserv --- db/changes/231201/00-workerNotes.sql | 6 ++- modules/worker/back/model-config.json | 3 ++ .../worker/back/models/worker-observation.js | 13 +++++++ .../back/models/worker-observation.json | 39 +++++++++++++++++++ modules/worker/front/note/index/index.html | 5 ++- 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 modules/worker/back/models/worker-observation.js create mode 100644 modules/worker/back/models/worker-observation.json diff --git a/db/changes/231201/00-workerNotes.sql b/db/changes/231201/00-workerNotes.sql index 602ea3296..0d9eaae7e 100644 --- a/db/changes/231201/00-workerNotes.sql +++ b/db/changes/231201/00-workerNotes.sql @@ -7,4 +7,8 @@ CREATE TABLE `vn`.`workerObservation` ( PRIMARY KEY (`id`), CONSTRAINT `workerFk_workerObservation_FK` FOREIGN KEY (`workerFk`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `userFk_workerObservation_FK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user`(`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Todas las observaciones referentes a un trabajador'; \ No newline at end of file +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Todas las observaciones referentes a un trabajador'; + +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('WorkerObservation', '*', '*', 'ALLOW', 'ROLE', 'hr'); diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json index 63fc65827..145934700 100644 --- a/modules/worker/back/model-config.json +++ b/modules/worker/back/model-config.json @@ -53,6 +53,9 @@ "Worker": { "dataSource": "vn" }, + "WorkerObservation": { + "dataSource": "vn" + }, "WorkerConfig": { "dataSource": "vn" }, diff --git a/modules/worker/back/models/worker-observation.js b/modules/worker/back/models/worker-observation.js new file mode 100644 index 000000000..3a4480265 --- /dev/null +++ b/modules/worker/back/models/worker-observation.js @@ -0,0 +1,13 @@ +module.exports = function(Self) { + Self.validate('text', isEnabled, {message: 'Description cannot be blank'}); + function isEnabled(err) { + if (!this.text) err(); + } + + Self.observe('before save', async function(ctx) { + ctx.instance.created = new Date(); + let token = ctx.options.accessToken; + let userId = token && token.userId; + ctx.instance.userFk = userId; + }); +}; diff --git a/modules/worker/back/models/worker-observation.json b/modules/worker/back/models/worker-observation.json new file mode 100644 index 000000000..90eb35837 --- /dev/null +++ b/modules/worker/back/models/worker-observation.json @@ -0,0 +1,39 @@ +{ + "name": "WorkerObservation", + "base": "VnModel", + "options": { + "mysql": { + "table": "workerObservation" + } + }, + "properties": { + "id": { + "id": true, + "type": "number" + }, + "workerFk": { + "type": "number" + }, + "userFk": { + "type": "number" + }, + "text": { + "type": "string" + }, + "created": { + "type": "date" + } + }, + "relations": { + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + }, + "user":{ + "type": "belongsTo", + "model": "Account", + "foreignKey": "userFk" + } + } +} diff --git a/modules/worker/front/note/index/index.html b/modules/worker/front/note/index/index.html index 4b72d60ab..9f5c27008 100644 --- a/modules/worker/front/note/index/index.html +++ b/modules/worker/front/note/index/index.html @@ -1,8 +1,9 @@ @@ -14,7 +15,7 @@ ng-repeat="note in notes" class="note vn-pa-sm border-solid border-radius vn-mb-md"> - {{::note.worker.user.nickname}} + {{::note.user.nickname}} {{::note.created | date:'dd/MM/yyyy HH:mm'}}