getProjectTimes API
This commit is contained in:
parent
6efc961774
commit
644d0ee12c
1 changed files with 42 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
import { NewProjMember } from "../Components/AddMember";
|
||||
import { ProjectRoleChange } from "../Components/ChangeRole";
|
||||
import { projectTimes } from "../Components/GetProjectTimes";
|
||||
import { ProjectMember } from "../Components/GetUsersInProject";
|
||||
import {
|
||||
NewWeeklyReport,
|
||||
|
@ -126,6 +127,16 @@ interface API {
|
|||
*/
|
||||
getProject(id: number): Promise<APIResponse<Project>>;
|
||||
|
||||
/** Gets a projects reported time
|
||||
* @param {string} projectName The name of the project.
|
||||
* @param {string} token The usertoken.
|
||||
* @returns {Promise<APIResponse<Times>>} A promise resolving to an API response containing the project times.
|
||||
*/
|
||||
getProjectTimes(
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<projectTimes>>;
|
||||
|
||||
/** Gets a list of all users.
|
||||
* @param {string} token The authentication token of the requesting user.
|
||||
* @returns {Promise<APIResponse<string[]>>} A promise resolving to an API response containing the list of users.
|
||||
|
@ -385,6 +396,37 @@ export const api: API = {
|
|||
}
|
||||
},
|
||||
|
||||
async getProjectTimes(
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<projectTimes>> {
|
||||
try {
|
||||
const response = await fetch(`/api/getProjectTimes/${projectName}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return Promise.resolve({
|
||||
success: false,
|
||||
message:
|
||||
"Fetch error: " + response.status + ", failed to get project times",
|
||||
});
|
||||
} else {
|
||||
const data = (await response.json()) as projectTimes;
|
||||
return Promise.resolve({ success: true, data });
|
||||
}
|
||||
} catch (e) {
|
||||
return Promise.resolve({
|
||||
success: false,
|
||||
message: "API error! Could not get times.",
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
async submitWeeklyReport(
|
||||
weeklyReport: NewWeeklyReport,
|
||||
token: string,
|
||||
|
|
Loading…
Reference in a new issue