#5919 createLocker #2446

Merged
jorgep merged 42 commits from 5919-createLocker into dev 2024-05-13 13:10:40 +00:00
10 changed files with 34 additions and 48 deletions
Showing only changes of commit f35b2a4905 - Show all commits

View File

@ -1,3 +1,6 @@
ALTER TABLE vn.worker MODIFY COLUMN locker varchar(10) DEFAULT NULL NULL;
CREATE TABLE `vn`.`locker` ( CREATE TABLE `vn`.`locker` (
`code` varchar(10) DEFAULT NULL, `code` varchar(10) DEFAULT NULL,
`gender` varchar(255) 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`) CONSTRAINT `locker_ibfk_1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; ) 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) -- Insertar taquillas disponibles para mujeres (1A - 73A / 1B - 73B)
INSERT INTO `vn`.`locker` (code, gender, workerFk) VALUES 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), ('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); ('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": { "Operator": {
"dataSource": "vn" "dataSource": "vn"
}, },
"locker": { "Locker": {
"dataSource": "vn" "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", "description": "Employee's locker",
"base": "Loggable", "base": "VnModel",
"options": { "options": {
"mysql": { "mysql": {
"table": "locker" "table": "locker"

View File

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

View File

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

View File

@ -13,9 +13,15 @@ class Controller extends Section {
return this.$.watcher.submit() return this.$.watcher.submit()
.then(() => this.card.reload()); .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-link-phone>
</vn-label-value> </vn-label-value>
<vn-label-value label="Locker" <vn-label-value label="Locker"
value="{{::locker.code}}"> value="{{worker.locker.code}}">
</vn-label-value> </vn-label-value>
</vn-one> </vn-one>
<vn-one> <vn-one>

View File

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