Correctly type nullable columns

TypeORM columns with `nullable: true` can be `null` at runtime.
This commit ensures that the types of the corresponding properties reflect that.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2021-04-29 16:54:57 +02:00
parent 16ed12bfd7
commit b93f01fe57
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
6 changed files with 14 additions and 14 deletions

View file

@ -38,12 +38,12 @@ export class AuthToken {
@Column({ @Column({
nullable: true, nullable: true,
}) })
validUntil: Date; validUntil: Date | null;
@Column({ @Column({
nullable: true, nullable: true,
}) })
lastUsed: Date; lastUsed: Date | null;
public static create( public static create(
user: User, user: User,

View file

@ -26,7 +26,7 @@ export class MediaUpload {
@ManyToOne((_) => Note, (note) => note.mediaUploads, { @ManyToOne((_) => Note, (note) => note.mediaUploads, {
nullable: true, nullable: true,
}) })
note: Note; note: Note | null;
@ManyToOne((_) => User, (user) => user.mediaUploads, { @ManyToOne((_) => User, (user) => user.mediaUploads, {
nullable: false, nullable: false,
@ -44,7 +44,7 @@ export class MediaUpload {
@Column({ @Column({
nullable: true, nullable: true,
}) })
backendData: BackendData; backendData: BackendData | null;
@CreateDateColumn() @CreateDateColumn()
createdAt: Date; createdAt: Date;

View file

@ -36,7 +36,7 @@ export class Note {
unique: true, unique: true,
nullable: true, nullable: true,
}) })
alias?: string; alias: string | null;
@OneToMany( @OneToMany(
(_) => NoteGroupPermission, (_) => NoteGroupPermission,
(groupPermission) => groupPermission.note, (groupPermission) => groupPermission.note,
@ -70,11 +70,11 @@ export class Note {
@Column({ @Column({
nullable: true, nullable: true,
}) })
description?: string; description: string | null;
@Column({ @Column({
nullable: true, nullable: true,
}) })
title?: string; title: string | null;
@ManyToMany((_) => Tag, (tag) => tag.notes, { eager: true, cascade: true }) @ManyToMany((_) => Tag, (tag) => tag.notes, { eager: true, cascade: true })
@JoinTable() @JoinTable()

View file

@ -153,7 +153,7 @@ describe('NotesService', () => {
expect(newNote.groupPermissions).toHaveLength(0); expect(newNote.groupPermissions).toHaveLength(0);
expect(newNote.tags).toHaveLength(0); expect(newNote.tags).toHaveLength(0);
expect(newNote.owner).toBeUndefined(); expect(newNote.owner).toBeUndefined();
expect(newNote.alias).toBeUndefined(); expect(newNote.alias).toBeNull();
}); });
it('without alias, with owner', async () => { it('without alias, with owner', async () => {
const newNote = await service.createNote(content, undefined, user); const newNote = await service.createNote(content, undefined, user);
@ -166,7 +166,7 @@ describe('NotesService', () => {
expect(newNote.groupPermissions).toHaveLength(0); expect(newNote.groupPermissions).toHaveLength(0);
expect(newNote.tags).toHaveLength(0); expect(newNote.tags).toHaveLength(0);
expect(newNote.owner).toEqual(user); expect(newNote.owner).toEqual(user);
expect(newNote.alias).toBeUndefined(); expect(newNote.alias).toBeNull();
}); });
it('with alias, without owner', async () => { it('with alias, without owner', async () => {
const newNote = await service.createNote(content, alias); const newNote = await service.createNote(content, alias);

View file

@ -39,15 +39,15 @@ export class Identity {
@Column({ @Column({
nullable: true, nullable: true,
}) })
providerUserId?: string; providerUserId: string | null;
@Column({ @Column({
nullable: true, nullable: true,
}) })
oAuthAccessToken?: string; oAuthAccessToken: string | null;
@Column({ @Column({
nullable: true, nullable: true,
}) })
passwordHash?: string; passwordHash: string | null;
} }

View file

@ -41,12 +41,12 @@ export class User {
@Column({ @Column({
nullable: true, nullable: true,
}) })
photo?: string; photo: string | null;
@Column({ @Column({
nullable: true, nullable: true,
}) })
email?: string; email: string | null;
@OneToMany((_) => Note, (note) => note.owner) @OneToMany((_) => Note, (note) => note.owner)
ownedNotes: Note[]; ownedNotes: Note[];