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

25 lines
732 B
MySQL
Raw Permalink Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`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 ;