From 8bd1d19dbd899047bc8503dbe682358ddfc564cc Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Thu, 1 Mar 2018 19:48:47 +0000 Subject: Implement GET and POST request handlers --- src/db/model/File.ts | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'src/db/model/File.ts') diff --git a/src/db/model/File.ts b/src/db/model/File.ts index 225512d..50c8e74 100644 --- a/src/db/model/File.ts +++ b/src/db/model/File.ts @@ -5,43 +5,55 @@ import { default as User } from './User'; @Table export default class File extends Model { + @AllowNull @Column - public name: string = ''; + public name!: string; @PrimaryKey @Column - public uuid: string = ''; + public uuid!: string; @Column - public mimetype: string = ''; + public mimetype!: string; @ForeignKey(() => File) @AllowNull @Column(DataType.TEXT) - public parentFolderId: string | null = null; + public parentFolderId!: string | null; @BelongsTo(() => File) - public parentFolder: File = new File(); + public parentFolder?: File; @HasMany(() => File) - public containedFiles: File[] = []; + public containedFilesInternal?: File[]; @ForeignKey(() => User) @AllowNull @Column(DataType.TEXT) - public creatorName: string | null = null; + public creatorName!: string | null; @BelongsTo(() => User) - public creator: User = new User(); + public creator?: User; @HasOne(() => Project) - public rootFolderOf: Project = new Project(); + public rootFolderOf?: Project; @CreatedAt @Column - public uploadDate: Date = new Date(); + public uploadDate!: Date; @UpdatedAt @Column - public modifyDate: Date = new Date(); + public modifyDate!: Date; + + public get containedFiles(): File[] { + if (this.containedFilesInternal === undefined) { + throw new Error('containedFiles is undefined'); + } + return this.containedFilesInternal; + } + + public set containedFiles(files: File[]) { + this.containedFilesInternal = files; + } } -- cgit v1.2.1