2024-04-22 16:03:17 +00:00
|
|
|
DELIMITER $$
|
2024-07-22 09:52:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`worker_checkMultipleDevice`(
|
2024-04-22 16:03:17 +00:00
|
|
|
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;
|
2024-04-22 16:03:17 +00:00
|
|
|
|
|
|
|
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-22 16:03:17 +00:00
|
|
|
|
2024-04-24 12:29:57 +00:00
|
|
|
IF NOT vIsFreelance AND vHasPda > vMaxDevicesPerUser THEN
|
2024-04-22 16:03:17 +00:00
|
|
|
CALL util.throw('You can only have one PDA');
|
|
|
|
END IF;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|