aboutsummaryrefslogtreecommitdiff
path: root/src/db/model/Project.ts
diff options
context:
space:
mode:
authorTom Harley2018-02-22 18:47:08 +0000
committerTom Harley2018-02-22 18:47:08 +0000
commit5dafe924bbbd5cc09901186ff74e4b68a6dcd52f (patch)
treeff4a76d6eaed5773d89d0da6a02d788ffe210abb /src/db/model/Project.ts
parentMerge branch 'master' into trh/payload-checker (diff)
downloadmedicine-5dafe924bbbd5cc09901186ff74e4b68a6dcd52f.tar.gz
medicine-5dafe924bbbd5cc09901186ff74e4b68a6dcd52f.zip

Revert “Revert”Merge branch ‘trh/error-middleware’ into ‘master’""

This reverts commit 3198c6c2474101623e3b95bd038effe210c176a8.

Diffstat (limited to 'src/db/model/Project.ts')
-rw-r--r--src/db/model/Project.ts75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/db/model/Project.ts b/src/db/model/Project.ts
new file mode 100644
index 0000000..2c26a04
--- /dev/null
+++ b/src/db/model/Project.ts
@@ -0,0 +1,75 @@
+import { default as ContributorGroup } from './ContributorGroup';
+import { default as File } from './File';
+import { BelongsTo, BelongsToMany, Column, CreatedAt, ForeignKey,
+ Model, PrimaryKey, Table, UpdatedAt } from 'sequelize-typescript';
+import { default as User } from './User';
+import { default as UserJoinsProject } from './UserJoinsProject';
+
+@Table
+export default class Project extends Model<Project> {
+
+ @PrimaryKey
+ @Column
+ public name: string = '';
+
+ @BelongsToMany(() => User, () => UserJoinsProject)
+ public contributors: User[] = [];
+
+ @ForeignKey(() => File)
+ @Column
+ public rootFolderId: string = '';
+
+ @BelongsTo(() => File)
+ public rootFolder: File = new File();
+
+ @CreatedAt
+ @Column
+ public creationDate: Date = new Date();
+
+ @UpdatedAt
+ @Column
+ public lastActivity: Date = new Date();
+
+ public getAccessLevel(user: User): ContributorGroup {
+ throw new Error(`unimplemented, ${this}`);
+ }
+
+ public getUserInfo(user: User): UserInfo {
+ return {
+ username: user.username,
+ access_level: this.getAccessLevel(user)
+ .toString()
+ };
+ }
+
+ public getProjectFullInfo(): ProjectFullInfo {
+ return {
+ project_name: this.name,
+ users: this.contributors
+ .map<UserInfo>(
+ (u: User) => this.getUserInfo(u)
+ ),
+ public_metadata: {
+ creation_date: this.creationDate
+ },
+ // TODO: Check if we have anything to use these for yet?
+ private_metadata: {},
+ admin_metadata: {}
+ };
+ }
+}
+
+interface Metadata {}
+
+interface UserInfo {
+ username: string;
+ access_level: string;
+}
+
+export interface ProjectFullInfo {
+ project_name: string;
+ users: UserInfo[];
+ public_metadata: Metadata;
+ private_metadata?: Metadata;
+ admin_metadata?: Metadata;
+}