Compare commits
No commits in common. "ecce80babc082872e8a6dd30b9ba657080845711" and "fdaba36d5747bf62d31653e113812f5f9583ee8d" have entirely different histories.
ecce80babc
...
fdaba36d57
6 changed files with 13 additions and 43 deletions
|
@ -1,5 +1,5 @@
|
||||||
CREATE TABLE IF NOT EXISTS weekly_reports (
|
CREATE TABLE IF NOT EXISTS weekly_reports (
|
||||||
report_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
report_id INTEGER AUTO_INCREMENT UNIQUE,
|
||||||
user_id INTEGER NOT NULL,
|
user_id INTEGER NOT NULL,
|
||||||
project_id INTEGER NOT NULL,
|
project_id INTEGER NOT NULL,
|
||||||
week INTEGER NOT NULL,
|
week INTEGER NOT NULL,
|
||||||
|
@ -10,8 +10,8 @@ CREATE TABLE IF NOT EXISTS weekly_reports (
|
||||||
study_time INTEGER,
|
study_time INTEGER,
|
||||||
testing_time INTEGER,
|
testing_time INTEGER,
|
||||||
signed_by INTEGER,
|
signed_by INTEGER,
|
||||||
UNIQUE(user_id, project_id, week),
|
|
||||||
FOREIGN KEY (user_id) REFERENCES users(id),
|
FOREIGN KEY (user_id) REFERENCES users(id),
|
||||||
FOREIGN KEY (project_id) REFERENCES projects(id),
|
FOREIGN KEY (project_id) REFERENCES projects(id),
|
||||||
FOREIGN KEY (signed_by) REFERENCES users(id)
|
FOREIGN KEY (signed_by) REFERENCES users(id),
|
||||||
|
PRIMARY KEY (user_id, project_id, week)
|
||||||
);
|
);
|
|
@ -89,13 +89,13 @@ func (gs *GState) SignReport(c *fiber.Ctx) error {
|
||||||
|
|
||||||
log.Info("Signing report for: ", projectManagerUsername)
|
log.Info("Signing report for: ", projectManagerUsername)
|
||||||
|
|
||||||
// Extract report ID from the request
|
// Extract report ID from the request query parameters
|
||||||
rid, err := strconv.Atoi(c.Params("reportId"))
|
// reportID := c.Query("reportId")
|
||||||
if err != nil {
|
rid := new(ReportId)
|
||||||
log.Info("Invalid report ID:", err)
|
if err := c.BodyParser(rid); err != nil {
|
||||||
return c.Status(400).SendString("Invalid report ID")
|
return err
|
||||||
}
|
}
|
||||||
log.Info("Signing report for: ", rid)
|
log.Info("Signing report for: ", rid.ReportId)
|
||||||
|
|
||||||
// Get the project manager's ID
|
// Get the project manager's ID
|
||||||
projectManagerID, err := gs.Db.GetUserId(projectManagerUsername)
|
projectManagerID, err := gs.Db.GetUserId(projectManagerUsername)
|
||||||
|
@ -106,7 +106,7 @@ func (gs *GState) SignReport(c *fiber.Ctx) error {
|
||||||
log.Info("Project manager ID: ", projectManagerID)
|
log.Info("Project manager ID: ", projectManagerID)
|
||||||
|
|
||||||
// Call the database function to sign the weekly report
|
// Call the database function to sign the weekly report
|
||||||
err = gs.Db.SignWeeklyReport(rid, projectManagerID)
|
err = gs.Db.SignWeeklyReport(rid.ReportId, projectManagerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("Error signing weekly report:", err)
|
log.Info("Error signing weekly report:", err)
|
||||||
return c.Status(500).SendString(err.Error())
|
return c.Status(500).SendString(err.Error())
|
||||||
|
|
|
@ -92,7 +92,7 @@ func main() {
|
||||||
server.Get("/api/project/:projectId", gs.GetProject)
|
server.Get("/api/project/:projectId", gs.GetProject)
|
||||||
server.Get("/api/project/getAllUsers", gs.GetAllUsersProject)
|
server.Get("/api/project/getAllUsers", gs.GetAllUsersProject)
|
||||||
server.Get("/api/getWeeklyReport", gs.GetWeeklyReport)
|
server.Get("/api/getWeeklyReport", gs.GetWeeklyReport)
|
||||||
server.Post("/api/signReport/:reportId", gs.SignReport)
|
server.Post("/api/signReport", gs.SignReport)
|
||||||
server.Put("/api/addUserToProject", gs.AddUserToProjectHandler)
|
server.Put("/api/addUserToProject", gs.AddUserToProjectHandler)
|
||||||
server.Put("/api/changeUserName", gs.ChangeUserName)
|
server.Put("/api/changeUserName", gs.ChangeUserName)
|
||||||
server.Post("/api/promoteToAdmin", gs.PromoteToAdmin)
|
server.Post("/api/promoteToAdmin", gs.PromoteToAdmin)
|
||||||
|
|
|
@ -127,11 +127,6 @@ interface API {
|
||||||
* @returns {Promise<APIResponse<string[]>>} A promise resolving to an API response containing the list of users.
|
* @returns {Promise<APIResponse<string[]>>} A promise resolving to an API response containing the list of users.
|
||||||
*/
|
*/
|
||||||
getAllUsers(token: string): Promise<APIResponse<string[]>>;
|
getAllUsers(token: string): Promise<APIResponse<string[]>>;
|
||||||
|
|
||||||
/**
|
|
||||||
* Sign a report
|
|
||||||
*/
|
|
||||||
signReport(reportId: number, token: string): Promise<APIResponse<boolean>>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An instance of the API */
|
/** An instance of the API */
|
||||||
|
@ -453,29 +448,4 @@ export const api: API = {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async signReport(
|
|
||||||
reportId: number,
|
|
||||||
token: string,
|
|
||||||
): Promise<APIResponse<boolean>> {
|
|
||||||
try {
|
|
||||||
const response = await fetch(`/api/signReport/${reportId}`, {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: "Bearer " + token,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
message: "Failed to sign report:" + response.status,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return { success: true };
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
return { success: false, message: "Failed to sign report" };
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,7 +30,7 @@ function AllTimeReportsInProject(): JSX.Element {
|
||||||
// Call getProjects when the component mounts
|
// Call getProjects when the component mounts
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void getWeeklyReports();
|
void getWeeklyReports();
|
||||||
}, []);
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -274,7 +274,7 @@ def test_sign_report():
|
||||||
submitReportPath,
|
submitReportPath,
|
||||||
json={
|
json={
|
||||||
"projectName": projectName,
|
"projectName": projectName,
|
||||||
"week": 2,
|
"week": 1,
|
||||||
"developmentTime": 10,
|
"developmentTime": 10,
|
||||||
"meetingTime": 5,
|
"meetingTime": 5,
|
||||||
"adminTime": 5,
|
"adminTime": 5,
|
||||||
|
|
Loading…
Reference in a new issue