ChangeProjectName Handler + API
This commit is contained in:
parent
6c4fe7bda3
commit
47d4bda99b
7 changed files with 166 additions and 2 deletions
|
|
@ -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" };
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue