-
Notifications
You must be signed in to change notification settings - Fork 38
/
NumericField.ts
32 lines (26 loc) · 1.11 KB
/
NumericField.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Float } from 'type-graphql';
import { ColumnNumericOptions } from 'typeorm/decorator/options/ColumnNumericOptions';
import { ColumnCommonOptions } from 'typeorm/decorator/options/ColumnCommonOptions';
import { DecoratorCommonOptions } from '../metadata';
import { composeMethodDecorators } from '../utils';
import { NumericColumnType, NumericWhereOperator } from '../torm';
import { getCombinedDecorator } from './getCombinedDecorator';
interface NumericFieldOptions
extends ColumnCommonOptions,
ColumnNumericOptions,
DecoratorCommonOptions {
dataType?: NumericColumnType;
filter?: boolean | NumericWhereOperator[];
}
export function NumericField(options: NumericFieldOptions = {}): any {
const { dataType, filter, sort, ...dbOptions } = options;
const nullableOption = options.nullable === true ? { nullable: true } : {};
const factories = getCombinedDecorator({
fieldType: 'numeric',
warthogColumnMeta: options,
gqlFieldType: Float,
dbType: options.dataType ?? 'numeric',
dbColumnOptions: { ...nullableOption, ...dbOptions }
});
return composeMethodDecorators(...factories);
}