Commit 4e22e17a authored by nanahira's avatar nanahira

update bool column handle

parent 4e7f22f6
...@@ -19,7 +19,7 @@ import { ...@@ -19,7 +19,7 @@ import {
} from 'typeorm/driver/types/ColumnTypes'; } from 'typeorm/driver/types/ColumnTypes';
import { ColumnWithWidthOptions } from 'typeorm/decorator/options/ColumnWithWidthOptions'; import { ColumnWithWidthOptions } from 'typeorm/decorator/options/ColumnWithWidthOptions';
import { ColumnNumericOptions } from 'typeorm/decorator/options/ColumnNumericOptions'; import { ColumnNumericOptions } from 'typeorm/decorator/options/ColumnNumericOptions';
import { Exclude } from 'class-transformer'; import { Exclude, Transform } from 'class-transformer';
import { BigintTransformer } from '../utility/bigint'; import { BigintTransformer } from '../utility/bigint';
import { Metadata } from '../utility/metadata'; import { Metadata } from '../utility/metadata';
...@@ -164,6 +164,13 @@ export const BoolColumn = ( ...@@ -164,6 +164,13 @@ export const BoolColumn = (
): PropertyDecorator => ): PropertyDecorator =>
MergePropertyDecorators([ MergePropertyDecorators([
Index(), Index(),
Transform((v) => {
const trueValues = ['true', '1', 'yes', 'on', true, 1];
const falseValues = ['false', '0', 'no', 'off', false, 0];
if (trueValues.indexOf(v.value) !== -1) return true;
if (falseValues.indexOf(v.value) !== -1) return false;
return undefined;
}),
Column('boolean', columnDecoratorOptions(options)), Column('boolean', columnDecoratorOptions(options)),
validatorDecorator(options), validatorDecorator(options),
swaggerDecorator(options, { type: Boolean }), swaggerDecorator(options, { type: Boolean }),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment