aboutsummaryrefslogtreecommitdiff
path: root/src/db/model/Project.ts
blob: 7128296dd36f6c8fd4e384f85f3dab882f71d8d1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import {Table, Model, Column, PrimaryKey, BelongsToMany,
        ForeignKey, BelongsTo, CreatedAt, 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;

  @BelongsToMany(() => User, () => UserJoinsProject)
  contributors: User[];

  @ForeignKey(() => File)
  @Column
  rootFolderId: string;

  @BelongsTo(() => File)
  rootFolder: File;

  @CreatedAt
  @Column
  creationDate: Date;

  @UpdatedAt
  @Column
  lastActivity: Date;

  getAccessLevel(arg0: any): any {
      return "unimplemented, Will be db query on UserJoinsProject table";
  }

  getUserInfo(user: User): UserInfo {
      return {
          username: user.username,
          access_level: this.getAccessLevel(user)
      }
  }

  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 = {};

type UserInfo = {
    username: string,
    access_level: string
};

type ProjectFullInfo = {
    project_name: string,
    users: UserInfo[],
    public_metadata: metadata,
    private_metadata?: metadata,
    admin_metadata?: metadata
};