#84 added PasswordRecovery model

parent d98464d7
......@@ -4,6 +4,7 @@ import {Task} from './models/Task';
import { Project } from "./models/Project";
import { Member } from "./models/Member";
import { DateTimeTask } from "./models/DateTimeTask";
import { PasswordRecovery } from "./models/PasswordRecovery";
export const myDataSource = new DataSource({
type: "postgres",
......@@ -12,7 +13,7 @@ export const myDataSource = new DataSource({
username: "pluser",
password: "pluser",
database: "planner",
entities: [User,Task,Project,Member,DateTimeTask],
entities: [User,Task,Project,Member,DateTimeTask,PasswordRecovery],
logging: true,
synchronize: true, // in build switch to false
migrationsRun: false
......
import {
Column,
Entity,
PrimaryGeneratedColumn,
BaseEntity,
OneToOne,
CreateDateColumn,
} from 'typeorm';
import { User } from './User';
interface IPasswordRecovery{
user: User;
token: string;
enabled:boolean;
createdAt:Date;
}
@Entity({name: 'PasswordRecovery'})
export class PasswordRecovery extends BaseEntity implements IPasswordRecovery{
@PrimaryGeneratedColumn('uuid')
id!: string;
@CreateDateColumn({ name: 'created_at', type: Date, default: new Date() })
createdAt!: Date;
@Column({ name: 'token', type:'string', nullable:false})
token!: string;
@OneToOne(()=>User, (user:{passwordRecovery:PasswordRecovery})=>user.passwordRecovery)
user!:User;
@Column({ name: 'enabled', type:'boolean', default:false})
enabled!: boolean;
}
\ No newline at end of file
......@@ -5,9 +5,7 @@ import {
CreateDateColumn,
BeforeInsert,
BaseEntity,
ManyToMany,
OneToMany,
JoinTable,
OneToOne,
} from 'typeorm';
import {IsEmail
......@@ -17,6 +15,7 @@ import bcrypt from 'bcrypt';
import {nanoid} from 'nanoid';
import {Task} from './Task';
import {Member} from './Member';
import { PasswordRecovery } from './PasswordRecovery';
const SALT_WORK_FACTOR= 10;
......@@ -35,6 +34,7 @@ interface IUser {
createdAt: Date;
createdTasks:Task[];
members: Member[];
passwordRecovery:PasswordRecovery;
}
......@@ -76,21 +76,17 @@ export class User extends BaseEntity implements IUser {
@Exclude({ toPlainOnly: true })
password!: string;
@OneToMany(() => Task, (task: { user: User }) => task.user)
createdTasks!: Task[];
@OneToMany(() => Task, (task: { user: User }) =>task.user)
tasks!: Task[];
@OneToMany(() => Member, (member: { user: User }) => member.user)
members!: Member[];
// @ManyToMany(() => Project,(project: { user: User }) => project.user)
// @JoinTable()
// workerInProjects!: Project[];
@OneToOne(()=>PasswordRecovery, (passwordRecovery:{user:User})=>passwordRecovery.user)
passwordRecovery!:PasswordRecovery;
@BeforeInsert()
protected async beforeInserthashPassword():Promise<void> {
......
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