diff options
| author | jw255 | 2018-04-19 16:35:01 +0100 |
|---|---|---|
| committer | jw255 | 2018-04-19 16:35:01 +0100 |
| commit | 29d4c4ba25828fb26d2d8ce8f3bfb5ecc7da7b57 (patch) | |
| tree | 54f1a49adcad01a8c960e4fe22d97b9b633ef5b9 /src/db | |
| parent | Reverting the ExtractAndStitchChunks to use Bufferbased method instead of VIPS (diff) | |
| parent | Add CORS support (diff) | |
| download | medicine-29d4c4ba25828fb26d2d8ce8f3bfb5ecc7da7b57.tar.gz medicine-29d4c4ba25828fb26d2d8ce8f3bfb5ecc7da7b57.zip | |
Merge branch ‘trh/gets’ into cjd24/conversion
Diffstat (limited to 'src/db')
| -rw-r--r-- | src/db/model/File.ts | 76 | ||||
| -rw-r--r-- | src/db/model/Project.ts | 4 | ||||
| -rw-r--r-- | src/db/model/User.ts | 8 | ||||
| -rw-r--r-- | src/db/model/UserGroup.ts | 3 |
4 files changed, 85 insertions, 6 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'; + } } diff --git a/src/db/model/Project.ts b/src/db/model/Project.ts index d57eaaa..6cda34e 100644 --- a/src/db/model/Project.ts +++ b/src/db/model/Project.ts @@ -36,6 +36,10 @@ export default class Project extends Model<Project> { return this.rootFolderInternal; } + public get properties(): object { + return this; + } + public get metadata(): { public_metadata?: Metadata; private_metadata?: Metadata; diff --git a/src/db/model/User.ts b/src/db/model/User.ts index 171e899..73d2356 100644 --- a/src/db/model/User.ts +++ b/src/db/model/User.ts @@ -128,16 +128,16 @@ export default class User extends Model<User> { public get fullInfo(): UserFullInfo { // FIXME: Fetch these things if they aren't already present if (this.userGroups === undefined) { - throw new Error('userGroups undefined'); + this.userGroups = []; } else if (this.projects === undefined) { - throw new Error('projects undefined'); + this.projects = []; } return { username : this.username, - privileges: this.userGroups + privileges: this.userGroups! .filter((ug: UserGroup): boolean => ug.name !== null) .map((ug: UserGroup): string => ug.name as string), - projects : this.projects.map( + projects : this.projects!.map( (p: Project): ProjectInfo => this.getProjectInfo(p) ), // TODO: Check if we have anything to use these for yet? diff --git a/src/db/model/UserGroup.ts b/src/db/model/UserGroup.ts index 46945de..60d45c8 100644 --- a/src/db/model/UserGroup.ts +++ b/src/db/model/UserGroup.ts @@ -38,6 +38,9 @@ export default class UserGroup extends Model<UserGroup> { public canEditProjects!: boolean; @Column + public canAccessLogs!: boolean; + + @Column public isInternal!: boolean; @AllowNull |
