Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly mark nullability for language properties #2963

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 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,33 +62,33 @@ 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;

@Field({ nullable: true })
@NameField({ nullable: true })
@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
24 changes: 12 additions & 12 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,33 +68,33 @@ export abstract class UpdateLanguage {

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

@Field({ nullable: true })
@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;

@Field({ nullable: true })
@NameField({ nullable: true })
@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
Loading