aboutsummaryrefslogtreecommitdiff
path: root/src/db/model/File.ts
diff options
context:
space:
mode:
authorcjd242018-04-19 20:48:19 +0100
committercjd242018-04-19 20:48:19 +0100
commit92e23d37f843e49eda01a4d0ea7ed8005efffdb2 (patch)
tree7c08678dfce9bf82eaa4f71f5e23182f8515d386 /src/db/model/File.ts
parentAdded a write of the base teir JSON object, made the images actually write to... (diff)
parentMerge branch 'trh/gets' into cjd24/conversion (diff)
downloadmedicine-92e23d37f843e49eda01a4d0ea7ed8005efffdb2.tar.gz
medicine-92e23d37f843e49eda01a4d0ea7ed8005efffdb2.zip

Merge branch ‘cjd24/conversion’ of https://gitlab.cs.st-andrews.ac.uk/cs3099group-be-4/project-code into cjd24/conversion

Diffstat (limited to 'src/db/model/File.ts')
-rw-r--r--src/db/model/File.ts76
1 files changed, 74 insertions, 2 deletions
diff --git a/src/db/model/File.ts b/src/db/model/File.ts
index 33043f0..8a12431 100644
--- a/src/db/model/File.ts
+++ b/src/db/model/File.ts
@@ -3,18 +3,45 @@ 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';
+
+/*
+ * attributes:
+ * - nameInternal
+ * - fullPathInternal
+ * - uuid
+ * - type
+ * - size
+ * - parentFolderId
+ * - containedFilesInternal
+ * - creatorName
+ * - creator
+ * - rootFolderOf
+ * - uploadDate
+ * - modifyDate
+ * - status
+ * - metadataInternal
+*/
+
@Table
export default class File extends Model<File> {
@AllowNull
@Column
- public name!: string;
+ public 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 +73,39 @@ 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;
+ if (this.fullPathInternal) {
+ this.fullPathInternal = this.fullPathInternal.substring(
+ 0,
+ this.fullPathInternal.lastIndexOf('/') + 1
+ ) + this.name;
+ } else {
+ this.fullPathInternal = 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 +116,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';
+ }
}