diff --git a/src/entity/users_activity.ts b/src/entity/users_activity.ts index 0ff6623..31fd37d 100644 --- a/src/entity/users_activity.ts +++ b/src/entity/users_activity.ts @@ -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); - } } \ No newline at end of file diff --git a/src/entity/users_refresh_token.ts b/src/entity/users_refresh_token.ts index 0ff6623..28ebf3b 100644 --- a/src/entity/users_refresh_token.ts +++ b/src/entity/users_refresh_token.ts @@ -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); - } } \ No newline at end of file diff --git a/src/helpers/orm.ts b/src/helpers/orm.ts index 0b6c5df..3cba593 100644 --- a/src/helpers/orm.ts +++ b/src/helpers/orm.ts @@ -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: [], }) diff --git a/src/types/action.ts b/src/types/action.ts new file mode 100644 index 0000000..fa30453 --- /dev/null +++ b/src/types/action.ts @@ -0,0 +1,7 @@ +export enum ActivityType { + "Create" = "C", + "Read" = "R", + "Update" = "U", + "Delete" = "D", + "Restore" = "T", +}; \ No newline at end of file