From b8c066fc6885b68bc6ec3206d4afd02e20783420 Mon Sep 17 00:00:00 2001 From: Vaibhav Ganatra Date: Fri, 31 Jul 2020 20:14:11 +0530 Subject: [PATCH 1/2] Entities, Migrations and Custom Repositories have been initialized for Users, Projects and Github tables --- pmt-auth/src/database/entity/Github.ts | 62 +++++++++++++ pmt-auth/src/database/entity/Project.ts | 45 +++++++++ pmt-auth/src/database/entity/User.ts | 93 +++++++++---------- .../src/database/migration/GithubMigration.ts | 10 ++ .../database/migration/ProjectMigration.ts | 11 +++ pmt-auth/src/database/repositories/Project.ts | 17 ++++ pmt-auth/src/database/repositories/User.ts | 9 ++ pmt-auth/src/interfaces/models/Project.ts | 7 ++ pmt-auth/src/interfaces/models/User.ts | 10 ++ 9 files changed, 214 insertions(+), 50 deletions(-) create mode 100644 pmt-auth/src/database/entity/Github.ts create mode 100644 pmt-auth/src/database/entity/Project.ts create mode 100644 pmt-auth/src/database/migration/GithubMigration.ts create mode 100644 pmt-auth/src/database/migration/ProjectMigration.ts create mode 100644 pmt-auth/src/database/repositories/Project.ts create mode 100644 pmt-auth/src/database/repositories/User.ts create mode 100644 pmt-auth/src/interfaces/models/Project.ts create mode 100644 pmt-auth/src/interfaces/models/User.ts diff --git a/pmt-auth/src/database/entity/Github.ts b/pmt-auth/src/database/entity/Github.ts new file mode 100644 index 0000000..7b032ee --- /dev/null +++ b/pmt-auth/src/database/entity/Github.ts @@ -0,0 +1,62 @@ +import { Entity, PrimaryColumn, Column } from 'typeorm'; + +@Entity() +export class Github { + + @PrimaryColumn('text') + username: string | undefined; + + @Column('text') + login: string | undefined; + + @Column('text') + avatar_url: string | undefined; + + @Column('text') + html_url: string | undefined; + + @Column('text') + repos_url: string | undefined; + + @Column('text') + name: string | undefined; + + @Column('text') + company: string | undefined; + + @Column('text') + blog: string | undefined; + + @Column('text') + location: string | undefined; + + @Column('text') + email: string | undefined; + + @Column('text') + bio: string | undefined; + + @Column('text') + twitter_username: string | undefined; + + @Column('int') + public_repos: number | undefined; + + @Column('int') + public_gists: number | undefined; + + @Column('int') + followers: number | undefined; + + @Column('int') + following: number | undefined; + + @Column('int') + private_gists: number | undefined; + + @Column('int') + total_private_repos: number | undefined; + + @Column('int') + owned_private_repos: number | undefined; +} diff --git a/pmt-auth/src/database/entity/Project.ts b/pmt-auth/src/database/entity/Project.ts new file mode 100644 index 0000000..9f9635d --- /dev/null +++ b/pmt-auth/src/database/entity/Project.ts @@ -0,0 +1,45 @@ +import { + Entity, + PrimaryGeneratedColumn, + Column, + JoinColumn, + ManyToOne, + CreateDateColumn, + UpdateDateColumn, + Timestamp +} from 'typeorm'; +import { Users } from './User'; + +@Entity({name: 'projects'}) +export class Project { + @PrimaryGeneratedColumn() + id: number | undefined; + + @Column({ + type: 'varchar', + unique: true + }) + name: string | undefined; + + @Column('text') + description: string | undefined; + + @Column('int') + chat_channel_id: number | undefined; + + @Column({ + type: 'int', + unique: true + }) + created_by_id: number | undefined; + + @ManyToOne((type) => Users) + @JoinColumn() + created_by: Users | undefined; + + @CreateDateColumn() + created_time: Timestamp | undefined; + + @UpdateDateColumn() + updated_time: Timestamp | undefined; +} diff --git a/pmt-auth/src/database/entity/User.ts b/pmt-auth/src/database/entity/User.ts index 2dacee6..cc20e9b 100644 --- a/pmt-auth/src/database/entity/User.ts +++ b/pmt-auth/src/database/entity/User.ts @@ -1,62 +1,55 @@ -import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm'; +import { + Entity, + PrimaryGeneratedColumn, + Column, + JoinColumn, + OneToOne, + CreateDateColumn, + UpdateDateColumn, + Timestamp +} from 'typeorm'; +import { Github } from './Github'; + +export enum UserRole { + COORDI = 'coordi', + CORE = 'core', + CREW = 'crew' +} @Entity() export class Users { + @PrimaryGeneratedColumn() + id: number | undefined; - @PrimaryGeneratedColumn() - id: number | undefined; - - @Column('text') - login: string | undefined; - - @Column('text') - avatar_url: string | undefined; - - @Column('text') - html_url: string | undefined; - - @Column('text') - repos_url: string | undefined; - - @Column('text') - name: string | undefined; - - @Column('text') - company: string | undefined; - - @Column('text') - blog: string | undefined; - - @Column('text') - location: string | undefined; - - @Column('text') - email: string | undefined; - - @Column('text') - bio: string | undefined; - - @Column('text') - twitter_username: string | undefined; + @Column('varchar') + name: string | undefined; - @Column('int') - public_repos: number | undefined; + @Column({ type: 'varchar', unique: true }) + email: string | undefined; - @Column('int') - public_gists: number | undefined; + @Column({ type: 'text', nullable: true }) + avatar_url: string | undefined; - @Column('int') - followers: number | undefined; + @Column({ + type: 'enum', + enum: UserRole, + default: UserRole.CREW + }) + org_role: UserRole | undefined; - @Column('int') - following: number | undefined; + @Column({ + type: 'text', + unique: true + }) + github_username: string | undefined; - @Column('int') - private_gists: number | undefined; + @OneToOne((type) => Github) + @JoinColumn() + github: Github | undefined; - @Column('int') - total_private_repos: number | undefined; + @CreateDateColumn() + created_at: Timestamp | undefined; - @Column('int') - owned_private_repos: number | undefined; + @UpdateDateColumn() + updated_at: Timestamp | undefined; } diff --git a/pmt-auth/src/database/migration/GithubMigration.ts b/pmt-auth/src/database/migration/GithubMigration.ts new file mode 100644 index 0000000..65da8b2 --- /dev/null +++ b/pmt-auth/src/database/migration/GithubMigration.ts @@ -0,0 +1,10 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class GithubMigration implements MigrationInterface { + async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE "github" IF NOT EXISTS`); + } + async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE "github"`); + } +} diff --git a/pmt-auth/src/database/migration/ProjectMigration.ts b/pmt-auth/src/database/migration/ProjectMigration.ts new file mode 100644 index 0000000..816b444 --- /dev/null +++ b/pmt-auth/src/database/migration/ProjectMigration.ts @@ -0,0 +1,11 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class ProjectMigration implements MigrationInterface { + name?: string; + async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE "projects" IF NOT EXISTS`); + } + async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE "projects"`); + } +} diff --git a/pmt-auth/src/database/repositories/Project.ts b/pmt-auth/src/database/repositories/Project.ts new file mode 100644 index 0000000..6334a79 --- /dev/null +++ b/pmt-auth/src/database/repositories/Project.ts @@ -0,0 +1,17 @@ +import { Repository, EntityRepository } from 'typeorm'; +import { Project } from '../entity/Project'; +import { Users } from '../entity/User'; + +@EntityRepository(Project) +export class ProjectRepository extends Repository { + findByName(name: string) { + return this.findOne({ name: name }); + } + findByCreator(user: Users) { + return this.find({ + where: { + created_by: user + } + }); + } +} diff --git a/pmt-auth/src/database/repositories/User.ts b/pmt-auth/src/database/repositories/User.ts new file mode 100644 index 0000000..a4b5911 --- /dev/null +++ b/pmt-auth/src/database/repositories/User.ts @@ -0,0 +1,9 @@ +import { EntityRepository, Repository } from 'typeorm'; +import { Users } from '../entity/User'; + +@EntityRepository(Users) +export class UserRepository extends Repository { + findByEmail(email: string) { + return this.findOne({email: email}); + } +} diff --git a/pmt-auth/src/interfaces/models/Project.ts b/pmt-auth/src/interfaces/models/Project.ts new file mode 100644 index 0000000..62d7d1a --- /dev/null +++ b/pmt-auth/src/interfaces/models/Project.ts @@ -0,0 +1,7 @@ +export interface Project { + id: number; + name: string; + description: string; + chat_channel_id: number; + created_by_id: number; +} diff --git a/pmt-auth/src/interfaces/models/User.ts b/pmt-auth/src/interfaces/models/User.ts new file mode 100644 index 0000000..7a48935 --- /dev/null +++ b/pmt-auth/src/interfaces/models/User.ts @@ -0,0 +1,10 @@ +import { UserRole } from '../../database/entity/User'; + +export interface User { + id: number; + name: string; + email: string; + avatar_url: string; + org_roles: UserRole; + github_username: string; +} From 5992f00c4c2ec677ffedd5fcf4320b72246a57d5 Mon Sep 17 00:00:00 2001 From: Vaibhav Ganatra Date: Sat, 1 Aug 2020 03:11:54 +0530 Subject: [PATCH 2/2] Completed Repositories, Interfaces, Entities and Migrations for all tables except Permissions and Roles --- pmt-auth/src/database/entity/Card.ts | 69 +++++++++++++++++++ pmt-auth/src/database/entity/Github.ts | 2 +- pmt-auth/src/database/entity/Project.ts | 13 +++- pmt-auth/src/database/entity/Taskboard.ts | 56 +++++++++++++++ pmt-auth/src/database/entity/User.ts | 25 ++++++- .../src/database/migration/CardMigration.ts | 11 +++ .../src/database/migration/GithubMigration.ts | 1 + .../database/migration/TaskboardMigration.ts | 11 +++ pmt-auth/src/database/repositories/Card.ts | 32 +++++++++ pmt-auth/src/database/repositories/Project.ts | 48 ++++++++++++- .../src/database/repositories/Taskboard.ts | 40 +++++++++++ pmt-auth/src/database/repositories/User.ts | 43 +++++++++++- pmt-auth/src/interfaces/models/Card.ts | 16 +++++ pmt-auth/src/interfaces/models/Project.ts | 6 ++ pmt-auth/src/interfaces/models/Taskboard.ts | 15 ++++ pmt-auth/src/interfaces/models/User.ts | 8 ++- 16 files changed, 387 insertions(+), 9 deletions(-) create mode 100644 pmt-auth/src/database/entity/Card.ts create mode 100644 pmt-auth/src/database/entity/Taskboard.ts create mode 100644 pmt-auth/src/database/migration/CardMigration.ts create mode 100644 pmt-auth/src/database/migration/TaskboardMigration.ts create mode 100644 pmt-auth/src/database/repositories/Card.ts create mode 100644 pmt-auth/src/database/repositories/Taskboard.ts create mode 100644 pmt-auth/src/interfaces/models/Card.ts create mode 100644 pmt-auth/src/interfaces/models/Taskboard.ts diff --git a/pmt-auth/src/database/entity/Card.ts b/pmt-auth/src/database/entity/Card.ts new file mode 100644 index 0000000..cfe3afc --- /dev/null +++ b/pmt-auth/src/database/entity/Card.ts @@ -0,0 +1,69 @@ +import { + Entity, + Column, + PrimaryGeneratedColumn, + CreateDateColumn, + UpdateDateColumn, + Timestamp, + ManyToOne, + JoinColumn, + ManyToMany, + JoinTable +} from 'typeorm'; + +import { Taskboard } from './Taskboard'; +import { Users } from './User'; + +export enum CardStatus { + ONGOING = 'ongoing', + TODO = 'todo', + COMPLETED = 'completed' +} + +@Entity({name: 'cards'}) +export class Card { + @PrimaryGeneratedColumn() + id: number | undefined; + + @Column('text') + title: string | undefined; + + @Column('text') + description: string | undefined; + + @CreateDateColumn() + created_at: Timestamp | undefined; + + @UpdateDateColumn() + updated_at: Timestamp | undefined; + + @ManyToOne((type) => Taskboard, board => board.cards) + board: Taskboard | undefined; + + @ManyToOne((type) => Users) + @JoinColumn() + created_by: Users | undefined; + + @Column('text', { array: true, nullable: true }) + labels: string[] | undefined; + + @Column({ + type: 'enum', + enum: CardStatus, + default: CardStatus.TODO + }) + card_status: CardStatus | undefined; + + @ManyToMany(type => Users, user => user.cards) + @JoinTable() + members: Users[] | undefined; + + @Column({ + type: 'timestamp', + nullable: true + }) + completed_at: Timestamp | undefined; + + @Column('timestamp') + deadline: Timestamp | undefined; +} diff --git a/pmt-auth/src/database/entity/Github.ts b/pmt-auth/src/database/entity/Github.ts index 7b032ee..577fee4 100644 --- a/pmt-auth/src/database/entity/Github.ts +++ b/pmt-auth/src/database/entity/Github.ts @@ -1,6 +1,6 @@ import { Entity, PrimaryColumn, Column } from 'typeorm'; -@Entity() +@Entity({ name: 'github'}) export class Github { @PrimaryColumn('text') diff --git a/pmt-auth/src/database/entity/Project.ts b/pmt-auth/src/database/entity/Project.ts index 9f9635d..f99f117 100644 --- a/pmt-auth/src/database/entity/Project.ts +++ b/pmt-auth/src/database/entity/Project.ts @@ -6,9 +6,13 @@ import { ManyToOne, CreateDateColumn, UpdateDateColumn, - Timestamp + Timestamp, + OneToMany, + ManyToMany, + JoinTable } from 'typeorm'; import { Users } from './User'; +import { Taskboard } from './Taskboard'; @Entity({name: 'projects'}) export class Project { @@ -37,9 +41,16 @@ export class Project { @JoinColumn() created_by: Users | undefined; + @OneToMany((type) => Taskboard, taskboard => taskboard.project) + boards: Taskboard[] | undefined; + @CreateDateColumn() created_time: Timestamp | undefined; @UpdateDateColumn() updated_time: Timestamp | undefined; + + @ManyToMany((type) => Users, user => user.projects) + @JoinTable() + members: Users[] | undefined; } diff --git a/pmt-auth/src/database/entity/Taskboard.ts b/pmt-auth/src/database/entity/Taskboard.ts new file mode 100644 index 0000000..3a0e056 --- /dev/null +++ b/pmt-auth/src/database/entity/Taskboard.ts @@ -0,0 +1,56 @@ +import { + Entity, + PrimaryGeneratedColumn, + Column, + UpdateDateColumn, + CreateDateColumn, + Timestamp, + ManyToOne, + JoinColumn, + ManyToMany, + JoinTable, + OneToMany +} from 'typeorm'; + +import { Project } from './Project'; +import { Users } from './User'; +import { Card } from './Card'; + +@Entity({ name: 'taskboards'}) +export class Taskboard { + @PrimaryGeneratedColumn() + id: number | undefined; + + @Column('varchar') + name: string | undefined; + + @Column('text') + description: string | undefined; + + @Column('text') + github_repo_url: string | undefined; + + @CreateDateColumn() + created_at: Timestamp | undefined; + + @UpdateDateColumn() + updated_at: Timestamp | undefined; + + @Column('int') + chat_channel_id: number | undefined; + + @ManyToOne((type) => Project, project => project.boards) + project: Project | undefined; + + @ManyToOne((type) => Users) + @JoinColumn() + created_by: Users | undefined; + + @ManyToMany(type => Users, user => user.boards) + @JoinTable() + members: Users[] | undefined; + + @OneToMany(type => Card, card => card.board) + cards: Card[] | undefined; + +} diff --git a/pmt-auth/src/database/entity/User.ts b/pmt-auth/src/database/entity/User.ts index cc20e9b..a5e14a9 100644 --- a/pmt-auth/src/database/entity/User.ts +++ b/pmt-auth/src/database/entity/User.ts @@ -3,12 +3,17 @@ import { PrimaryGeneratedColumn, Column, JoinColumn, + JoinTable, OneToOne, CreateDateColumn, UpdateDateColumn, - Timestamp + Timestamp, + ManyToMany } from 'typeorm'; import { Github } from './Github'; +import { Project } from './Project'; +import { Taskboard } from './Taskboard'; +import { Card } from './Card'; export enum UserRole { COORDI = 'coordi', @@ -16,7 +21,7 @@ export enum UserRole { CREW = 'crew' } -@Entity() +@Entity({name: 'users'}) export class Users { @PrimaryGeneratedColumn() id: number | undefined; @@ -52,4 +57,20 @@ export class Users { @UpdateDateColumn() updated_at: Timestamp | undefined; + + @ManyToMany((type) => Project, project => project.members, { + cascade: true + }) + projects: Project[] | undefined; + + @ManyToMany(type => Taskboard, board => board.members, { + cascade: true + }) + boards: Taskboard[] | undefined; + + @ManyToMany(type => Card, card => card.members, { + cascade: true + }) + cards: Card[] | undefined; + } diff --git a/pmt-auth/src/database/migration/CardMigration.ts b/pmt-auth/src/database/migration/CardMigration.ts new file mode 100644 index 0000000..7abf304 --- /dev/null +++ b/pmt-auth/src/database/migration/CardMigration.ts @@ -0,0 +1,11 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class GithubMigration implements MigrationInterface { + name?: string; + async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE "cards" IF NOT EXISTS`); + } + async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE "cards"`); + } +} diff --git a/pmt-auth/src/database/migration/GithubMigration.ts b/pmt-auth/src/database/migration/GithubMigration.ts index 65da8b2..178ac9f 100644 --- a/pmt-auth/src/database/migration/GithubMigration.ts +++ b/pmt-auth/src/database/migration/GithubMigration.ts @@ -1,6 +1,7 @@ import { MigrationInterface, QueryRunner } from 'typeorm'; export class GithubMigration implements MigrationInterface { + name?: string; async up(queryRunner: QueryRunner): Promise { await queryRunner.query(`CREATE TABLE "github" IF NOT EXISTS`); } diff --git a/pmt-auth/src/database/migration/TaskboardMigration.ts b/pmt-auth/src/database/migration/TaskboardMigration.ts new file mode 100644 index 0000000..db3f849 --- /dev/null +++ b/pmt-auth/src/database/migration/TaskboardMigration.ts @@ -0,0 +1,11 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class GithubMigration implements MigrationInterface { + name?: string; + async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE "taskboards" IF NOT EXISTS`); + } + async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE "taskboards"`); + } +} diff --git a/pmt-auth/src/database/repositories/Card.ts b/pmt-auth/src/database/repositories/Card.ts new file mode 100644 index 0000000..9945119 --- /dev/null +++ b/pmt-auth/src/database/repositories/Card.ts @@ -0,0 +1,32 @@ +import { Repository, EntityRepository, getCustomRepository } from 'typeorm'; +import { Card } from '../entity/Card'; +import { Users } from '../entity/User'; +import { UserRepository } from './User'; + +@EntityRepository(Card) +export class CardRepository extends Repository { + async findMembersForCard(id: number): Promise { + const card = await this.findOne(id, { + relations: ['members'] + }); + return card!.members!; + } + + findAllDetails(id: number): Promise { + return this.findOne(id, { + relations: ['board', 'members', 'created_by'] + }); + } + + async assignMemberToCard(user_id: number, card_id: number): Promise { + const userRepo = getCustomRepository(UserRepository); + const user = await userRepo.findOne(user_id); + if (user) { + const card = await this.findOne(card_id); + if (card) { + card.members?.push(user); + return card; + } + } + } +} diff --git a/pmt-auth/src/database/repositories/Project.ts b/pmt-auth/src/database/repositories/Project.ts index 6334a79..cf64e68 100644 --- a/pmt-auth/src/database/repositories/Project.ts +++ b/pmt-auth/src/database/repositories/Project.ts @@ -1,13 +1,55 @@ -import { Repository, EntityRepository } from 'typeorm'; +import { Repository, EntityRepository, getCustomRepository } from 'typeorm'; import { Project } from '../entity/Project'; import { Users } from '../entity/User'; +import { UserRepository } from './User'; +import { Taskboard } from '../entity/Taskboard'; @EntityRepository(Project) export class ProjectRepository extends Repository { - findByName(name: string) { + + async findTaskBoardsForProject(id: number): Promise { + const project = await this.findOne(id, { + relations: ['boards'] + }); + return project!.boards!; + } + + async findMembersForProject(id: number): Promise { + const project = await this.findOne(id, { + relations: ['members'] + }); + return project!.members!; + } + + async findCreatorOfProject(id: number): Promise { + const project = await this.findOne(id, { + relations: ['created_by'] + }); + return project!.created_by!; + } + + async findAllDetails(id: number): Promise { + const project = await this.findOne(id, { + relations: ['created_by', 'members', 'boards'] + }); + return project!; + } + + async addMemberToProject(user_id: number, project_id: number): Promise { + const userRepo = getCustomRepository(UserRepository); + const user = await userRepo.findOne(user_id); + if (user) { + const project = await this.findOne(project_id); + if (project) { + project.members?.push(user); + } + } + } + + findByName(name: string): Promise { return this.findOne({ name: name }); } - findByCreator(user: Users) { + findByCreator(user: Users): Promise { return this.find({ where: { created_by: user diff --git a/pmt-auth/src/database/repositories/Taskboard.ts b/pmt-auth/src/database/repositories/Taskboard.ts new file mode 100644 index 0000000..732d8bc --- /dev/null +++ b/pmt-auth/src/database/repositories/Taskboard.ts @@ -0,0 +1,40 @@ +import { Repository, EntityRepository, getCustomRepository } from 'typeorm'; +import { Taskboard } from '../entity/Taskboard'; +import { Project } from '../entity/Project'; +import { UserRepository } from './User'; +import { Card } from '../entity/Card'; +import { Users } from '../entity/User'; + +@EntityRepository(Taskboard) +export class TaskboardRepository extends Repository { + async findCardsForBoard(id: number): Promise { + const board = await this.findOne(id, { + relations: ['cards'] + }); + return board!.cards!; + } + + async findMembersOfBoard(id: number): Promise { + const board = await this.findOne(id, { + relations: ['members'] + }); + return board!.members!; + } + + async addMemberToTaskBoard(user_id: number, board_id: number): Promise { + const userRepo = getCustomRepository(UserRepository); + const user = await userRepo.findOne(user_id); + if (user) { + const board = await this.findOne(board_id); + if (board) { + board.members?.push(user); + } + } + } + + findAllDetails(id: number): Promise { + return this.findOne(id, { + relations: ['project', 'created_by', 'cards', 'members'] + }); + } +} diff --git a/pmt-auth/src/database/repositories/User.ts b/pmt-auth/src/database/repositories/User.ts index a4b5911..73eec00 100644 --- a/pmt-auth/src/database/repositories/User.ts +++ b/pmt-auth/src/database/repositories/User.ts @@ -1,9 +1,50 @@ import { EntityRepository, Repository } from 'typeorm'; import { Users } from '../entity/User'; +import { Taskboard } from '../entity/Taskboard'; +import { Project } from '../entity/Project'; +import { Card } from '../entity/Card'; +import { Github } from '../entity/Github'; @EntityRepository(Users) export class UserRepository extends Repository { - findByEmail(email: string) { + findByEmail(email: string): Promise { return this.findOne({email: email}); } + + async findProjectsForUser(id: number): Promise { + const user = await this.findOne(id, { + relations: ['projects'] + }); + return user!.projects!; + } + + async findBoardsForUser(id: number): Promise { + const user = await this.findOne(id, { + relations: ['boards'] + }); + return user!.boards!; + } + + async findUserCards(id: number): Promise { + const user = await this.findOne(id, { + relations: ['cards'] + }); + return user!.cards!; + } + + async getGithubProfle(id: number): Promise { + const user = await this.findOne(id, { + relations: ['github'] + }); + return user!.github!; + } + + async addGithubProfile(profile: Github, id: number): Promise { + const user = await this.findOne(id); + if (user) { + user.github = profile; + await this.save(user); + return user; + } + } } diff --git a/pmt-auth/src/interfaces/models/Card.ts b/pmt-auth/src/interfaces/models/Card.ts new file mode 100644 index 0000000..241f78d --- /dev/null +++ b/pmt-auth/src/interfaces/models/Card.ts @@ -0,0 +1,16 @@ +import { CardStatus } from '../../database/entity/Card'; +import { User } from './User'; +import { Taskboard } from './Taskboard'; + +export interface Card { + id: number; + title: string; + description: string; + created_by?: User; + board?: Taskboard; + labels: string[]; + card_status: CardStatus; + members?: User[]; + completed_at?: string; + deadline: string; +} diff --git a/pmt-auth/src/interfaces/models/Project.ts b/pmt-auth/src/interfaces/models/Project.ts index 62d7d1a..39312af 100644 --- a/pmt-auth/src/interfaces/models/Project.ts +++ b/pmt-auth/src/interfaces/models/Project.ts @@ -1,7 +1,13 @@ +import { User } from './User'; +import { Taskboard } from './Taskboard'; + export interface Project { id: number; name: string; description: string; chat_channel_id: number; created_by_id: number; + created_by?: User; + boards?: Taskboard[]; + memmbers?: User[]; } diff --git a/pmt-auth/src/interfaces/models/Taskboard.ts b/pmt-auth/src/interfaces/models/Taskboard.ts new file mode 100644 index 0000000..369718a --- /dev/null +++ b/pmt-auth/src/interfaces/models/Taskboard.ts @@ -0,0 +1,15 @@ +import { Project } from './Project'; +import { User } from './User'; +import { Card } from './Card'; + +export interface Taskboard { + id: number; + name: string; + description: string; + github_repo_url: string; + chat_channel_id: number; + project?: Project; + created_by?: User; + members?: User[]; + cards?: Card[]; +} diff --git a/pmt-auth/src/interfaces/models/User.ts b/pmt-auth/src/interfaces/models/User.ts index 7a48935..ad7a218 100644 --- a/pmt-auth/src/interfaces/models/User.ts +++ b/pmt-auth/src/interfaces/models/User.ts @@ -1,4 +1,7 @@ import { UserRole } from '../../database/entity/User'; +import { Project } from './Project'; +import { Taskboard } from './Taskboard'; +import { Card } from './Card'; export interface User { id: number; @@ -6,5 +9,8 @@ export interface User { email: string; avatar_url: string; org_roles: UserRole; - github_username: string; + github_username: string; + projects?: Project[]; + boards?: Taskboard[]; + cards?: Card[]; }