Skip to content

Commit

Permalink
Use boolean pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjstevens committed Oct 8, 2024
1 parent 6e63137 commit de035bd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Controller, Get, Logger, Param, Query } from '@nestjs/common'
import {
Controller,
Get,
Logger,
Param,
ParseBoolPipe,
Query,
} from '@nestjs/common'

import { FeatureRangeSearchDto } from '../entity/gff3Object.dto'
import { Role } from '../utils/role/role.enum'
Expand Down Expand Up @@ -56,10 +63,11 @@ export class FeaturesController {
@Get(':featureid')
getFeature(
@Param('featureid') featureid: string,
@Query('topLevel') topLevel: string,
@Query('topLevel', new ParseBoolPipe({ optional: true }))
topLevel: boolean | undefined,
) {
this.logger.debug(`Get feature by featureId: ${featureid}`)
return this.featuresService.findById(featureid, topLevel == 'true')
return this.featuresService.findById(featureid, topLevel)
}

@Get('check/:featureid')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class FeaturesService {
* @param topLevel - If true, return the top level feature and its children. If false, return the requested feature and its children.
* @returns Return the feature(s) if search was successful. Otherwise throw exception
*/
async findById(featureId: string, topLevel: boolean) {
async findById(featureId: string, topLevel?: boolean) {
// Search correct feature
const topLevelFeature = await this.featureModel
.findOne({ allIds: featureId })
Expand Down Expand Up @@ -111,7 +111,7 @@ export class FeaturesService {
getFeatureFromId(
feature: Feature,
featureId: string,
topLevel: boolean,
topLevel?: boolean,
parent?: Feature | null,
): Feature | null {
this.logger.verbose(`Entry=${JSON.stringify(feature)}`)
Expand Down

0 comments on commit de035bd

Please sign in to comment.