Skip to content

Commit

Permalink
cleaning up responses
Browse files Browse the repository at this point in the history
  • Loading branch information
sord-dev committed Aug 7, 2023
1 parent 638782d commit 3ce3c41
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/routes/TeamRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ router.get('/', async (req, res) => {
}
})


// Team CRUD Operations

router.post('/new', async (req, res) => {
Expand Down Expand Up @@ -102,4 +101,17 @@ router.get('/:teamId/:memberId/tasks', async (req, res) => {
}
});

// Team Memebrs Operations

router.get('/:teamId/members', async (req, res) => {
try {
const teamId = req.params.teamId;
const teamTasks = await TeamService.getMembers(teamId);
res.json(teamTasks);
} catch (error) {
console.log(error)
res.status(500).json({ error: 'Failed to fetch team members.' });
}
});

module.exports = router;
14 changes: 14 additions & 0 deletions src/services/TeamService.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class TeamService {
model: User,
attributes: { exclude: ['password', 'id', 'updatedAt'] } // Exclude the 'password' attribute
},
attributes: { exclude: ['backlog'] }
});

return allTeams.map(this.scrubTeamResponse);
Expand Down Expand Up @@ -79,6 +80,19 @@ class TeamService {
}
}

static async getMembers(teamId) {
try {
const team = await Team.findByPk(teamId, { include: { model: User, attributes: { exclude: ['id', 'updatedAt'] } } });
const members = this.scrubTeamResponse(team).members;

return members;

} catch (error) {
console.log(error)
throw new Error('Failed to query backlog.');
}
}

static async getMemberTasks(teamId, memberId) {
try {
const team = await Team.findByPk(teamId);
Expand Down

0 comments on commit 3ce3c41

Please sign in to comment.