Commit 6d19d5d3 authored by “Yevgeniy's avatar “Yevgeniy

#23 adde model Project

parent e5346cd0
import {
Column,
Entity,
PrimaryGeneratedColumn,
CreateDateColumn,
BaseEntity,
ManyToOne,
ManyToMany
} from 'typeorm';
import {User} from './User';
interface IProject{
id: string;
title: string;
color: string;
admin:User;
workers:User[]| undefined;
createdAt: Date;
dateDue: Date| null;
department:boolean| false;
}
@Entity({ name: 'Project' })
export class Project extends BaseEntity implements IProject{
@PrimaryGeneratedColumn('uuid')
id!: string
@Column({ name: 'title', type: 'varchar', length:100,nullable: false })
title!: string
@CreateDateColumn({ name: 'createdAt', type: Date, default: new Date() })
createdAt!: Date;
@Column({ name: 'color', type: 'varchar', length:100,nullable: false })
color!: string
@Column({ name: 'dateDue', type: Date, default: null })
dateDue!: Date| null;
@Column({ name: 'department', type: Boolean, default: false })
department!: boolean| false;
@ManyToOne(() => User, (user: { projects: Project[]; }) => user.projects)
admin!: User;
@ManyToMany(() => User, (user: { projects: Project[]; }) => user.projects)
workers!: User[];
}
...@@ -12,6 +12,7 @@ import { ...@@ -12,6 +12,7 @@ import {
import bcrypt from 'bcrypt'; import bcrypt from 'bcrypt';
import {nanoid} from 'nanoid'; import {nanoid} from 'nanoid';
import {Task} from './Task'; import {Task} from './Task';
import {Project} from './Project';
const SALT_WORK_FACTOR= 10; const SALT_WORK_FACTOR= 10;
...@@ -75,6 +76,14 @@ export class User extends BaseEntity implements IUser { ...@@ -75,6 +76,14 @@ export class User extends BaseEntity implements IUser {
@ManyToMany(() => Task, (task: { users: User[] }) =>task.users) @ManyToMany(() => Task, (task: { users: User[] }) =>task.users)
tasksToMake!: Task[]; tasksToMake!: Task[];
@OneToMany(() => Project, (project: { user: User }) => project.user)
adminInProjects!: Project[];
@ManyToMany(() => Project, (project: { users: User[] }) =>project.users)
workerInProjects!: Project[];
@BeforeInsert() @BeforeInsert()
protected async beforeInserthashPassword():Promise<void> { protected async beforeInserthashPassword():Promise<void> {
const salt = await bcrypt.genSalt(SALT_WORK_FACTOR); const salt = await bcrypt.genSalt(SALT_WORK_FACTOR);
......
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