Skip to content

Commit fe70d06

Browse files
authored
Merge pull request #3273 from SeedCompany/date-filters-projects
2 parents 6f47a20 + 73e610a commit fe70d06

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-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/components/project/dto/list-projects.dto.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Field, InputType, ObjectType } from '@nestjs/graphql';
22
import { Type } from 'class-transformer';
33
import { ValidateNested } from 'class-validator';
44
import {
5+
DateFilter,
56
DateTimeFilter,
67
FilterField,
78
ID,
@@ -78,6 +79,20 @@ export abstract class ProjectFilters {
7879
@ValidateNested()
7980
readonly modifiedAt?: DateTimeFilter;
8081

82+
@Field({
83+
nullable: true,
84+
})
85+
@Type(() => DateFilter)
86+
@ValidateNested()
87+
readonly mouStart?: DateFilter;
88+
89+
@Field({
90+
nullable: true,
91+
})
92+
@Type(() => DateFilter)
93+
@ValidateNested()
94+
readonly mouEnd?: DateFilter;
95+
8196
@Field({
8297
nullable: true,
8398
description: 'only mine',

src/components/project/project-filters.query.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export const projectFilters = filter.define(() => ProjectFilters, {
4040
step: filter.stringListProp(),
4141
createdAt: filter.dateTimeBaseNodeProp(),
4242
modifiedAt: filter.dateTimeProp(),
43+
mouStart: filter.dateTimeProp(),
44+
mouEnd: filter.dateTimeProp(),
4345
mine: filter.pathExistsWhenTrue([
4446
node('requestingUser'),
4547
relation('in', '', 'user'),

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)