Merge branch 'dev' into gruppDM
This commit is contained in:
commit
b9b17bf229
14 changed files with 325 additions and 62 deletions
|
@ -7,62 +7,131 @@ import {
|
|||
WeeklyReport,
|
||||
} from "../Types/goTypes";
|
||||
|
||||
// This type of pattern should be hard to misuse
|
||||
/**
|
||||
* Response object returned by API methods.
|
||||
*/
|
||||
export interface APIResponse<T> {
|
||||
/** Indicates whether the API call was successful */
|
||||
success: boolean;
|
||||
/** Optional message providing additional information or error description */
|
||||
message?: string;
|
||||
/** Optional data returned by the API method */
|
||||
data?: T;
|
||||
}
|
||||
|
||||
// Note that all protected routes also require a token
|
||||
// Defines all the methods that an instance of the API must implement
|
||||
/**
|
||||
* Interface defining methods that an instance of the API must implement.
|
||||
*/
|
||||
interface API {
|
||||
/** Register a new user */
|
||||
/**
|
||||
* Register a new user
|
||||
* @param {NewUser} user The user object to be registered
|
||||
* @returns {Promise<APIResponse<User>>} A promise containing the API response with the user data.
|
||||
*/
|
||||
registerUser(user: NewUser): Promise<APIResponse<User>>;
|
||||
/** Remove a user */
|
||||
|
||||
/**
|
||||
* Removes a user.
|
||||
* @param {string} username The username of the user to be removed.
|
||||
* @param {string} token The authentication token.
|
||||
* @returns {Promise<APIResponse<User>>} A promise containing the API response with the removed user data.
|
||||
*/
|
||||
removeUser(username: string, token: string): Promise<APIResponse<User>>;
|
||||
/** Check if user is project manager */
|
||||
|
||||
/**
|
||||
* 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(
|
||||
username: string,
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<boolean>>;
|
||||
/** Login */
|
||||
|
||||
/** 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 */
|
||||
|
||||
/**
|
||||
* Renew the token
|
||||
* @param {string} token The current authentication token.
|
||||
* @returns {Promise<APIResponse<string>>} A promise resolving to an API response with a renewed token.
|
||||
*/
|
||||
renewToken(token: string): Promise<APIResponse<string>>;
|
||||
|
||||
/** Promote user to admin */
|
||||
/** Create a project */
|
||||
|
||||
/** Creates a new project.
|
||||
* @param {NewProject} project The project object containing name and description.
|
||||
* @param {string} token The authentication token.
|
||||
* @returns {Promise<APIResponse<Project>>} A promise resolving to an API response with the created project.
|
||||
*/
|
||||
createProject(
|
||||
project: NewProject,
|
||||
token: string,
|
||||
): Promise<APIResponse<Project>>;
|
||||
/** Submit a weekly report */
|
||||
|
||||
/** Submits a weekly report
|
||||
* @param {NewWeeklyReport} weeklyReport The weekly report object.
|
||||
* @param {string} token The authentication token.
|
||||
* @returns {Promise<APIResponse<NewWeeklyReport>>} A promise resolving to an API response with the submitted report.
|
||||
*/
|
||||
submitWeeklyReport(
|
||||
project: NewWeeklyReport,
|
||||
weeklyReport: NewWeeklyReport,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewWeeklyReport>>;
|
||||
/**Gets a weekly report*/
|
||||
|
||||
/** Gets a weekly report for a specific user, project and week
|
||||
* @param {string} username The username of the user.
|
||||
* @param {string} projectName The name of the project.
|
||||
* @param {string} week The week number.
|
||||
* @param {string} token The authentication token.
|
||||
* @returns {Promise<APIResponse<WeeklyReport>>} A promise resolving to an API response with the retrieved report.
|
||||
*/
|
||||
getWeeklyReport(
|
||||
username: string,
|
||||
projectName: string,
|
||||
week: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<WeeklyReport>>;
|
||||
|
||||
/**
|
||||
* Returns all the weekly reports for a user in a particular project
|
||||
* The username is derived from the token
|
||||
* @param {string} projectName The name of the project
|
||||
* @param {string} token The token of the user
|
||||
* @returns {APIResponse<WeeklyReport[]>} A list of weekly reports
|
||||
*/
|
||||
getWeeklyReportsForUser(
|
||||
username: string,
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<WeeklyReport[]>>;
|
||||
/** Gets all the projects of a user*/
|
||||
|
||||
/** Gets all the projects of a user
|
||||
* @param {string} token - The authentication token.
|
||||
* @returns {Promise<APIResponse<Project[]>>} A promise containing the API response with the user's projects.
|
||||
*/
|
||||
getUserProjects(token: string): Promise<APIResponse<Project[]>>;
|
||||
/** Gets a project from id*/
|
||||
|
||||
/** Gets a project by its id.
|
||||
* @param {number} id The id of the project to retrieve.
|
||||
* @returns {Promise<APIResponse<Project>>} A promise resolving to an API response containing the project data.
|
||||
*/
|
||||
getProject(id: number): Promise<APIResponse<Project>>;
|
||||
/** Gets a project from id*/
|
||||
|
||||
/** 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.
|
||||
*/
|
||||
getAllUsers(token: string): Promise<APIResponse<string[]>>;
|
||||
}
|
||||
|
||||
// Export an instance of the API
|
||||
/** An instance of the API */
|
||||
export const api: API = {
|
||||
async registerUser(user: NewUser): Promise<APIResponse<User>> {
|
||||
try {
|
||||
|
@ -277,26 +346,24 @@ export const api: API = {
|
|||
},
|
||||
|
||||
async getWeeklyReportsForUser(
|
||||
username: string,
|
||||
projectName: string,
|
||||
token: string,
|
||||
): Promise<APIResponse<WeeklyReport[]>> {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`/api/getWeeklyReportsUser?username=${username}&projectName=${projectName}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
const response = await fetch(`/api/getWeeklyReportsUser/${projectName}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed to get weekly reports for project",
|
||||
message:
|
||||
"Failed to get weekly reports for project: Response code " +
|
||||
response.status,
|
||||
};
|
||||
} else {
|
||||
const data = (await response.json()) as WeeklyReport[];
|
||||
|
@ -305,7 +372,7 @@ export const api: API = {
|
|||
} catch (e) {
|
||||
return {
|
||||
success: false,
|
||||
message: "fucked again",
|
||||
message: "Failed to get weekly reports for project, unknown error",
|
||||
};
|
||||
}
|
||||
},
|
||||
|
@ -331,7 +398,6 @@ export const api: API = {
|
|||
}
|
||||
},
|
||||
|
||||
// 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}`, {
|
||||
|
@ -357,7 +423,6 @@ export const api: API = {
|
|||
}
|
||||
},
|
||||
|
||||
// Gets all users
|
||||
async getAllUsers(token: string): Promise<APIResponse<string[]>> {
|
||||
try {
|
||||
const response = await fetch("/api/users/all", {
|
||||
|
|
|
@ -7,7 +7,7 @@ import Button from "./Button";
|
|||
|
||||
/**
|
||||
* Tries to add a project to the system
|
||||
* @param props - Project name and description
|
||||
* @param {Object} props - Project name and description
|
||||
* @returns {boolean} True if created, false if not
|
||||
*/
|
||||
function CreateProject(props: { name: string; description: string }): boolean {
|
||||
|
@ -34,8 +34,8 @@ function CreateProject(props: { name: string; description: string }): boolean {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tries to add a project to the system
|
||||
* @returns {JSX.Element} UI for project adding
|
||||
* Provides UI for adding a project to the system.
|
||||
* @returns {JSX.Element} - Returns the component UI for adding a project
|
||||
*/
|
||||
function AddProject(): JSX.Element {
|
||||
const [name, setName] = useState("");
|
||||
|
|
|
@ -7,7 +7,7 @@ import { api } from "../API/API";
|
|||
|
||||
/**
|
||||
* Renders a component that displays all the time reports for a specific project.
|
||||
* @returns JSX.Element representing the component.
|
||||
* @returns {JSX.Element} representing the component.
|
||||
*/
|
||||
function AllTimeReportsInProject(): JSX.Element {
|
||||
const { projectName } = useParams();
|
||||
|
@ -16,7 +16,6 @@ function AllTimeReportsInProject(): JSX.Element {
|
|||
const getWeeklyReports = async (): Promise<void> => {
|
||||
const token = localStorage.getItem("accessToken") ?? "";
|
||||
const response = await api.getWeeklyReportsForUser(
|
||||
localStorage.getItem("username") ?? "",
|
||||
projectName ?? "",
|
||||
token,
|
||||
);
|
||||
|
|
|
@ -40,6 +40,44 @@ export interface NewWeeklyReport {
|
|||
*/
|
||||
testingTime: number /* int */;
|
||||
}
|
||||
export interface WeeklyReportList {
|
||||
/**
|
||||
* The name of the project, as it appears in the database
|
||||
*/
|
||||
projectName: string;
|
||||
/**
|
||||
* The week number
|
||||
*/
|
||||
week: number /* int */;
|
||||
/**
|
||||
* Total time spent on development
|
||||
*/
|
||||
developmentTime: number /* int */;
|
||||
/**
|
||||
* Total time spent in meetings
|
||||
*/
|
||||
meetingTime: number /* int */;
|
||||
/**
|
||||
* Total time spent on administrative tasks
|
||||
*/
|
||||
adminTime: number /* int */;
|
||||
/**
|
||||
* Total time spent on personal projects
|
||||
*/
|
||||
ownWorkTime: number /* int */;
|
||||
/**
|
||||
* Total time spent on studying
|
||||
*/
|
||||
studyTime: number /* int */;
|
||||
/**
|
||||
* Total time spent on testing
|
||||
*/
|
||||
testingTime: number /* int */;
|
||||
/**
|
||||
* The project manager who signed it
|
||||
*/
|
||||
signedBy?: number /* int */;
|
||||
}
|
||||
export interface WeeklyReport {
|
||||
/**
|
||||
* The ID of the report
|
||||
|
@ -106,6 +144,15 @@ export interface NewProject {
|
|||
name: string;
|
||||
description: string;
|
||||
}
|
||||
export interface RoleChange {
|
||||
role: 'project_manager' | 'user';
|
||||
username: string;
|
||||
projectname: string;
|
||||
}
|
||||
export interface NameChange {
|
||||
id: number /* int */;
|
||||
name: string;
|
||||
}
|
||||
|
||||
//////////
|
||||
// source: users.go
|
||||
|
@ -138,3 +185,7 @@ export interface PublicUser {
|
|||
export interface Token {
|
||||
token: string;
|
||||
}
|
||||
export interface StrNameChange {
|
||||
prevName: string;
|
||||
newName: string;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue