Skip to content

Commit

Permalink
fix: fixed an issue where boolean string would not be transformed pro…
Browse files Browse the repository at this point in the history
…perly with implicit transformation enabled
  • Loading branch information
spuxx1701 committed Oct 27, 2023
1 parent 147c6eb commit ff10334
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/).

## [2.2.1] - 2023-10-27

### Fixed

- Fixed an issue where boolean string would not be transformed properly with implicit transformation enabled.

## [2.2.0] - 2023-10-27

### Added
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "potber-api",
"version": "2.2.0",
"version": "2.2.1",
"description": "A modern JSON API for forum.mods.de",
"author": "",
"private": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class PrivateMessagesFindManyQuery {
@IsOptional()
folder?: PrivateMessageFolder;

@TransformBooleanString()
@TransformBooleanString('unread')
@IsBoolean()
@IsOptional()
unread?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class ThreadsFindByIdQuery {
@IsOptional()
page?: number;

@TransformBooleanString()
@TransformBooleanString('updateBookmark')
@IsBoolean()
@IsOptional()
updateBookmark: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/threads/controllers/threads.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class ThreadsController {
@Request() request: ExpressRequest,
@Query() query: ThreadsFindByIdQuery,
): Promise<ThreadReadResource> {
console.log(query);
return this.service.findById(id, request.user, {
...query,
});
Expand Down
10 changes: 7 additions & 3 deletions src/utility/transformers/boolean-string.transformer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Transform } from 'class-transformer';

export function TransformBooleanString() {
return Transform(({ value }) => {
return value === 'true';
/**
* Implicit conversion does not properly convert boolean strings, so we need to
* handle those manually.
*/
export function TransformBooleanString(key: string) {
return Transform(({ obj }) => {
return obj[key].toLowerCase() === 'true';
});
}

0 comments on commit ff10334

Please sign in to comment.