build table user activity & user refresh token

This commit is contained in:
2024-11-26 13:33:13 +07:00
parent df875117b0
commit 6e71588f91
4 changed files with 55 additions and 78 deletions

View File

@ -1,53 +1,54 @@
import bcrypt from 'bcryptjs';
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn } from 'typeorm';
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Index } from 'typeorm';
import { Role } from '../types/role';
import { Status } from '../types/status';
import { ActivityType } from '../types/action';
@Entity('users')
export class User {
@Entity('user_activities')
export class UserActivity {
@PrimaryGeneratedColumn('uuid')
id: string;
@Index()
@Column({
type: 'uuid'
})
id_user: string;
@Index()
@Column({
type: 'uuid'
})
refresh_token: string;
@Index()
@Column({
nullable: false,
unique: true,
length: 64
length: 512
})
email: string;
module: string;
@Column({
nullable: false,
length: 64,
select: false
length: 2048
})
password: string;
@Column({
nullable: false,
unique: true,
length: 64
})
username: string;
description: string;
@Column({
nullable: true,
length: 64
length: 1
})
name: string;
action: ActivityType;
@Column({
nullable: false,
default: 'STAFF' as Role,
length: 30,
length: 2048,
})
role: Role;
url: String;
@Column({
nullable: false,
length: 64
type: 'text',
nullable: true,
})
status: Status;
data_body: String;
@Column()
@CreateDateColumn()
@ -60,12 +61,4 @@ export class User {
@Column({ nullable: true })
@DeleteDateColumn()
deleted_at: Date;
hashPassword() {
this.password = bcrypt.hashSync(this.password, 8);
}
checkIfPasswordMatch(unencryptedPassword: string) {
return bcrypt.compareSync(unencryptedPassword, this.password);
}
}

View File

@ -1,53 +1,39 @@
import bcrypt from 'bcryptjs';
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn } from 'typeorm';
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Index } from 'typeorm';
import { Role } from '../types/role';
import { Status } from '../types/status';
@Entity('users')
export class User {
@Entity('user_refresh_tokens')
export class UserRefreshToken {
@PrimaryGeneratedColumn('uuid')
id: string;
@Index()
@Column({
nullable: false,
unique: true,
length: 64
type: 'uuid'
})
email: string;
id_user: string;
@Column({
nullable: false,
length: 64,
select: false
length: 4096,
})
password: string;
@Column({
nullable: false,
unique: true,
length: 64
})
username: string;
user_agent: string;
@Column({
nullable: true,
length: 64
})
name: string;
os: string;
@Column({
nullable: false,
default: 'STAFF' as Role,
length: 30,
})
role: Role;
@Column({
nullable: false,
nullable: true,
length: 64
})
status: Status;
browser: string;
@Column({
nullable: true,
length: 32
})
remote_addr: string;
@Column()
@CreateDateColumn()
@ -60,12 +46,4 @@ export class User {
@Column({ nullable: true })
@DeleteDateColumn()
deleted_at: Date;
hashPassword() {
this.password = bcrypt.hashSync(this.password, 8);
}
checkIfPasswordMatch(unencryptedPassword: string) {
return bcrypt.compareSync(unencryptedPassword, this.password);
}
}