aboutsummaryrefslogtreecommitdiff
path: root/src/db/model/File.ts
diff options
context:
space:
mode:
authorTom Harley2018-03-01 19:48:47 +0000
committerTom Harley2018-03-01 19:48:47 +0000
commit8bd1d19dbd899047bc8503dbe682358ddfc564cc (patch)
treeda016b8bb301a3f74123aceeee1d1a3427301fd6 /src/db/model/File.ts
parentRevert "Revert "Merge branch 'trh/error-middleware' into 'master'"" (diff)
downloadmedicine-8bd1d19dbd899047bc8503dbe682358ddfc564cc.tar.gz
medicine-8bd1d19dbd899047bc8503dbe682358ddfc564cc.zip

Implement GET and POST request handlers

Diffstat (limited to 'src/db/model/File.ts')
-rw-r--r--src/db/model/File.ts34
1 files changed, 23 insertions, 11 deletions
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<File> {
+ @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;
+ }
}