src/user/user.entity.ts
User entity
Properties |
Methods |
articles |
articles:
|
Type : ArticleEntity[]
|
Decorators :
@OneToMany(undefined, undefined)
|
Defined in src/user/user.entity.ts:59
|
Link with his articles |
bio |
bio:
|
Type : string
|
Decorators :
@Column({default: ''})
|
Defined in src/user/user.entity.ts:33
|
email:
|
Type : string
|
Decorators :
@Column()
|
Defined in src/user/user.entity.ts:30
|
favorites |
favorites:
|
Type : ArticleEntity[]
|
Decorators :
@ManyToMany(undefined)
|
Defined in src/user/user.entity.ts:53
|
id |
id:
|
Type : number
|
Decorators :
@PrimaryGeneratedColumn()
|
Defined in src/user/user.entity.ts:20
|
image |
image:
|
Type : string
|
Decorators :
@Column({default: ''})
|
Defined in src/user/user.entity.ts:36
|
password |
password:
|
Type : string
|
Decorators :
@Column()
|
Defined in src/user/user.entity.ts:42
|
Password |
username |
username:
|
Type : string
|
Decorators :
@Column()
|
Defined in src/user/user.entity.ts:26
|
Username |
hashPassword |
hashPassword()
|
Decorators :
@BeforeInsert()
|
Defined in src/user/user.entity.ts:45
|
Returns :
void
|
import {
Entity,
PrimaryGeneratedColumn,
Column,
BeforeInsert,
JoinTable,
ManyToMany,
OneToMany
} from 'typeorm';
import { IsEmail, Validate } from 'class-validator';
import * as crypto from 'crypto';
import { ArticleEntity } from '../article/article.entity';
/**
* User entity
*/
@Entity('user')
export class UserEntity {
@PrimaryGeneratedColumn()
id: number;
/**
* Username
*/
@Column()
username: string;
@Column()
@IsEmail()
email: string;
@Column({ default: '' })
bio: string;
@Column({ default: '' })
image: string;
/**
* Password
*/
@Column()
password: string;
@BeforeInsert()
hashPassword() {
this.password = crypto
.createHmac('sha256', this.password)
.digest('hex');
}
@ManyToMany(type => ArticleEntity)
@JoinTable()
favorites: ArticleEntity[];
/**
* Link with his articles
*/
@OneToMany(type => ArticleEntity, article => article.author)
articles: ArticleEntity[];
}