From 9c800c6afd148aec3f46c7cd0d345b83b0427ada Mon Sep 17 00:00:00 2001 From: Carson Full Date: Wed, 15 Nov 2023 09:18:08 -0600 Subject: [PATCH] Correctly mark nullability for language properties --- .../language/dto/create-language.dto.ts | 20 +++++++-------- src/components/language/dto/language.dto.ts | 25 ++++++++++--------- .../language/dto/update-language.dto.ts | 20 +++++++-------- src/components/language/language.resolver.ts | 6 ++--- 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/components/language/dto/create-language.dto.ts b/src/components/language/dto/create-language.dto.ts index 4a7658c1b3..91159a9758 100644 --- a/src/components/language/dto/create-language.dto.ts +++ b/src/components/language/dto/create-language.dto.ts @@ -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() @@ -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; @@ -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; @@ -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; diff --git a/src/components/language/dto/language.dto.ts b/src/components/language/dto/language.dto.ts index 6b08db39ef..570c73d151 100644 --- a/src/components/language/dto/language.dto.ts +++ b/src/components/language/dto/language.dto.ts @@ -14,12 +14,13 @@ import { Resource, ResourceRelationsShape, SecuredBoolean, - SecuredDate, - SecuredInt, + SecuredDateNullable, + SecuredIntNullable, SecuredProperty, SecuredPropertyList, SecuredProps, SecuredString, + SecuredStringNullable, Sensitivity, SensitivityField, SetUnsecuredType, @@ -56,7 +57,7 @@ export class EthnologueLanguage { @Field({ description: 'ISO 639-3 code', }) - readonly code: SecuredString; + readonly code: SecuredStringNullable; @Field({ description: stripIndent` @@ -64,13 +65,13 @@ export class EthnologueLanguage { 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; @@ -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.`, @@ -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` @@ -138,7 +139,7 @@ export class Language extends Interfaces { `, }) @DbUnique('RegistryOfDialectsCode') - readonly registryOfDialectsCode: SecuredString; + readonly registryOfDialectsCode: SecuredStringNullable; // consider making object @Field({ @@ -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; diff --git a/src/components/language/dto/update-language.dto.ts b/src/components/language/dto/update-language.dto.ts index 3afc473859..e66ca035bb 100644 --- a/src/components/language/dto/update-language.dto.ts +++ b/src/components/language/dto/update-language.dto.ts @@ -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() @@ -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; @@ -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; @@ -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; diff --git a/src/components/language/language.resolver.ts b/src/components/language/language.resolver.ts index 8e1d9e1597..95be5a7b06 100644 --- a/src/components/language/language.resolver.ts +++ b/src/components/language/language.resolver.ts @@ -17,7 +17,7 @@ import { ListArg, LoggedInSession, SecuredDate, - SecuredInt, + SecuredIntNullable, Session, viewOfChangeset, } from '../../common'; @@ -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;