Skip to content

Commit 906f47d

Browse files
committed
Update Filters shapes to handle nulls & empty lists correctly
1 parent dc04f2a commit 906f47d

File tree

15 files changed

+135
-153
lines changed

15 files changed

+135
-153
lines changed

src/components/ceremony/dto/list-ceremony.dto.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { Field, InputType } from '@nestjs/graphql';
2-
import { FilterField, SortablePaginationInput } from '~/common';
1+
import { InputType } from '@nestjs/graphql';
2+
import { FilterField, OptionalField, SortablePaginationInput } from '~/common';
33
import { CeremonyType } from './ceremony-type.enum';
44
import { Ceremony } from './ceremony.dto';
55

66
@InputType()
77
export abstract class CeremonyFilters {
8-
@Field(() => CeremonyType, {
8+
@OptionalField(() => CeremonyType, {
99
description: 'Only ceremonies of this type',
10-
nullable: true,
1110
})
1211
readonly type?: CeremonyType;
1312
}

src/components/engagement/dto/list-engagements.dto.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { Field, InputType, ObjectType } from '@nestjs/graphql';
1+
import { InputType, ObjectType } from '@nestjs/graphql';
22
import { Type } from 'class-transformer';
33
import { ValidateNested } from 'class-validator';
44
import {
55
DateFilter,
66
FilterField,
77
ID,
8+
ListField,
9+
OptionalField,
810
PaginatedList,
911
SecuredList,
1012
SortablePaginationInput,
@@ -26,30 +28,28 @@ import { EngagementStatus } from './status.enum';
2628

2729
@InputType()
2830
export abstract class EngagementFilters {
29-
@Field({
31+
@OptionalField({
3032
description: 'Only engagements matching this type',
31-
nullable: true,
3233
})
3334
readonly type?: 'language' | 'internship';
3435

35-
@Field({
36-
nullable: true,
36+
@OptionalField({
3737
description:
3838
'Only engagements whose project or engaged entity (language / user) name match',
3939
})
4040
readonly name?: string;
4141

42-
@Field(() => [EngagementStatus], {
43-
nullable: true,
42+
@ListField(() => EngagementStatus, {
43+
optional: true,
44+
empty: 'omit',
4445
})
4546
readonly status?: readonly EngagementStatus[];
4647

4748
readonly projectId?: ID;
4849
@FilterField(() => ProjectFilters)
4950
readonly project?: ProjectFilters & {};
5051

51-
@Field({
52-
nullable: true,
52+
@OptionalField({
5353
description:
5454
'Only engagements whose engaged entity (language / user) name match',
5555
})
@@ -64,26 +64,26 @@ export abstract class EngagementFilters {
6464

6565
readonly partnerId?: ID<'Partner'>;
6666

67-
@Field({
68-
nullable: true,
69-
})
67+
@OptionalField()
7068
@Type(() => DateFilter)
7169
@ValidateNested()
7270
readonly startDate?: DateFilter;
7371

74-
@Field({
75-
nullable: true,
76-
})
72+
@OptionalField()
7773
@Type(() => DateFilter)
7874
@ValidateNested()
7975
readonly endDate?: DateFilter;
8076

81-
@Field(() => [LanguageMilestone], {
82-
nullable: true,
77+
@ListField(() => LanguageMilestone, {
78+
optional: true,
79+
empty: 'omit',
8380
})
8481
readonly milestoneReached?: readonly LanguageMilestone[];
8582

86-
@Field(() => [AIAssistedTranslation], { nullable: true })
83+
@ListField(() => AIAssistedTranslation, {
84+
optional: true,
85+
empty: 'omit',
86+
})
8787
readonly usingAIAssistedTranslation?: readonly AIAssistedTranslation[];
8888
}
8989

src/components/file/dto/list.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
import { Field, InputType, ObjectType } from '@nestjs/graphql';
2-
import { FilterField, PaginatedList, SortablePaginationInput } from '~/common';
1+
import { InputType, ObjectType } from '@nestjs/graphql';
2+
import {
3+
FilterField,
4+
OptionalField,
5+
PaginatedList,
6+
SortablePaginationInput,
7+
} from '~/common';
38
import { FileNodeType } from './file-node-type.enum';
49
import { Directory, File, FileNode, IFileNode } from './node';
510

611
@InputType()
712
export abstract class FileFilters {
8-
@Field({
13+
@OptionalField({
914
description: 'Only file nodes matching this name',
10-
nullable: true,
1115
})
1216
readonly name?: string;
1317

14-
@Field(() => FileNodeType, {
18+
@OptionalField(() => FileNodeType, {
1519
description: 'Only file nodes matching this type',
16-
nullable: true,
1720
})
1821
readonly type?: FileNodeType;
1922
}

src/components/language/dto/list-language.dto.ts

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Field, InputType, ObjectType } from '@nestjs/graphql';
1+
import { InputType, ObjectType } from '@nestjs/graphql';
22
import {
33
FilterField,
44
ID,
5+
OptionalField,
56
PaginatedList,
67
SecuredList,
78
SensitivitiesFilterField,
@@ -12,68 +13,52 @@ import { Language } from './language.dto';
1213

1314
@InputType()
1415
export abstract class EthnologueLanguageFilters {
15-
@Field({
16-
nullable: true,
17-
})
16+
@OptionalField()
1817
readonly code?: string;
1918

20-
@Field({
21-
nullable: true,
22-
})
19+
@OptionalField()
2320
readonly provisionalCode?: string;
2421

25-
@Field({
26-
nullable: true,
27-
})
22+
@OptionalField()
2823
readonly name?: string;
2924
}
3025

3126
@InputType()
3227
export abstract class LanguageFilters {
33-
@Field({
34-
nullable: true,
35-
})
28+
@OptionalField()
3629
readonly name?: string;
3730

3831
@SensitivitiesFilterField()
3932
readonly sensitivity?: Sensitivity[];
4033

41-
@Field({
42-
nullable: true,
34+
@OptionalField({
4335
description: 'Is a Least Of These partnership',
4436
})
4537
readonly leastOfThese?: boolean;
4638

47-
@Field({
48-
nullable: true,
49-
})
39+
@OptionalField()
5040
readonly isDialect?: boolean;
5141

52-
@Field({
53-
nullable: true,
54-
})
42+
@OptionalField()
5543
readonly isSignLanguage?: boolean;
5644

57-
@Field({
58-
nullable: true,
45+
@OptionalField({
5946
description: 'Only languages that are (not) in the "Preset Inventory"',
6047
})
6148
readonly presetInventory?: boolean;
6249

63-
@Field({
50+
@OptionalField({
6451
description:
6552
'Only languages that are pinned/unpinned by the requesting user',
66-
nullable: true,
6753
})
6854
readonly pinned?: boolean;
6955

70-
@Field({
71-
nullable: true,
56+
@OptionalField({
7257
deprecationReason: 'Use `registryOfLanguageVarietiesCode` instead',
7358
})
7459
readonly registryOfDialectsCode?: string;
7560

76-
@Field({ nullable: true })
61+
@OptionalField()
7762
readonly registryOfLanguageVarietiesCode?: string;
7863

7964
readonly partnerId?: ID;

src/components/location/dto/list-locations.dto.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Field, InputType, ObjectType } from '@nestjs/graphql';
1+
import { InputType, ObjectType } from '@nestjs/graphql';
22
import {
33
FilterField,
44
ID,
5+
OptionalField,
56
PaginatedList,
67
SecuredList,
78
SortablePaginationInput,
@@ -10,9 +11,7 @@ import { Location } from './location.dto';
1011

1112
@InputType()
1213
export abstract class LocationFilters {
13-
@Field({
14-
nullable: true,
15-
})
14+
@OptionalField()
1615
readonly name?: string;
1716

1817
readonly fundingAccountId?: ID;

src/components/notifications/dto/notification-list.input.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { Field, InputType, Int, ObjectType } from '@nestjs/graphql';
2-
import { FilterField, PaginatedList, PaginationInput } from '~/common';
2+
import {
3+
FilterField,
4+
OptionalField,
5+
PaginatedList,
6+
PaginationInput,
7+
} from '~/common';
38
import { Notification } from './notification.dto';
49

510
@InputType()
611
export abstract class NotificationFilters {
7-
@Field(() => Boolean, {
12+
@OptionalField(() => Boolean, {
813
description: 'Only read/unread notifications',
9-
nullable: true,
1014
})
1115
readonly unread?: boolean;
1216
}

src/components/organization/dto/list-organization.dto.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Field, InputType, ObjectType } from '@nestjs/graphql';
1+
import { InputType, ObjectType } from '@nestjs/graphql';
22
import {
33
FilterField,
44
ID,
5+
OptionalField,
56
PaginatedList,
67
SecuredList,
78
SortablePaginationInput,
@@ -10,9 +11,7 @@ import { Organization } from './organization.dto';
1011

1112
@InputType()
1213
export abstract class OrganizationFilters {
13-
@Field({
14-
nullable: true,
15-
})
14+
@OptionalField()
1615
readonly name?: string;
1716

1817
readonly userId?: ID;

src/components/partner/dto/list-partner.dto.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { Field, InputType, ObjectType } from '@nestjs/graphql';
1+
import { InputType, ObjectType } from '@nestjs/graphql';
22
import { Type } from 'class-transformer';
33
import { ValidateNested } from 'class-validator';
44
import {
55
DateFilter,
66
DateTimeFilter,
77
FilterField,
88
ID,
9+
ListField,
10+
OptionalField,
911
PaginatedList,
1012
SecuredList,
1113
SortablePaginationInput,
@@ -19,41 +21,36 @@ import { Partner } from './partner.dto';
1921
export abstract class PartnerFilters {
2022
readonly userId?: ID;
2123

22-
@Field({
24+
@OptionalField({
2325
description:
2426
'Only partners that are pinned/unpinned by the requesting user',
25-
nullable: true,
2627
})
2728
readonly pinned?: boolean;
2829

29-
@Field({
30-
nullable: true,
31-
})
30+
@OptionalField()
3231
readonly globalInnovationsClient?: boolean;
3332

3433
@FilterField(() => OrganizationFilters)
3534
readonly organization?: OrganizationFilters & {};
3635

37-
@Field(() => [PartnerType], {
38-
nullable: true,
36+
@ListField(() => PartnerType, {
37+
optional: true,
38+
empty: 'omit',
3939
})
40-
readonly types?: PartnerType[];
40+
readonly types?: readonly PartnerType[];
4141

42-
@Field(() => [FinancialReportingType], {
43-
nullable: true,
42+
@ListField(() => FinancialReportingType, {
43+
optional: true,
44+
empty: 'omit',
4445
})
45-
readonly financialReportingTypes?: FinancialReportingType[];
46+
readonly financialReportingTypes?: readonly FinancialReportingType[];
4647

47-
@Field({
48-
nullable: true,
49-
})
48+
@OptionalField()
5049
@Type(() => DateFilter)
5150
@ValidateNested()
5251
readonly startDate?: DateFilter;
5352

54-
@Field({
55-
nullable: true,
56-
})
53+
@OptionalField()
5754
@Type(() => DateTimeFilter)
5855
@ValidateNested()
5956
readonly createdAt?: DateTimeFilter;

src/components/partnership/dto/list-partnership.dto.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { Field, InputType, ObjectType } from '@nestjs/graphql';
2-
import { Transform } from 'class-transformer';
3-
import { uniq } from 'lodash';
1+
import { InputType, ObjectType } from '@nestjs/graphql';
42
import {
53
FilterField,
64
ID,
5+
ListField,
76
PaginatedList,
87
SecuredList,
98
SortablePaginationInput,
@@ -18,12 +17,12 @@ export abstract class PartnershipFilters {
1817
@FilterField(() => PartnerFilters)
1918
readonly partner?: PartnerFilters & {};
2019

21-
@Field(() => [PartnerType], { nullable: true })
22-
@Transform(({ value }) => {
23-
const types = uniq(value);
24-
return types.length > 0 && types.length < PartnerType.values.size
25-
? types
26-
: undefined;
20+
@ListField(() => PartnerType, {
21+
optional: true,
22+
empty: 'omit',
23+
transform: (value) =>
24+
// If given all options, there is no need to filter
25+
!value || value.length === PartnerType.values.size ? undefined : value,
2726
})
2827
readonly types?: readonly PartnerType[];
2928
}

0 commit comments

Comments
 (0)