refs #5919 back chooseLocker
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Carlos Satorres 2023-12-26 13:44:52 +01:00
parent aa33c28468
commit f35b2a4905
10 changed files with 34 additions and 48 deletions

View File

@ -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`;

View File

@ -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);
};
};

View File

@ -116,7 +116,7 @@
"Operator": {
"dataSource": "vn"
},
"locker": {
"Locker": {
"dataSource": "vn"
}
}

View File

@ -1,7 +0,0 @@
module.exports = Self => {
require('../methods/worker/chooseLocker')(Self);
Self.validatesUniquenessOf('locker', {
message: 'This locker has already been assigned'
});
};

View File

@ -1,7 +1,7 @@
{
"name": "locker",
"name": "Locker",
"description": "Employee's locker",
"base": "Loggable",
"base": "VnModel",
"options": {
"mysql": {
"table": "locker"

View File

@ -88,6 +88,11 @@
"type": "hasMany",
"model": "WorkerTeamCollegues",
"foreignKey": "workerFk"
},
"locker": {
"type": "belongsTo",
"model": "Locker",
"foreignKey": "code"
}
}
}

View File

@ -78,7 +78,7 @@
<vn-autocomplete
label="Locker"
url="Lockers"
data="$ctrl.locker.code">
ng-model="$ctrl.locker.code">
</vn-autocomplete>
</vn-horizontal>
</vn-vertical>

View File

@ -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;
}
}

View File

@ -59,7 +59,7 @@
></vn-link-phone>
</vn-label-value>
<vn-label-value label="Locker"
value="{{::locker.code}}">
value="{{worker.locker.code}}">
</vn-label-value>
</vn-one>
<vn-one>

View File

@ -52,6 +52,10 @@ class Controller extends Summary {
}
}
},
{
relation: 'locker',
scope: {fields: ['code']}
}
]
};