-
Notifications
You must be signed in to change notification settings - Fork 38
/
DateOnlyField.ts
30 lines (24 loc) · 1.02 KB
/
DateOnlyField.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 { DateResolver } from 'graphql-scalars';
import { DecoratorCommonOptions } from '../metadata';
import { DateOnlyString } from '../core';
import { DateOnlyWhereOperator } from '../torm';
import { composeMethodDecorators } from '../utils';
import { getCombinedDecorator } from './getCombinedDecorator';
interface DateOnlyFieldOptions extends DecoratorCommonOptions {
default?: DateOnlyString;
filter?: boolean | DateOnlyWhereOperator[];
}
// V3: Update this to DateField
export function DateOnlyField(options: DateOnlyFieldOptions = {}): any {
const nullableOption = options.nullable === true ? { nullable: true } : {};
const defaultOption = options.default ? { default: options.default } : {};
const factories = getCombinedDecorator({
fieldType: 'dateonly',
warthogColumnMeta: options,
gqlFieldType: DateResolver,
dbType: 'date',
dbColumnOptions: { ...nullableOption, ...defaultOption }
});
return composeMethodDecorators(...factories);
}