File

src/user/user.entity.ts

Description

User entity

Index

Properties
Methods

Properties

articles
articles: ArticleEntity[]
Type : ArticleEntity[]
Decorators :
@OneToMany(undefined, undefined)

Link with his articles

bio
bio: string
Type : string
Decorators :
@Column({default: ''})
email
email: string
Type : string
Decorators :
@Column()
@IsEmail()
favorites
favorites: ArticleEntity[]
Type : ArticleEntity[]
Decorators :
@ManyToMany(undefined)
@JoinTable()
id
id: number
Type : number
Decorators :
@PrimaryGeneratedColumn()
image
image: string
Type : string
Decorators :
@Column({default: ''})
password
password: string
Type : string
Decorators :
@Column()

Password

username
username: string
Type : string
Decorators :
@Column()

Username

Methods

hashPassword
hashPassword()
Decorators :
@BeforeInsert()
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[];
}

result-matching ""

    No results matching ""