Merge remote-tracking branch 'origin/dev' into BumBranch
This commit is contained in:
commit
d0cc6f2c1b
7 changed files with 76 additions and 27 deletions
|
@ -46,6 +46,13 @@ interface API {
|
|||
week: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewWeeklyReport>>;
|
||||
/** Gets all the projects of a user*/
|
||||
getUserProjects(
|
||||
username: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<Project[]>>;
|
||||
/** Gets a project from id*/
|
||||
getProject(id: number): Promise<APIResponse<Project>>;
|
||||
}
|
||||
|
||||
// Export an instance of the API
|
||||
|
@ -253,4 +260,30 @@ export const api: API = {
|
|||
return Promise.resolve({ success: false, message: "Failed to login" });
|
||||
}
|
||||
},
|
||||
|
||||
// Gets a projet by id, currently untested since we have no javascript-based tests
|
||||
async getProject(id: number): Promise<APIResponse<Project>> {
|
||||
try {
|
||||
const response = await fetch(`/api/project/${id}`, {
|
||||
method: "GET",
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed to get project: Response code " + response.status,
|
||||
};
|
||||
} else {
|
||||
const data = (await response.json()) as Project;
|
||||
return { success: true, data };
|
||||
}
|
||||
// The code below is garbage but satisfies the linter
|
||||
// This needs fixing, do not copy this pattern
|
||||
} catch (e: unknown) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed to get project: " + (e as Error).toString(),
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue