diff options
Diffstat (limited to 'src/db/model/Project.ts')
| -rw-r--r-- | src/db/model/Project.ts | 111 |
1 files changed, 57 insertions, 54 deletions
diff --git a/src/db/model/Project.ts b/src/db/model/Project.ts index 7128296..2c26a04 100644 --- a/src/db/model/Project.ts +++ b/src/db/model/Project.ts @@ -1,72 +1,75 @@ -import {Table, Model, Column, PrimaryKey, BelongsToMany, - ForeignKey, BelongsTo, CreatedAt, UpdatedAt} from 'sequelize-typescript'; +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'; -import { default as File } from './File'; @Table export default class Project extends Model<Project> { - @PrimaryKey - @Column - name: string; + @PrimaryKey + @Column + public name: string = ''; - @BelongsToMany(() => User, () => UserJoinsProject) - contributors: User[]; + @BelongsToMany(() => User, () => UserJoinsProject) + public contributors: User[] = []; - @ForeignKey(() => File) - @Column - rootFolderId: string; + @ForeignKey(() => File) + @Column + public rootFolderId: string = ''; - @BelongsTo(() => File) - rootFolder: File; + @BelongsTo(() => File) + public rootFolder: File = new File(); - @CreatedAt - @Column - creationDate: Date; + @CreatedAt + @Column + public creationDate: Date = new Date(); - @UpdatedAt - @Column - lastActivity: Date; + @UpdatedAt + @Column + public lastActivity: Date = new Date(); - getAccessLevel(arg0: any): any { - return "unimplemented, Will be db query on UserJoinsProject table"; - } + public getAccessLevel(user: User): ContributorGroup { + throw new Error(`unimplemented, ${this}`); + } - getUserInfo(user: User): UserInfo { - return { - username: user.username, - access_level: this.getAccessLevel(user) - } - } + public getUserInfo(user: User): UserInfo { + return { + username: user.username, + access_level: this.getAccessLevel(user) + .toString() + }; + } - 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: {} - }; - } + 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: {} + }; + } } -type metadata = {}; +interface Metadata {} -type UserInfo = { - username: string, - access_level: string -}; +interface UserInfo { + username: string; + access_level: string; +} -type ProjectFullInfo = { - project_name: string, - users: UserInfo[], - public_metadata: metadata, - private_metadata?: metadata, - admin_metadata?: metadata -}; +export interface ProjectFullInfo { + project_name: string; + users: UserInfo[]; + public_metadata: Metadata; + private_metadata?: Metadata; + admin_metadata?: Metadata; +} |
