ChangeProjectName Handler + API

This commit is contained in:
al8763be 2024-04-17 21:31:47 +02:00
parent 6c4fe7bda3
commit 47d4bda99b
7 changed files with 166 additions and 2 deletions

View file

@ -271,6 +271,18 @@ interface API {
token: string,
userName?: string,
): Promise<APIResponse<Statistics>>;
/**
* Changes the name of a project
* @param {string} projectName The name of the project
* @param {string} newProjectName The new name of the project
* @param {string} token The authentication token
*/
changeProjectName(
projectName: string,
newProjectName: string,
token: string,
): Promise<APIResponse<string>>;
}
/** An instance of the API */
@ -1002,4 +1014,31 @@ export const api: API = {
return { success: false, message: "Failed to get statistics" };
}
},
async changeProjectName(
projectName: string,
newProjectName: string,
token: string,
): Promise<APIResponse<string>> {
try {
const response = await fetch(
`/api/changeProjectName/${projectName}?newProjectName=${newProjectName}`,
{
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token,
},
},
);
if (!response.ok) {
return { success: false, message: "Failed to change project name" };
} else {
return { success: true, message: "Project name changed" };
}
} catch (e) {
return { success: false, message: "Failed to change project name" };
}
},
};