aboutsummaryrefslogtreecommitdiff
path: root/src/db/model/File.ts
diff options
context:
space:
mode:
authorTom Harley2018-04-10 18:18:12 +0100
committerTom Harley2018-04-10 18:18:12 +0100
commit3a95396b773c3bfb5f8a407e256f98d926297002 (patch)
treeabdfe5d29a63b14c7338bf87e6c79a2c14880c10 /src/db/model/File.ts
parentAddress numerous errors in test suites (diff)
downloadmedicine-3a95396b773c3bfb5f8a407e256f98d926297002.tar.gz
medicine-3a95396b773c3bfb5f8a407e256f98d926297002.zip

WIP: Add support for raw and meta views

Diffstat (limited to 'src/db/model/File.ts')
-rw-r--r--src/db/model/File.ts54
1 files changed, 52 insertions, 2 deletions
diff --git a/src/db/model/File.ts b/src/db/model/File.ts
index 33043f0..4026b85 100644
--- a/src/db/model/File.ts
+++ b/src/db/model/File.ts
@@ -3,18 +3,27 @@ import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, HasMany,
HasOne, Model, PrimaryKey, Table, UpdatedAt } from 'sequelize-typescript';
import { default as User } from './User';
+import { FileTypeName, mimes } from '../../files';
+
@Table
export default class File extends Model<File> {
@AllowNull
@Column
- public name!: string;
+ private nameInternal!: string;
+
+ @AllowNull
+ @Column
+ private fullPathInternal!: string;
@PrimaryKey
@Column
public uuid!: string;
+ @Column(DataType.TEXT)
+ public type!: FileTypeName;
+
@Column
- public mimetype!: string;
+ public size!: number;
@ForeignKey(() => File)
@AllowNull
@@ -46,6 +55,35 @@ export default class File extends Model<File> {
@Column(DataType.DATE)
public modifyDate!: Date;
+ @Column
+ public status!: string;
+
+ @Column
+ private metadataInternal!: string;
+
+ public get name(): string {
+ return this.nameInternal;
+ }
+
+ public set name(name: string) {
+ this.nameInternal = name;
+ this.fullPathInternal = this.fullPathInternal.substring(
+ 0,
+ this.fullPathInternal.lastIndexOf('/') + 1
+ ) + this.name;
+ }
+
+ public get fullPath(): string {
+ return this.fullPathInternal;
+ }
+
+ public set fullPath(path: string) {
+ this.fullPathInternal = path;
+ this.nameInternal = this.fullPath.substring(
+ this.fullPathInternal.lastIndexOf('/') + 1
+ );
+ }
+
public get containedFiles(): File[] {
if (this.containedFilesInternal === undefined) {
throw new Error('containedFiles is undefined');
@@ -56,4 +94,16 @@ export default class File extends Model<File> {
public set containedFiles(files: File[]) {
this.containedFilesInternal = files;
}
+
+ public get metadata(): object {
+ return JSON.parse(this.metadataInternal);
+ }
+
+ public set metadata(metadata: object) {
+ this.metadataInternal = JSON.stringify(metadata);
+ }
+
+ public set mimetype(mime: string) {
+ this.type = mimes.get(mime) || 'generic';
+ }
}