This commit is contained in:
al8763be 2024-03-28 12:06:59 +01:00
parent ab313551c9
commit 7c46797634

View file

@ -20,7 +20,23 @@ interface API {
registerUser(user: NewUser): Promise<APIResponse<User>>;
/** Remove a user */
removeUser(username: string, token: string): Promise<APIResponse<User>>;
/** Login */
/**
* Check if user is project manager.
* @param {string} username The username of the user.
* @param {string} projectName The name of the project.
* @param {string} token The authentication token.
* @returns {Promise<APIResponse<boolean>>} A promise containing the API response indicating if the user is a project manager.
*/
checkIfProjectManager(
projectName: string,
token: string,
): Promise<APIResponse<boolean>>;
/** Logs in a user with the provided credentials.
* @param {NewUser} NewUser The user object containing username and password.
* @returns {Promise<APIResponse<string>>} A promise resolving to an API response with a token.
*/
login(NewUser: NewUser): Promise<APIResponse<string>>;
/** Renew the token */
renewToken(token: string): Promise<APIResponse<string>>;
@ -101,6 +117,36 @@ export const api: API = {
}
},
async checkIfProjectManager(
projectName: string,
token: string,
): Promise<APIResponse<boolean>> {
try {
const response = await fetch(
`/api/checkIfProjectManager?projectName=${projectName}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token,
},
},
);
if (!response.ok) {
return {
success: false,
message: "Failed to check if project manager",
};
} else {
const data = (await response.json()) as boolean;
return { success: true, data };
}
} catch (e) {
return { success: false, message: "Failed to check if project manager" };
}
},
async createProject(
project: NewProject,
token: string,