Skip to content

Commit

Permalink
Merge pull request #5 from fga-eps-mds/feat#75/gerenciar-jornada
Browse files Browse the repository at this point in the history
feat(#75): add endpoint get trails by journey
  • Loading branch information
DaviMatheus authored Aug 19, 2024
2 parents 3b97dbc + 42ac2fe commit 3f082fe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/journey/journey.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class JourneyService {
if (!journey) {
throw new NotFoundException(`Journey with ID ${id} not found`);
}
this.logger.log(`Deleted journey with ID ${id}`);
return journey;
}

Expand Down
5 changes: 5 additions & 0 deletions src/trail/trail.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export class TrailController {
return this.trailService.findAllTrails();
}

@Get('journey/:id')
async getTrailsByJourneyId(@Param('id') id: string) {
return this.trailService.findTrailsByJourneyId(id);
}

@Put(':id')
async updateTrail(
@Param('id') id: string,
Expand Down
7 changes: 7 additions & 0 deletions src/trail/trail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ export class TrailService {
return this.trailModel.find().exec();
}

async findTrailsByJourneyId(journeyId: string): Promise<Trail[]> {
const journey = await this.journeyModel.findById(journeyId).exec();
if (!journey) {
throw new NotFoundException(`Journey with ID ${journeyId} not found`);
}
return this.trailModel.find({ _id: { $in: journey.trails } }).exec();
}
async updateTrail(id: string, updateData: Partial<Trail>): Promise<Trail> {
const trail = await this.trailModel
.findByIdAndUpdate(id, updateData, { new: true })
Expand Down

0 comments on commit 3f082fe

Please sign in to comment.