-
Notifications
You must be signed in to change notification settings - Fork 38
/
IntField.ts
29 lines (23 loc) · 937 Bytes
/
IntField.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
import { Int } from 'type-graphql';
import { DecoratorCommonOptions } from '../metadata';
import { IntColumnType, IntWhereOperator } from '../torm';
import { composeMethodDecorators } from '../utils';
import { getCombinedDecorator } from './getCombinedDecorator';
interface IntFieldOptions extends DecoratorCommonOptions {
dataType?: IntColumnType;
default?: number;
filter?: boolean | IntWhereOperator[];
array?: boolean;
}
export function IntField(options: IntFieldOptions = {}): any {
const defaultOption = options.default ? { default: options.default } : {};
const nullableOption = options.nullable === true ? { nullable: true } : {};
const factories = getCombinedDecorator({
fieldType: 'integer',
warthogColumnMeta: options,
gqlFieldType: Int,
dbType: options.dataType ?? 'int',
dbColumnOptions: { ...nullableOption, ...defaultOption }
});
return composeMethodDecorators(...factories);
}