#58 added model Member and related fields in related models

parent 6a213935
......@@ -2,6 +2,7 @@ import { DataSource } from "typeorm";
import {User} from './models/User';
import {Task} from './models/Task';
import { Project } from "./models/Project";
import { Member } from "./models/Member";
export const myDataSource = new DataSource({
type: "postgres",
......@@ -10,7 +11,7 @@ export const myDataSource = new DataSource({
username: "pluser",
password: "pluser",
database: "planner",
entities: [User,Task,Project],
entities: [User,Task,Project,Member],
logging: true,
synchronize: true, // in build switch to false
migrationsRun: false
......
import {
Column,
Entity,
PrimaryGeneratedColumn,
CreateDateColumn,
BaseEntity,
ManyToOne,
ManyToMany,
OneToMany,
JoinTable
} from 'typeorm';
import {User} from './User';
import {Project} from './Project';
import {Task} from './Task';
export enum MemberRole {USER="user" ,WATCHER= "watcher",ADMIN="admin"}
interface IMember{
id: string;
user: User;
project: Project;
createdAt: Date;
role: MemberRole;
}
@Entity({name:"Member"})
export class Member extends BaseEntity implements IMember{
@PrimaryGeneratedColumn("uuid")
id!: string;
@CreateDateColumn({ name: 'createdAt', type: Date, default: new Date() })
createdAt!: Date;
@ManyToOne(() => User, (user: { members: Member[]; }) => user.members,{cascade: true, onUpdate:'CASCADE'})
user!: User;
@ManyToOne(() => Project, (project: { members: Member[]; }) => project.members,{cascade: true, onUpdate:'CASCADE'})
project!: Project;
@Column({
type: "enum",
enum: MemberRole,
default: MemberRole.ADMIN
})
role!: MemberRole
}
\ No newline at end of file
......@@ -9,8 +9,9 @@ import {
OneToMany,
JoinTable
} from 'typeorm';
import {User} from './User';
// import {User} from './User';
import {Task} from './Task';
import {Member} from './Member';
......@@ -18,12 +19,13 @@ import {
id: string;
title: string;
color: string;
admin:User;
workers:User[];
// admin:User;
// workers:User[];
tasks:Task[]|null;
createdAt: Date;
dateDue: Date| null;
department:boolean;
// department:boolean;
members: Member[];
}
@Entity({ name: 'Project' })
......@@ -44,16 +46,19 @@ import {
@Column({ name: 'dateDue', type: Date, default: null })
dateDue!: Date| null;
@Column({ name: 'department', type: Boolean,nullable:true ,default: false})
department!: boolean;
// @Column({ name: 'department', type: Boolean,nullable:true ,default: false})
// department!: boolean;
@ManyToOne(() => User, (user: { projects: Project[]; }) => user.projects,{eager : true})
admin!: User;
// @ManyToOne(() => User, (user: { projects: Project[]; }) => user.projects,{eager : true})
// admin!: User;
@OneToMany(() => Task, (task: { project: Project; })=>task.project)
tasks!:Task[]|null;
@ManyToMany(() => User, (user: { projects: Project[]; }) => user.projects,{eager : true,cascade: true, onUpdate:'CASCADE',onDelete: 'CASCADE'})
@JoinTable()
workers!: User[];
@OneToMany(() => Member, (member: { project: Project; })=>member.project)
members!:Member[];
// @ManyToMany(() => User, (user: { projects: Project[]; }) => user.projects,{eager : true,cascade: true, onUpdate:'CASCADE',onDelete: 'CASCADE'})
// @JoinTable()
// workers!: User[];
}
\ No newline at end of file
......@@ -16,6 +16,7 @@ import bcrypt from 'bcrypt';
import {nanoid} from 'nanoid';
import {Task} from './Task';
import {Project} from './Project';
import {Member} from './Member';
const SALT_WORK_FACTOR= 10;
......@@ -33,8 +34,9 @@ interface IUser {
token: string;
createdAt: Date;
createdTasks:Task[];
workerInProjects:Project[];
adminInProjects:Project[];
// workerInProjects:Project[];
// adminInProjects:Project[];
membership: Member[];
}
......@@ -84,12 +86,12 @@ export class User extends BaseEntity implements IUser {
tasks!: Task[];
@OneToMany(() => Project, (project: { user: User }) => project.user)
adminInProjects!: Project[];
@OneToMany(() => Member, (member: { user: User }) => member.user)
membership!: Member[];
@ManyToMany(() => Project,(project: { user: User }) => project.user)
@JoinTable()
workerInProjects!: Project[];
// @ManyToMany(() => Project,(project: { user: User }) => project.user)
// @JoinTable()
// workerInProjects!: Project[];
@BeforeInsert()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment