build table user activity & user refresh token
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,9 @@
|
||||
import config from 'config';
|
||||
import { DataSource } from "typeorm";
|
||||
import { User } from "../entity/users";
|
||||
import { TrialBalance } from '../entity/trial_balance';
|
||||
import { ILogObj, Logger } from 'tslog';
|
||||
import { LNKOLEK } from '../entity/lnkolek';
|
||||
import { CifAccount } from '../entity/cif_account';
|
||||
import { UserActivity } from '../entity/users_activity';
|
||||
import { UserRefreshToken } from '../entity/users_refresh_token';
|
||||
|
||||
export class OrmHelper {
|
||||
static DB: DataSource = null
|
||||
@ -23,7 +22,7 @@ export class OrmHelper {
|
||||
database: String(config.get("database.database")),
|
||||
synchronize: true,
|
||||
logging: true,
|
||||
entities: [User, TrialBalance, LNKOLEK, CifAccount],
|
||||
entities: [User, UserActivity, UserRefreshToken],
|
||||
subscribers: [],
|
||||
migrations: [],
|
||||
})
|
||||
|
||||
7
src/types/action.ts
Normal file
7
src/types/action.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export enum ActivityType {
|
||||
"Create" = "C",
|
||||
"Read" = "R",
|
||||
"Update" = "U",
|
||||
"Delete" = "D",
|
||||
"Restore" = "T",
|
||||
};
|
||||
Reference in New Issue
Block a user