-
Notifications
You must be signed in to change notification settings - Fork 38
/
DateTimeField.ts
30 lines (24 loc) · 1.06 KB
/
DateTimeField.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
// https://www.postgresql.org/docs/10/datatype-datetime.html
import { GraphQLISODateTime } from 'type-graphql';
import { DecoratorCommonOptions } from '../metadata';
import { DateTimeString } from '../core';
import { DateTimeWhereOperator } from '../torm';
import { composeMethodDecorators } from '../utils';
import { getCombinedDecorator } from './getCombinedDecorator';
interface DateTimeFieldOptions extends DecoratorCommonOptions {
default?: DateTimeString;
filter?: boolean | DateTimeWhereOperator[];
}
// V3: Deprecate this usage in favor of DateTimeField
export function DateTimeField(options: DateTimeFieldOptions = {}): any {
const nullableOption = options.nullable === true ? { nullable: true } : {};
const defaultOption = options.default ? { default: options.default } : {};
const factories = getCombinedDecorator({
fieldType: 'datetime',
warthogColumnMeta: options,
gqlFieldType: GraphQLISODateTime,
dbType: 'timestamp',
dbColumnOptions: { ...nullableOption, ...defaultOption }
});
return composeMethodDecorators(...factories);
}