Merge branch 'dev' into gruppDM
This commit is contained in:
commit
492cfed08c
2 changed files with 58 additions and 4 deletions
|
@ -233,3 +233,57 @@ func (gs *GState) IsProjectManagerHandler(c *fiber.Ctx) error {
|
|||
// Return the result as JSON
|
||||
return c.JSON(fiber.Map{"isProjectManager": isManager})
|
||||
}
|
||||
|
||||
func (gs *GState) GetProjectTimesHandler(c *fiber.Ctx) error {
|
||||
// Get the username from the token
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
username := claims["name"].(string)
|
||||
|
||||
// Get project
|
||||
projectName := c.Params("projectName")
|
||||
if projectName == "" {
|
||||
log.Info("No project name provided")
|
||||
return c.Status(400).SendString("No project name provided")
|
||||
}
|
||||
|
||||
// Get all users in the project and roles
|
||||
userProjects, err := gs.Db.GetAllUsersProject(projectName)
|
||||
if err != nil {
|
||||
log.Info("Error getting users in project:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
// If the user is member
|
||||
isMember := false
|
||||
for _, userProject := range userProjects {
|
||||
if userProject.Username == username {
|
||||
isMember = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// If the user is admin
|
||||
if !isMember {
|
||||
isAdmin, err := gs.Db.IsSiteAdmin(username)
|
||||
if err != nil {
|
||||
log.Info("Error checking admin status:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
if !isAdmin {
|
||||
log.Info("User is neither a project member nor a site admin:", username)
|
||||
return c.Status(403).SendString("User is neither a project member nor a site admin")
|
||||
}
|
||||
}
|
||||
|
||||
// Get project times
|
||||
projectTimes, err := gs.Db.GetProjectTimes(projectName)
|
||||
if err != nil {
|
||||
log.Info("Error getting project times:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
// Return project times as JSON
|
||||
log.Info("Returning project times for project:", projectName)
|
||||
return c.JSON(projectTimes)
|
||||
}
|
|
@ -85,7 +85,7 @@ interface API {
|
|||
submitWeeklyReport(
|
||||
weeklyReport: NewWeeklyReport,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewWeeklyReport>>;
|
||||
): Promise<APIResponse<string>>;
|
||||
|
||||
/** Gets a weekly report for a specific user, project and week
|
||||
* @param {string} projectName The name of the project.
|
||||
|
@ -294,7 +294,7 @@ export const api: API = {
|
|||
async submitWeeklyReport(
|
||||
weeklyReport: NewWeeklyReport,
|
||||
token: string,
|
||||
): Promise<APIResponse<NewWeeklyReport>> {
|
||||
): Promise<APIResponse<string>> {
|
||||
try {
|
||||
const response = await fetch("/api/submitWeeklyReport", {
|
||||
method: "POST",
|
||||
|
@ -312,8 +312,8 @@ export const api: API = {
|
|||
};
|
||||
}
|
||||
|
||||
const data = (await response.json()) as NewWeeklyReport;
|
||||
return { success: true, data };
|
||||
const data = await response.text();
|
||||
return { success: true, message: data };
|
||||
} catch (e) {
|
||||
return {
|
||||
success: false,
|
||||
|
|
Loading…
Reference in a new issue