Skip to content

Commit

Permalink
Merge pull request #49 from Vaibhav-Ganatra/master
Browse files Browse the repository at this point in the history
Entities, Migrations, Interfaces and Custom Repositories for all tables except permissions and roles
  • Loading branch information
Sarvesh67 authored Aug 1, 2020
2 parents 510242e + 5992f00 commit e114250
Show file tree
Hide file tree
Showing 17 changed files with 589 additions and 47 deletions.
69 changes: 69 additions & 0 deletions pmt-auth/src/database/entity/Card.ts
Original file line number Diff line number Diff line change
@@ -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;
}
62 changes: 62 additions & 0 deletions pmt-auth/src/database/entity/Github.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Entity, PrimaryColumn, Column } from 'typeorm';

@Entity({ name: 'github'})
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;
}
56 changes: 56 additions & 0 deletions pmt-auth/src/database/entity/Project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
JoinColumn,
ManyToOne,
CreateDateColumn,
UpdateDateColumn,
Timestamp,
OneToMany,
ManyToMany,
JoinTable
} from 'typeorm';
import { Users } from './User';
import { Taskboard } from './Taskboard';

@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;

@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;
}
56 changes: 56 additions & 0 deletions pmt-auth/src/database/entity/Taskboard.ts
Original file line number Diff line number Diff line change
@@ -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;

}
108 changes: 61 additions & 47 deletions pmt-auth/src/database/entity/User.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,76 @@
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
import {
Entity,
PrimaryGeneratedColumn,
Column,
JoinColumn,
JoinTable,
OneToOne,
CreateDateColumn,
UpdateDateColumn,
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',
CORE = 'core',
CREW = 'crew'
}

@Entity()
@Entity({name: 'users'})
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('varchar')
name: string | undefined;

@Column('text')
location: string | undefined;
@Column({ type: 'varchar', unique: true })
email: string | undefined;

@Column('text')
email: string | undefined;
@Column({ type: 'text', nullable: true })
avatar_url: string | undefined;

@Column('text')
bio: string | undefined;
@Column({
type: 'enum',
enum: UserRole,
default: UserRole.CREW
})
org_role: UserRole | undefined;

@Column('text')
twitter_username: string | undefined;
@Column({
type: 'text',
unique: true
})
github_username: string | undefined;

@Column('int')
public_repos: number | undefined;
@OneToOne((type) => Github)
@JoinColumn()
github: Github | undefined;

@Column('int')
public_gists: number | undefined;
@CreateDateColumn()
created_at: Timestamp | undefined;

@Column('int')
followers: number | undefined;
@UpdateDateColumn()
updated_at: Timestamp | undefined;

@Column('int')
following: number | undefined;
@ManyToMany((type) => Project, project => project.members, {
cascade: true
})
projects: Project[] | undefined;

@Column('int')
private_gists: number | undefined;
@ManyToMany(type => Taskboard, board => board.members, {
cascade: true
})
boards: Taskboard[] | undefined;

@Column('int')
total_private_repos: number | undefined;
@ManyToMany(type => Card, card => card.members, {
cascade: true
})
cards: Card[] | undefined;

@Column('int')
owned_private_repos: number | undefined;
}
11 changes: 11 additions & 0 deletions pmt-auth/src/database/migration/CardMigration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class GithubMigration implements MigrationInterface {
name?: string;
async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "cards" IF NOT EXISTS`);
}
async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "cards"`);
}
}
11 changes: 11 additions & 0 deletions pmt-auth/src/database/migration/GithubMigration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class GithubMigration implements MigrationInterface {
name?: string;
async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "github" IF NOT EXISTS`);
}
async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "github"`);
}
}
Loading

0 comments on commit e114250

Please sign in to comment.