From f35b2a4905baf3d0bd34a64cfc3c2c265d33adf3 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 26 Dec 2023 13:44:52 +0100 Subject: [PATCH] refs #5919 back chooseLocker --- db/changes/{234201 => 240201}/00-locker.sql | 14 ++++++-- .../back/methods/worker/chooseLocker.js | 32 ------------------- modules/worker/back/model-config.json | 2 +- modules/worker/back/models/locker.js | 7 ---- modules/worker/back/models/locker.json | 4 +-- modules/worker/back/models/worker.json | 5 +++ modules/worker/front/basic-data/index.html | 2 +- modules/worker/front/basic-data/index.js | 10 ++++-- modules/worker/front/summary/index.html | 2 +- modules/worker/front/summary/index.js | 4 +++ 10 files changed, 34 insertions(+), 48 deletions(-) rename db/changes/{234201 => 240201}/00-locker.sql (83%) delete mode 100644 modules/worker/back/methods/worker/chooseLocker.js delete mode 100644 modules/worker/back/models/locker.js diff --git a/db/changes/234201/00-locker.sql b/db/changes/240201/00-locker.sql similarity index 83% rename from db/changes/234201/00-locker.sql rename to db/changes/240201/00-locker.sql index c925cb1af..20ab6ed16 100644 --- a/db/changes/234201/00-locker.sql +++ b/db/changes/240201/00-locker.sql @@ -1,3 +1,6 @@ +ALTER TABLE vn.worker MODIFY COLUMN locker varchar(10) DEFAULT NULL NULL; + + CREATE TABLE `vn`.`locker` ( `code` varchar(10) DEFAULT NULL, `gender` varchar(255) DEFAULT NULL, @@ -8,6 +11,14 @@ CREATE TABLE `vn`.`locker` ( CONSTRAINT `locker_ibfk_1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +ALTER TABLE `vn`.`worker` +ADD CONSTRAINT `worker_locker_fk` +FOREIGN KEY (`locker`) +REFERENCES `vn`.`locker` (`code`) +ON UPDATE CASCADE +ON DELETE SET NULL; + + -- Insertar taquillas disponibles para mujeres (1A - 73A / 1B - 73B) INSERT INTO `vn`.`locker` (code, gender, workerFk) VALUES ('1A', 'M', NULL), ('2A', 'M', NULL), ('3A', 'M', NULL), ('4A', 'M', NULL), ('5A', 'M', NULL), ('6A', 'M', NULL), ('7A', 'M', NULL), @@ -19,5 +30,4 @@ INSERT INTO `vn`.`locker` (code, gender, workerFk) VALUES ('200B', 'F', NULL), ('201B', 'F', NULL), ('202B', 'F', NULL), ('203B', 'F', NULL), ('204B', 'F', NULL), ('205B', 'F', NULL), ('206B', 'F', NULL); --- Eliminar locker -ALTER TABLE `vn`.`worker` DROP COLUMN `locker`; + diff --git a/modules/worker/back/methods/worker/chooseLocker.js b/modules/worker/back/methods/worker/chooseLocker.js deleted file mode 100644 index dc7775d08..000000000 --- a/modules/worker/back/methods/worker/chooseLocker.js +++ /dev/null @@ -1,32 +0,0 @@ - -module.exports = Self => { - Self.remoteMethod('chooseLocker', { - description: 'Returns an unoccupied locker for the employee', - accessType: 'WRITE', - accepts: [{ - arg: 'filter', - type: 'Object', - description: 'Filter defining where and paginated data', - required: true - }], - returns: { - type: ['object'], - root: true - }, - http: { - path: `/chooseLocker`, - verb: 'GET' - } - }); - - Self.chooseLocker = async filter => { - const query = - `SELECT l.code - FROM worker w - JOIN locker l ON w.sex = l.gender - WHERE w.id = ? AND l.workerFk IS NULL; - `[this.worker.id]; - - return Self.chooseLocker(query, filter); - }; -}; diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json index fe2b24c06..8be67a10d 100644 --- a/modules/worker/back/model-config.json +++ b/modules/worker/back/model-config.json @@ -116,7 +116,7 @@ "Operator": { "dataSource": "vn" }, - "locker": { + "Locker": { "dataSource": "vn" } } diff --git a/modules/worker/back/models/locker.js b/modules/worker/back/models/locker.js deleted file mode 100644 index 25b33f517..000000000 --- a/modules/worker/back/models/locker.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = Self => { - require('../methods/worker/chooseLocker')(Self); - - Self.validatesUniquenessOf('locker', { - message: 'This locker has already been assigned' - }); -}; diff --git a/modules/worker/back/models/locker.json b/modules/worker/back/models/locker.json index 0e72784b3..9601ca129 100644 --- a/modules/worker/back/models/locker.json +++ b/modules/worker/back/models/locker.json @@ -1,7 +1,7 @@ { - "name": "locker", + "name": "Locker", "description": "Employee's locker", - "base": "Loggable", + "base": "VnModel", "options": { "mysql": { "table": "locker" diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index 1a777fffe..b045f1465 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -88,6 +88,11 @@ "type": "hasMany", "model": "WorkerTeamCollegues", "foreignKey": "workerFk" + }, + "locker": { + "type": "belongsTo", + "model": "Locker", + "foreignKey": "code" } } } diff --git a/modules/worker/front/basic-data/index.html b/modules/worker/front/basic-data/index.html index b15c6c669..a3f122a49 100644 --- a/modules/worker/front/basic-data/index.html +++ b/modules/worker/front/basic-data/index.html @@ -78,7 +78,7 @@ + ng-model="$ctrl.locker.code"> diff --git a/modules/worker/front/basic-data/index.js b/modules/worker/front/basic-data/index.js index 82ed2e6bf..bf162f49b 100644 --- a/modules/worker/front/basic-data/index.js +++ b/modules/worker/front/basic-data/index.js @@ -13,9 +13,15 @@ class Controller extends Section { return this.$.watcher.submit() .then(() => this.card.reload()); } + async chooseLocker() { + const locker = + `SELECT l.code + FROM worker w + JOIN locker l ON w.sex = l.gender + WHERE w.id = ? AND l.workerFk IS NULL; + `[this.code]; - chooseLocker() { - // + return locker; } } diff --git a/modules/worker/front/summary/index.html b/modules/worker/front/summary/index.html index ff464aa79..ba96d25a6 100644 --- a/modules/worker/front/summary/index.html +++ b/modules/worker/front/summary/index.html @@ -59,7 +59,7 @@ > + value="{{worker.locker.code}}"> diff --git a/modules/worker/front/summary/index.js b/modules/worker/front/summary/index.js index 0e7f46c7c..a7387a125 100644 --- a/modules/worker/front/summary/index.js +++ b/modules/worker/front/summary/index.js @@ -52,6 +52,10 @@ class Controller extends Summary { } } }, + { + relation: 'locker', + scope: {fields: ['code']} + } ] };