Skip to content

Commit 73e610a

Browse files
Brent KulwickiCarsonF
authored andcommitted
Add DateFilter.isNull
1 parent bd7c35c commit 73e610a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/common/date-filter.input.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InputType } from '@nestjs/graphql';
1+
import { Field, InputType } from '@nestjs/graphql';
22
import { DateTime } from 'luxon';
33
import { DateField, DateTimeField } from './luxon.graphql';
44
import { CalendarDate } from './temporal';
@@ -30,6 +30,9 @@ export abstract class DateFilter {
3030
nullable: true,
3131
})
3232
beforeInclusive?: CalendarDate;
33+
34+
@Field({ description: 'Whether the field is null or not', nullable: true })
35+
isNull?: boolean;
3336
}
3437

3538
@InputType({
@@ -59,4 +62,7 @@ export abstract class DateTimeFilter {
5962
nullable: true,
6063
})
6164
beforeInclusive?: DateTime;
65+
66+
@Field({ description: 'Whether the field is null or not', nullable: true })
67+
isNull?: boolean;
6268
}

src/core/database/query/filters.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,13 @@ export const comparisonOfDateTimeFilter = (
222222
after: comparisions.greaterThan,
223223
beforeInclusive: comparisions.lessEqualTo,
224224
before: comparisions.lessThan,
225+
isNull:
226+
(val: boolean | any): Comparator =>
227+
(_, name) =>
228+
`${name} ${val ? 'IS' : 'IS NOT'} NULL`,
225229
};
226230
const comparators = entries(input).flatMap(([key, val]) =>
227-
val ? comparatorMap[key](val) : [],
231+
val != null ? comparatorMap[key](val) : [],
228232
);
229233
return comparators.length > 0
230234
? (...args) => comparators.map((comp) => comp(...args)).join(' AND ')

0 commit comments

Comments
 (0)