Skip to content

Commit 0d268ca

Browse files
authored
Merge pull request #3246 from SeedCompany/filters-optional
2 parents b37106e + eb12253 commit 0d268ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+57
-53
lines changed

src/common/filter-field.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { applyDecorators } from '@nestjs/common';
22
import { Field } from '@nestjs/graphql';
3-
import { Transform, Type } from 'class-transformer';
3+
import { Type } from 'class-transformer';
44
import { ValidateNested } from 'class-validator';
55
import { Constructor, HasRequiredKeys } from 'type-fest';
6-
import { DefaultValue } from './default-value';
76
import { AbstractClassType } from './types';
87

98
/**
@@ -24,11 +23,8 @@ export const FilterField = <T extends object>(
2423
: [
2524
Field(type as unknown as () => Constructor<T>, {
2625
nullable: true,
27-
defaultValue: {} as unknown as T, // Only for GQL schema & not always applied in TS
2826
}),
2927
]),
3028
Type(type),
3129
ValidateNested(),
32-
DefaultValue.Set({}), // Default when omitted
33-
Transform(({ value }) => value || {}), // null -> {}
3430
);

src/common/pagination.input.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { setHas } from '@seedcompany/common';
44
import { Matches, Max, Min } from 'class-validator';
55
import { stripIndent } from 'common-tags';
66
import { DataObject } from './data-object';
7-
import { DefaultValue } from './default-value';
87
import { Order } from './order.enum';
98
import { AbstractClassType } from './types';
109

@@ -126,7 +125,7 @@ export const ListArg = <T extends PaginationInput>(
126125
name: 'input',
127126
type: () => input,
128127
nullable: true,
129-
defaultValue: DataObject.defaultValue(input, DefaultValue.Get(input)),
128+
defaultValue: DataObject.defaultValue(input),
130129
...opts,
131130
},
132131
...pipes,

src/components/budget/budget-record.repository.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Injectable } from '@nestjs/common';
22
import { node, Query, relation } from 'cypher-query-builder';
3+
import { pickBy } from 'lodash';
34
import {
45
ID,
56
labelForView,
@@ -131,10 +132,14 @@ export class BudgetRecordRepository extends DtoRepository<
131132
session: Session,
132133
view?: ObjectView,
133134
) {
134-
const { budgetId } = input.filter;
135+
const { budgetId } = input.filter ?? {};
135136
const result = await this.db
136137
.query()
137-
.matchNode('budget', labelForView('Budget', view), { id: budgetId })
138+
.matchNode(
139+
'budget',
140+
labelForView('Budget', view),
141+
pickBy({ id: budgetId }),
142+
)
138143
.apply(this.recordsOfBudget({ view }))
139144
.apply(sorting(BudgetRecord, input))
140145
.apply(paginate(input))

src/components/budget/budget.repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class BudgetRepository extends DtoRepository<
108108
.match([
109109
node('node', 'Budget'),
110110
relation('in', '', 'budget', ACTIVE),
111-
node('project', 'Project', pickBy({ id: filter.projectId })),
111+
node('project', 'Project', pickBy({ id: filter?.projectId })),
112112
])
113113
.match(requestingUser(session))
114114
.apply(
@@ -126,7 +126,7 @@ export class BudgetRepository extends DtoRepository<
126126
const result = await this.db
127127
.query()
128128
.match([
129-
...(filter.projectId
129+
...(filter?.projectId
130130
? [
131131
node('node', 'Budget'),
132132
relation('in', '', 'budget', ACTIVE),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class BudgetListInput extends SortablePaginationInput<keyof Budget>({
2121
defaultSort: 'status',
2222
}) {
2323
@FilterField(() => BudgetFilters, { internal: true })
24-
readonly filter: BudgetFilters;
24+
readonly filter?: BudgetFilters;
2525
}
2626

2727
@ObjectType()
@@ -45,7 +45,7 @@ export class BudgetRecordListInput extends SortablePaginationInput<
4545
}) {
4646
@Type(() => BudgetRecordFilters)
4747
@ValidateNested()
48-
readonly filter: BudgetRecordFilters;
48+
readonly filter?: BudgetRecordFilters;
4949
}
5050

5151
@ObjectType()

src/components/ceremony/ceremony.repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class CeremonyRepository extends DtoRepository<
7272
node('', 'Engagement'),
7373
relation('in', '', 'engagement', ACTIVE),
7474
node('project', 'Project'),
75-
...(filter.type
75+
...(filter?.type
7676
? [
7777
relation('out', '', 'type', ACTIVE),
7878
node('name', 'Property', { value: filter.type }),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class CeremonyListInput extends SortablePaginationInput<
1919
defaultSort: 'projectName',
2020
}) {
2121
@FilterField(() => CeremonyFilters)
22-
readonly filter: CeremonyFilters;
22+
readonly filter?: CeremonyFilters;
2323
}
2424

2525
@ObjectType()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class EngagementListInput extends SortablePaginationInput<
3535
defaultSort: 'createdAt',
3636
}) {
3737
@FilterField(() => EngagementFilters)
38-
readonly filter: EngagementFilters;
38+
readonly filter?: EngagementFilters;
3939
}
4040

4141
@ObjectType()

src/components/engagement/engagement.repository.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ export class EngagementRepository extends CommonRepository {
336336

337337
async list(input: EngagementListInput, session: Session, changeset?: ID) {
338338
const label =
339-
simpleSwitch(input.filter.type, {
339+
simpleSwitch(input.filter?.type, {
340340
language: 'LanguageEngagement',
341341
internship: 'InternshipEngagement',
342342
}) ?? 'Engagement';
@@ -346,14 +346,14 @@ export class EngagementRepository extends CommonRepository {
346346
.subQuery((sub) =>
347347
sub
348348
.match([
349-
node('project', 'Project', pickBy({ id: input.filter.projectId })),
349+
node('project', 'Project', pickBy({ id: input.filter?.projectId })),
350350
relation('out', '', 'engagement', ACTIVE),
351351
node('node', label),
352352
])
353353
.apply(whereNotDeletedInChangeset(changeset))
354354
.return(['node', 'project'])
355355
.apply((q) =>
356-
changeset && input.filter.projectId
356+
changeset && input.filter?.projectId
357357
? q
358358
.union()
359359
.match([
@@ -369,7 +369,7 @@ export class EngagementRepository extends CommonRepository {
369369
)
370370
.match(requestingUser(session))
371371
.apply(
372-
filter.builder(input.filter, {
372+
filter.builder(input.filter ?? {}, {
373373
type: filter.skip,
374374
projectId: filter.skip,
375375
partnerId: filter.pathExists((id) => [

src/components/ethno-art/dto/list-ethno-art.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class EthnoArtListInput extends SortablePaginationInput<keyof EthnoArt>({
1010
defaultSort: 'name',
1111
}) {
1212
@FilterField(() => EthnoArtFilters, { internal: true })
13-
readonly filter: EthnoArtFilters;
13+
readonly filter?: EthnoArtFilters;
1414
}
1515

1616
@ObjectType()

0 commit comments

Comments
 (0)