In my NodeJS method i make a simple select that return a response like:
[{id: 1, project: "project A", user: "Tom", duration: 8},
{id: 2, project: "project B", user: "Mark", duration: 8},
{id: 1, project: "project A", user: "Mark", duration: 8},
{id: 3, project: "project C", user: "Tom", duration: 8},
{id: 3, project: "project C", user: "Mark", duration: 8},
{id: 3, project: "project C", user: "Helen", duration: 8}]
How can i achieve to edit this array so that the final response that is sent in frontend to look like this:
[{project: {projectName: "project A", users: [{userName: "Tom", duration: 8},
{userName: "Mark", duration: 8}]},
{projectName: "project B", users: [{userName: "Mark", duration: 8}]},
{projectName: "project C", users: [{userName: "Tom", duration: 8},
{userName: "Mark", duration: 8},
{userName: "Helen", duration: 8}]}
Somehow I need to make an array of objects with the users and durations that are on the same project.
If it is more helpful, the general idea is that I have to create a monthly report that will get every user with worked hours on every project.
If someone can help me, thank you!