Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2709 from SeedCompany/filter-nulls
- Loading branch information
Showing
28 changed files
with
143 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const get = (type: any) => Reflect.getMetadata(key, type) ?? {}; | ||
|
||
const set = | ||
(value: any): PropertyDecorator => | ||
({ constructor: type }, propertyKey) => | ||
Reflect.defineMetadata(key, { ...get(type), [propertyKey]: value }, type); | ||
|
||
/** | ||
* A helper to get/set default values for classes. | ||
* Usage of this is discouraged in favor or more common practices. | ||
* This is mostly useful with abstractions. | ||
* Note that the defaults aren't automatically applied, this just holds | ||
* a container for them - They need to be fetched explicitly. | ||
*/ | ||
export const DefaultValue = { Get: get, Set: set }; | ||
|
||
const key = 'DefaultValue'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { applyDecorators } from '@nestjs/common'; | ||
import { Field } from '@nestjs/graphql'; | ||
import { Transform, Type } from 'class-transformer'; | ||
import { ValidateNested } from 'class-validator'; | ||
import { HasRequiredKeys } from 'type-fest'; | ||
import { DefaultValue } from './default-value'; | ||
import { AbstractClassType } from './types'; | ||
|
||
/** | ||
* A field that is a filter object probably for input on a list query. | ||
*/ | ||
export const FilterField = <T extends object>( | ||
type: HasRequiredKeys<T> extends true ? never : AbstractClassType<T>, | ||
options?: { | ||
/** | ||
* There are no external fields on the filter, so don't expose to GQL. | ||
*/ | ||
internal?: boolean; | ||
} | ||
): PropertyDecorator => | ||
applyDecorators( | ||
...(options?.internal | ||
? [] | ||
: [ | ||
Field(() => type, { | ||
nullable: true, | ||
defaultValue: {}, // Only for GQL schema & not always applied in TS | ||
}), | ||
]), | ||
Type(() => type), | ||
ValidateNested(), | ||
DefaultValue.Set({}), // Default when omitted | ||
Transform(({ value }) => value || {}) // null -> {} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 3 additions & 8 deletions
11
src/components/literacy-material/dto/list-literacy-material.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.