Skip to content

Commit

Permalink
Correctly mark nullability for language properties
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonF committed Nov 15, 2023
1 parent e9007a8 commit 9c800c6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
20 changes: 10 additions & 10 deletions src/components/language/dto/create-language.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ export abstract class CreateEthnologueLanguage {
@IsAlpha()
@IsLowercase()
@ExactLength(3)
readonly code?: string;
readonly code?: string | null;

@NameField({ nullable: true })
@IsAlpha()
@IsLowercase()
@ExactLength(3)
readonly provisionalCode?: string;
readonly provisionalCode?: string | null;

@NameField({ nullable: true })
readonly name?: string;
readonly name?: string | null;

@Field(() => Int, { nullable: true })
@IsPositive()
readonly population?: number;
readonly population?: number | null;
}

@InputType()
Expand All @@ -50,7 +50,7 @@ export abstract class CreateLanguage {
readonly displayName: string;

@NameField({ nullable: true })
readonly displayNamePronunciation?: string;
readonly displayNamePronunciation?: string | null;

@Field({ nullable: true })
readonly isDialect: boolean = false;
Expand All @@ -62,18 +62,18 @@ export abstract class CreateLanguage {

@Field(() => Int, { nullable: true })
@IsPositive()
readonly populationOverride: number;
readonly populationOverride: number | null;

@NameField({ nullable: true })
@ExactLength(5)
@IsNumberString()
readonly registryOfDialectsCode?: string;
readonly registryOfDialectsCode?: string | null;

@Field({ nullable: true })
readonly leastOfThese: boolean = false;

@NameField({ nullable: true })
readonly leastOfTheseReason?: string;
readonly leastOfTheseReason?: string | null;

@Field({ nullable: true })
readonly isSignLanguage?: boolean = false;
Expand All @@ -82,13 +82,13 @@ export abstract class CreateLanguage {
@Matches(/^[A-Z]{2}\d{2}$/, {
message: 'Must be 2 uppercase letters followed by 2 digits',
})
readonly signLanguageCode?: string;
readonly signLanguageCode?: string | null;

@SensitivityField({ nullable: true })
readonly sensitivity?: Sensitivity = Sensitivity.High;

@DateField({ nullable: true })
readonly sponsorEstimatedEndDate?: CalendarDate;
readonly sponsorEstimatedEndDate?: CalendarDate | null;

@Field({ nullable: true })
readonly hasExternalFirstScripture?: boolean = false;
Expand Down
25 changes: 13 additions & 12 deletions src/components/language/dto/language.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import {
Resource,
ResourceRelationsShape,
SecuredBoolean,
SecuredDate,
SecuredInt,
SecuredDateNullable,
SecuredIntNullable,
SecuredProperty,
SecuredPropertyList,
SecuredProps,
SecuredString,
SecuredStringNullable,
Sensitivity,
SensitivityField,
SetUnsecuredType,
Expand Down Expand Up @@ -56,21 +57,21 @@ export class EthnologueLanguage {
@Field({
description: 'ISO 639-3 code',
})
readonly code: SecuredString;
readonly code: SecuredStringNullable;

@Field({
description: stripIndent`
Provisional Ethnologue Code.
Used until official ethnologue code is created by SIL.
`,
})
readonly provisionalCode: SecuredString;
readonly provisionalCode: SecuredStringNullable;

@NameField()
readonly name: SecuredString;
readonly name: SecuredStringNullable;

@Field()
readonly population: SecuredInt;
readonly population: SecuredIntNullable;

@Field()
readonly canDelete: boolean;
Expand Down Expand Up @@ -113,7 +114,7 @@ export class Language extends Interfaces {
@Field({
description: 'The pronunciation of the display name',
})
readonly displayNamePronunciation: SecuredString;
readonly displayNamePronunciation: SecuredStringNullable;

@Field({
description: `Whether this language is a dialect.`,
Expand All @@ -128,7 +129,7 @@ export class Language extends Interfaces {
@Field({
description: `An override for the ethnologue's population`,
})
readonly populationOverride: SecuredInt;
readonly populationOverride: SecuredIntNullable;

@Field({
description: stripIndent`
Expand All @@ -138,7 +139,7 @@ export class Language extends Interfaces {
`,
})
@DbUnique('RegistryOfDialectsCode')
readonly registryOfDialectsCode: SecuredString;
readonly registryOfDialectsCode: SecuredStringNullable;

// consider making object
@Field({
Expand All @@ -149,13 +150,13 @@ export class Language extends Interfaces {
@Field({
description: `Reason why this language is a part of the Least of These program.`,
})
readonly leastOfTheseReason: SecuredString;
readonly leastOfTheseReason: SecuredStringNullable;

@Field()
readonly signLanguageCode: SecuredString;
readonly signLanguageCode: SecuredStringNullable;

@Field()
readonly sponsorEstimatedEndDate: SecuredDate;
readonly sponsorEstimatedEndDate: SecuredDateNullable;

@SensitivityField()
readonly sensitivity: Sensitivity;
Expand Down
20 changes: 10 additions & 10 deletions src/components/language/dto/update-language.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ export abstract class UpdateEthnologueLanguage {
@IsAlpha()
@IsLowercase()
@ExactLength(3)
readonly code?: string;
readonly code?: string | null;

@NameField({ nullable: true })
@IsAlpha()
@IsLowercase()
@ExactLength(3)
readonly provisionalCode?: string;
readonly provisionalCode?: string | null;

@NameField({ nullable: true })
readonly name?: string;
readonly name?: string | null;

@Field(() => Int, { nullable: true })
@IsPositive()
readonly population?: number;
readonly population?: number | null;
}

@InputType()
Expand All @@ -56,7 +56,7 @@ export abstract class UpdateLanguage {
readonly displayName?: string;

@NameField({ nullable: true })
readonly displayNamePronunciation?: string;
readonly displayNamePronunciation?: string | null;

@Field({ nullable: true })
readonly isDialect: boolean = false;
Expand All @@ -68,18 +68,18 @@ export abstract class UpdateLanguage {

@Field(() => Int, { nullable: true })
@IsPositive()
readonly populationOverride: number;
readonly populationOverride: number | null;

@Field({ nullable: true })
@ExactLength(5)
@IsNumberString()
readonly registryOfDialectsCode?: string;
readonly registryOfDialectsCode?: string | null;

@Field({ nullable: true })
readonly leastOfThese: boolean = false;

@NameField({ nullable: true })
readonly leastOfTheseReason?: string;
readonly leastOfTheseReason?: string | null;

@Field({ nullable: true })
readonly isSignLanguage?: boolean;
Expand All @@ -88,13 +88,13 @@ export abstract class UpdateLanguage {
@Matches(/^[A-Z]{2}\d{2}$/, {
message: 'Must be 2 uppercase letters followed by 2 digits',
})
readonly signLanguageCode?: string;
readonly signLanguageCode?: string | null;

@SensitivityField({ nullable: true })
readonly sensitivity?: Sensitivity;

@DateField({ nullable: true })
readonly sponsorEstimatedEndDate?: CalendarDate;
readonly sponsorEstimatedEndDate?: CalendarDate | null;

@Field({ nullable: true })
readonly hasExternalFirstScripture?: boolean;
Expand Down
6 changes: 3 additions & 3 deletions src/components/language/language.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
ListArg,
LoggedInSession,
SecuredDate,
SecuredInt,
SecuredIntNullable,
Session,
viewOfChangeset,
} from '../../common';
Expand Down Expand Up @@ -71,14 +71,14 @@ export class LanguageResolver {
: undefined;
}

@ResolveField(() => SecuredInt, {
@ResolveField(() => SecuredIntNullable, {
description: stripIndent`
The language's population.
This is either the \`populationOverride\` if defined
or the ethnologue population as a fallback.
`,
})
population(@Parent() language: Language): SecuredInt {
population(@Parent() language: Language): SecuredIntNullable {
// Only check this prop so we don't return different numbers based on
// authorization. This seems the most sane, but could double check with business.
const { canRead, value } = language.populationOverride;
Expand Down

0 comments on commit 9c800c6

Please sign in to comment.