Merge branch 'BumBranch' into gruppDM
This commit is contained in:
commit
08a0ebb533
9 changed files with 312 additions and 0 deletions
|
@ -20,10 +20,17 @@ interface API {
|
|||
registerUser(user: NewUser): Promise<APIResponse<User>>;
|
||||
/** Remove a user */
|
||||
removeUser(username: string, token: string): Promise<APIResponse<User>>;
|
||||
/** Check if user is project manager */
|
||||
checkIfProjectManager(
|
||||
username: string,
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<boolean>>;
|
||||
/** Login */
|
||||
login(NewUser: NewUser): Promise<APIResponse<string>>;
|
||||
/** Renew the token */
|
||||
renewToken(token: string): Promise<APIResponse<string>>;
|
||||
/** Promote user to admin */
|
||||
/** Create a project */
|
||||
createProject(
|
||||
project: NewProject,
|
||||
|
@ -41,6 +48,10 @@ interface API {
|
|||
week: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewWeeklyReport>>;
|
||||
getWeeklyReportsForProject(
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewWeeklyReport[]>>;
|
||||
/** Gets all the projects of a user*/
|
||||
getUserProjects(token: string): Promise<APIResponse<Project[]>>;
|
||||
/** Gets a project from id*/
|
||||
|
@ -101,6 +112,35 @@ export const api: API = {
|
|||
}
|
||||
},
|
||||
|
||||
async checkIfProjectManager(
|
||||
username: string,
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<boolean>> {
|
||||
try {
|
||||
const response = await fetch("/api/checkIfProjectManager", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
body: JSON.stringify({ username, projectName }),
|
||||
});
|
||||
|
||||
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: "fuck" };
|
||||
}
|
||||
},
|
||||
|
||||
async createProject(
|
||||
project: NewProject,
|
||||
token: string,
|
||||
|
@ -232,6 +272,34 @@ export const api: API = {
|
|||
}
|
||||
},
|
||||
|
||||
async getWeeklyReportsForProject(projectName: string, token: string) {
|
||||
try {
|
||||
const response = await fetch("/api/getWeeklyReportsForProject", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
body: JSON.stringify({ projectName }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed to get weekly reports for project",
|
||||
};
|
||||
} else {
|
||||
const data = (await response.json()) as NewWeeklyReport[];
|
||||
return { success: true, data };
|
||||
}
|
||||
} catch (e) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed to get weekly reports for project",
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
async login(NewUser: NewUser): Promise<APIResponse<string>> {
|
||||
try {
|
||||
const response = await fetch("/api/login", {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue