getStatistics handler, db-interface and ts API
This commit is contained in:
parent
2d2b63938c
commit
fe9d5f74bb
8 changed files with 188 additions and 1 deletions
|
@ -11,6 +11,7 @@ import {
|
|||
NewProject,
|
||||
WeeklyReport,
|
||||
StrNameChange,
|
||||
Statistics,
|
||||
} from "../Types/goTypes";
|
||||
|
||||
/**
|
||||
|
@ -258,6 +259,17 @@ interface API {
|
|||
reportId: number,
|
||||
token: string,
|
||||
): Promise<APIResponse<string>>;
|
||||
|
||||
/**
|
||||
* Retrieves the total time spent on a project for a particular user (the user is determined by the token)
|
||||
*
|
||||
* @param {string} projectName The name of the project
|
||||
* @param {string} token The authentication token
|
||||
*/
|
||||
getStatistics(
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<Statistics>>;
|
||||
}
|
||||
|
||||
/** An instance of the API */
|
||||
|
@ -962,4 +974,30 @@ export const api: API = {
|
|||
return { success: false, message: "Failed to delete report" };
|
||||
}
|
||||
},
|
||||
async getStatistics(
|
||||
token: string,
|
||||
projectName: string,
|
||||
): Promise<APIResponse<Statistics>> {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`/api/getStatistics/?projectName=${projectName}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
return { success: false, message: "Failed to get statistics" };
|
||||
} else {
|
||||
const data = (await response.json()) as Statistics;
|
||||
return { success: true, data };
|
||||
}
|
||||
} catch (e) {
|
||||
return { success: false, message: "Failed to get statistics" };
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -124,6 +124,14 @@ export interface WeeklyReport {
|
|||
*/
|
||||
signedBy?: number /* int */;
|
||||
}
|
||||
export interface Statistics {
|
||||
totalDevelopmentTime: number /* int */;
|
||||
totalMeetingTime: number /* int */;
|
||||
totalAdminTime: number /* int */;
|
||||
totalOwnWorkTime: number /* int */;
|
||||
totalStudyTime: number /* int */;
|
||||
totalTestingTime: number /* int */;
|
||||
}
|
||||
export interface UpdateWeeklyReport {
|
||||
/**
|
||||
* The name of the project, as it appears in the database
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue