fix: Allow modification of role warehouse in users endpoint

This commit is contained in:
Josepablo C
2025-02-28 21:59:59 -06:00
parent 679a265951
commit 423a4be51b

View File

@@ -54,24 +54,38 @@ const patchProfileData = async(req, res) => {
}
};
/**
* Verify if the author has enough rights to change the affected user role
* @param {*} change_author_job_role
* @param {*} affected_job_role
* @returns
*/
function job_role_change_allowance( change_author_job_role , affected_job_role ){
try{
/** Only owner and managers can change the role */
if( (change_author_job_role !== "owner") && (change_author_job_role !== "manager") ){
return false;
}
/** No one can affect the role of the owner */
if( affected_job_role === "owner" ){
return false;
}
switch( affected_job_role ){
case 'manager':
case 'driver':
case 'staff':
/** You can only modify the role of a user if it is in the following list */
const modifiable_roles = [
'manager',
'driver',
'staff',
'warehouse'
];
if( modifiable_roles.includes( affected_job_role ) ){
return true;
default:
}else{
return false;
}
}catch( error ){
console.error( error );
return res.status( 500 ).send( { error } );