Commit b575540d authored by nanahira's avatar nanahira

updates

parent 822a50a5
Pipeline #7076 passed with stages
in 1 minute and 20 seconds
......@@ -5,11 +5,14 @@ import { ColumnCommonOptions } from 'typeorm/decorator/options/ColumnCommonOptio
import { ColumnEnumOptions } from 'typeorm/decorator/options/ColumnEnumOptions';
import {
IsEnum,
IsInt,
IsNotEmpty,
IsOptional,
IsString,
ValidateIf,
Min,
} from 'class-validator';
import { ColumnWithWidthOptions } from 'typeorm/decorator/options/ColumnWithWidthOptions';
import { BigintTransformer } from '../utility/bigint-transform';
export function MergePropertyDecorators(
decs: PropertyDecorator[],
......@@ -36,14 +39,14 @@ export const StringColumn = (
Column('varchar', {
length,
default: defaultValue,
nullable: !required && !defaultValue,
nullable: !required && defaultValue == null,
...columnExtras,
}),
ApiProperty({
type: String,
description,
default: defaultValue,
required: required && !defaultValue,
required: required && defaultValue == null,
...propertyExtras,
}),
...(required ? [] : [IsOptional()]),
......@@ -51,6 +54,35 @@ export const StringColumn = (
IsNotEmpty(),
]);
export const IntColumn = (
type: 'int' | 'smallint' | 'bigint' | 'tinyint' = 'int',
unsigned = false,
description = 'unknown',
defaultValue?: number,
required = false,
columnExtras: ColumnCommonOptions & ColumnWithWidthOptions = {},
propertyExtras: ApiPropertyOptions = {},
) =>
MergePropertyDecorators([
Column(type, {
default: defaultValue,
nullable: !required && defaultValue == null,
unsigned,
...(type === 'bigint' ? { transformer: new BigintTransformer() } : {}),
...columnExtras,
}),
ApiProperty({
type: Number,
description,
default: defaultValue,
required: required && defaultValue == null,
...propertyExtras,
}),
...(required ? [] : [IsOptional()]),
IsInt(),
...(unsigned ? [Min(0)] : []),
]);
export const EnumColumn = <T>(
targetEnum: Record<string, T>,
description = 'unknown',
......
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