salix/db/routines/vn/procedures/worker_checkMultipleDevice.sql

25 lines
734 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_checkMultipleDevice`(
vSelf INT
)
BEGIN
/**
* Verify if a worker has multiple assigned devices,
* except for freelancers.
*
* @param vUserFk worker id.
*/
DECLARE vHasPda BOOLEAN;
DECLARE vIsFreelance BOOLEAN;
2024-04-24 12:29:57 +00:00
DECLARE vMaxDevicesPerUser INT;
SELECT COUNT(*) INTO vHasPda FROM deviceProductionUser WHERE userFk = vSelf;
2024-04-24 12:29:57 +00:00
SELECT IFNULL(isFreelance, FALSE) INTO vIsFreelance FROM worker WHERE id = vSelf;
SELECT IFNULL(maxDevicesPerUser, FALSE) INTO vMaxDevicesPerUser FROM deviceProductionConfig LIMIT 1;
2024-04-24 12:29:57 +00:00
IF NOT vIsFreelance AND vHasPda > vMaxDevicesPerUser THEN
CALL util.throw('You can only have one PDA');
END IF;
END$$
DELIMITER ;