-
Notifications
You must be signed in to change notification settings - Fork 38
/
DateField.ts
29 lines (23 loc) · 1 KB
/
DateField.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 { GraphQLISODateTime } from 'type-graphql';
import { DecoratorCommonOptions } from '../metadata';
import { ColumnType, DateWhereOperator } from '../torm';
import { composeMethodDecorators } from '../utils';
import { getCombinedDecorator } from './getCombinedDecorator';
interface DateFieldOptions extends DecoratorCommonOptions {
dataType?: ColumnType; // int16, jsonb, etc...
default?: Date;
filter?: boolean | DateWhereOperator[];
}
// V3: Deprecate this usage in favor of DateTimeField
export function DateField(options: DateFieldOptions = {}): any {
const nullableOption = options.nullable === true ? { nullable: true } : {};
const defaultOption = options.default ? { default: options.default } : {};
const factories = getCombinedDecorator({
fieldType: 'date',
warthogColumnMeta: options,
gqlFieldType: GraphQLISODateTime,
dbType: options.dataType || 'timestamp',
dbColumnOptions: { ...nullableOption, ...defaultOption }
});
return composeMethodDecorators(...factories);
}