#84 added PasswordRecovery model

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