Commit a27aa9cf authored by nanahira's avatar nanahira

add comment as description

parent 77123080
Pipeline #11453 passed with stages
in 1 minute and 34 seconds
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
IsNotEmpty, IsNotEmpty,
IsOptional, IsOptional,
IsString, IsString,
MaxLength,
Min, Min,
} from 'class-validator'; } from 'class-validator';
import { ColumnWithWidthOptions } from 'typeorm/decorator/options/ColumnWithWidthOptions'; import { ColumnWithWidthOptions } from 'typeorm/decorator/options/ColumnWithWidthOptions';
...@@ -41,6 +42,7 @@ export const StringColumn = ( ...@@ -41,6 +42,7 @@ export const StringColumn = (
length, length,
default: defaultValue, default: defaultValue,
nullable: !required && defaultValue == null, nullable: !required && defaultValue == null,
comment: description,
...columnExtras, ...columnExtras,
}), }),
ApiProperty({ ApiProperty({
...@@ -48,11 +50,13 @@ export const StringColumn = ( ...@@ -48,11 +50,13 @@ export const StringColumn = (
description, description,
default: defaultValue, default: defaultValue,
required: required && defaultValue == null, required: required && defaultValue == null,
maxLength: length,
...propertyExtras, ...propertyExtras,
}), }),
...(required ? [] : [IsOptional()]), ...(required ? [] : [IsOptional()]),
IsString(), IsString(),
IsNotEmpty(), IsNotEmpty(),
MaxLength(length),
]); ]);
export const IntColumn = ( export const IntColumn = (
...@@ -69,6 +73,7 @@ export const IntColumn = ( ...@@ -69,6 +73,7 @@ export const IntColumn = (
default: defaultValue, default: defaultValue,
nullable: !required && defaultValue == null, nullable: !required && defaultValue == null,
unsigned, unsigned,
comment: description,
...(type === 'bigint' ? { transformer: new BigintTransformer() } : {}), ...(type === 'bigint' ? { transformer: new BigintTransformer() } : {}),
...columnExtras, ...columnExtras,
}), }),
...@@ -98,6 +103,7 @@ export const EnumColumn = <T>( ...@@ -98,6 +103,7 @@ export const EnumColumn = <T>(
enum: targetEnum, enum: targetEnum,
default: defaultValue, default: defaultValue,
nullable: !required && !defaultValue, nullable: !required && !defaultValue,
comment: description,
...columnExtras, ...columnExtras,
}), }),
ApiProperty({ ApiProperty({
......
...@@ -18,6 +18,7 @@ export const RelationColumn = ( ...@@ -18,6 +18,7 @@ export const RelationColumn = (
nullable: !notNull, nullable: !notNull,
unsigned: true, unsigned: true,
transformer: new BigintTransformer(), transformer: new BigintTransformer(),
comment: description,
...columnExtras, ...columnExtras,
}), }),
ApiProperty({ ApiProperty({
...@@ -30,7 +31,6 @@ export const RelationColumn = ( ...@@ -30,7 +31,6 @@ export const RelationColumn = (
IsInt(), IsInt(),
IsPositive(), IsPositive(),
]); ]);
export const StringRelationColumn = ( export const StringRelationColumn = (
description = '对应编号', description = '对应编号',
notNull = false, notNull = false,
...@@ -38,7 +38,12 @@ export const StringRelationColumn = ( ...@@ -38,7 +38,12 @@ export const StringRelationColumn = (
propertyExtras: ApiPropertyOptions = {}, propertyExtras: ApiPropertyOptions = {},
) => ) =>
MergePropertyDecorators([ MergePropertyDecorators([
Column('varchar', { length: 32, nullable: !notNull, ...columnExtras }), Column('varchar', {
length: 32,
nullable: !notNull,
comment: description,
...columnExtras,
}),
ApiProperty({ ApiProperty({
type: String, type: String,
required: notNull, required: notNull,
......
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