Skip to content

Commit

Permalink
feat(team): Add parentObj and ancestorObjs virtuals to team
Browse files Browse the repository at this point in the history
  • Loading branch information
jrassa committed Nov 25, 2024
1 parent 47082bf commit 19388f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
17 changes: 17 additions & 0 deletions src/app/core/teams/team.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ TeamSchema.plugin(containsSearchPlugin, {
fields: ['name', 'description']
});

/*****************
* Virtual declarations
*****************/

TeamSchema.virtual('parentObj', {
ref: 'Team',
localField: 'parent',
foreignField: '_id',
justOne: true
});

TeamSchema.virtual('ancestorObjs', {
ref: 'Team',
localField: 'ancestors',
foreignField: '_id'
});

/**
* Index declarations
*/
Expand Down
10 changes: 2 additions & 8 deletions src/app/core/teams/teams.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,8 @@ export default function (_fastify: FastifyInstance) {
async function loadTeamById(req: FastifyRequest) {
const id = req.params['id'];
const populate = [
{
path: 'parent',
select: ['name']
},
{
path: 'ancestors',
select: ['name']
}
{ path: 'parentObj', select: ['name'] },
{ path: 'ancestorObjs', select: ['name'] }
];

req.team = await teamsService.read(id, populate);
Expand Down

0 comments on commit 19388f1

Please sign in to comment.