PromoteToPm handler

This commit is contained in:
Imbus 2024-04-03 15:53:15 +02:00
parent 9cca8edd9d
commit 61a2d1ce0c
4 changed files with 97 additions and 588 deletions

View file

@ -209,6 +209,19 @@ interface API {
* @param {string} token The authentication token
*/
signReport(reportId: number, token: string): Promise<APIResponse<string>>;
/**
* Promotes a user to project manager within a project.
*
* @param {string} userName The username of the user to promote
* @param {string} projectName The name of the project to promote the user in
* @returns {Promise<APIResponse<string>} A promise resolving to an API response.
*/
promoteToPm(
userName: string,
projectName: string,
token: string,
): Promise<APIResponse<string>>;
}
/** An instance of the API */
@ -783,4 +796,35 @@ export const api: API = {
return { success: false, message: "Failed to sign report" };
}
},
async promoteToPm(
userName: string,
projectName: string,
token: string,
): Promise<APIResponse<string>> {
try {
const response = await fetch(
`/api/promoteToPm/${projectName}?userName=${userName}`,
{
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token,
},
},
);
if (!response.ok) {
return {
success: false,
message: "Failed to promote user to project manager",
};
}
} catch (e) {
return {
success: false,
message: "Failed to promote user to project manager",
};
}
return { success: true, message: "User promoted to project manager" };
},
};