Skip to content

Commit

Permalink
Use builtin parsers for boolean query params (safe-global#747)
Browse files Browse the repository at this point in the history
Adds ParseBoolPipe to validate boolean query params at controllers
  • Loading branch information
hectorgomezv authored Oct 11, 2023
1 parent c21e2cf commit 62882df
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/routes/balances/balances.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ describe('Balances Controller (Unit)', () => {
// trusted and exclude_spam params are passed
expect(networkService.get.mock.calls[1][1]).toStrictEqual({
params: {
trusted: trusted.toString(),
exclude_spam: excludeSpam.toString(),
trusted,
exclude_spam: excludeSpam,
},
});
});
Expand Down
7 changes: 5 additions & 2 deletions src/routes/balances/balances.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
DefaultValuePipe,
Get,
Param,
ParseBoolPipe,
Query,
} from '@nestjs/common';
import { BalancesService } from './balances.service';
Expand All @@ -23,8 +24,10 @@ export class BalancesController {
@Param('chainId') chainId: string,
@Param('safeAddress') safeAddress: string,
@Param('fiatCode') fiatCode: string,
@Query('trusted', new DefaultValuePipe(false)) trusted: boolean,
@Query('exclude_spam', new DefaultValuePipe(true)) excludeSpam: boolean,
@Query('trusted', new DefaultValuePipe(false), ParseBoolPipe)
trusted: boolean,
@Query('exclude_spam', new DefaultValuePipe(true), ParseBoolPipe)
excludeSpam: boolean,
): Promise<Balances> {
return this.balancesService.getBalances({
chainId,
Expand Down
4 changes: 2 additions & 2 deletions src/routes/collectibles/collectibles.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ describe('Collectibles Controller (Unit)', () => {
params: {
limit: PaginationData.DEFAULT_LIMIT,
offset: PaginationData.DEFAULT_OFFSET,
exclude_spam: excludeSpam.toString(),
trusted: trusted.toString(),
exclude_spam: excludeSpam,
trusted,
},
});
});
Expand Down
7 changes: 5 additions & 2 deletions src/routes/collectibles/collectibles.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
DefaultValuePipe,
Get,
Param,
ParseBoolPipe,
Query,
} from '@nestjs/common';
import { CollectiblesService } from './collectibles.service';
Expand Down Expand Up @@ -43,8 +44,10 @@ export class CollectiblesController {
@Param('safeAddress') safeAddress: string,
@RouteUrlDecorator() routeUrl: URL,
@PaginationDataDecorator() paginationData: PaginationData,
@Query('trusted', new DefaultValuePipe(false)) trusted: boolean,
@Query('exclude_spam', new DefaultValuePipe(true)) excludeSpam: boolean,
@Query('trusted', new DefaultValuePipe(false), ParseBoolPipe)
trusted: boolean,
@Query('exclude_spam', new DefaultValuePipe(true), ParseBoolPipe)
excludeSpam: boolean,
): Promise<Page<Collectible>> {
return this.service.getCollectibles({
chainId,
Expand Down
3 changes: 2 additions & 1 deletion src/routes/transactions/transactions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export class TransactionsController {
@Query('to') to?: string,
@Query('value') value?: string,
@Query('nonce') nonce?: string,
@Query('executed') executed?: boolean,
@Query('executed', new ParseBoolPipe({ optional: true }))
executed?: boolean,
): Promise<Partial<Page<MultisigTransaction>>> {
return this.transactionsService.getMultisigTransactions({
chainId,
Expand Down

0 comments on commit 62882df

Please sign in to comment.