From 9873400aa602728c49ef7267281c0adf9fc40413 Mon Sep 17 00:00:00 2001 From: fro1991 Date: Wed, 7 May 2025 01:16:32 +0700 Subject: [PATCH] brilink update --- .../brilink_merchant_user_refresh_token.ts | 64 ++++++++++++++ src/entity/brilink_merchant_users.ts | 85 +++++++++++++++++++ src/index.ts | 4 + 3 files changed, 153 insertions(+) create mode 100644 src/entity/brilink_merchant_user_refresh_token.ts create mode 100644 src/entity/brilink_merchant_users.ts diff --git a/src/entity/brilink_merchant_user_refresh_token.ts b/src/entity/brilink_merchant_user_refresh_token.ts new file mode 100644 index 0000000..bb6e627 --- /dev/null +++ b/src/entity/brilink_merchant_user_refresh_token.ts @@ -0,0 +1,64 @@ +import { Column, CreateDateColumn, DeleteDateColumn, Entity, Index, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'; + +@Entity('brilink_merchant_user_refresh_tokens', { schema: 'brilinks' }) +export class BrilinkMerchantUserRefreshToken { + @PrimaryGeneratedColumn('uuid') + refresh_token: string; + + @Index() + @Column({ + type: 'uuid' + }) + id_user: string; + + @Column({ + nullable: false, + length: 4096, + }) + user_agent: string; + + @Column({ + nullable: true, + length: 128 + }) + os: string; + + @Column({ + nullable: true, + length: 256 + }) + device: string; + + @Column({ + nullable: true, + length: 64 + }) + platform: string; + + @Column({ + nullable: true, + length: 64 + }) + browser: string; + + @Column({ + nullable: true, + length: 32 + }) + remote_addr: string; + + @Column('timestamp') + expired_at: Date; + + @Column() + @CreateDateColumn() + created_at: Date; + + @Column({ nullable: true }) + @UpdateDateColumn() + updated_at: Date; + + @Column({ nullable: true }) + @DeleteDateColumn() + deleted_at: Date; +} \ No newline at end of file diff --git a/src/entity/brilink_merchant_users.ts b/src/entity/brilink_merchant_users.ts new file mode 100644 index 0000000..1b9efe2 --- /dev/null +++ b/src/entity/brilink_merchant_users.ts @@ -0,0 +1,85 @@ +import bcrypt from 'bcryptjs'; +import { Column, CreateDateColumn, DeleteDateColumn, Entity, Index, JoinTable, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'; + +import { Status } from '../types/status'; +import { BrilinkMerchantTerminal } from './brilink_merchant_terminals'; +import { BrilinkMerchant } from './brilink_merchants'; + +@Entity('brilink_merchant_users', { schema: 'brilinks' }) +export class BrilinkMerchantUser { + @PrimaryGeneratedColumn('uuid') + id: string; + + @Column({ + nullable: false, + unique: false, + length: 64 + }) + email: string; + + @Column({ + nullable: false, + length: 64, + select: false + }) + password: string; + + @Column({ + nullable: false, + unique: false, + length: 64 + }) + username: string; + + @Column({ + nullable: false, + unique: true, + length: 256 + }) + authenticator: string; + + @Column({ + nullable: true, + length: 64, + unique: false, + }) + name: string; + + @ManyToOne(() => BrilinkMerchant, { onDelete: 'CASCADE' }) + @JoinTable() + merchant: BrilinkMerchant + + @Index() + @Column({ + nullable: true, + type: 'uuid', + select: false + }) + reset_token: string; + + @Column({ + nullable: false, + length: 64 + }) + status: Status; + + @Column() + @CreateDateColumn() + created_at: Date; + + @Column({ nullable: true }) + @UpdateDateColumn() + updated_at: Date; + + @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/index.ts b/src/index.ts index b228ead..328328f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -115,6 +115,8 @@ import { } from './types/brilink' import { BrilinkMerchant } from './entity/brilink_merchants' +import { BrilinkMerchantUser } from './entity/brilink_merchant_users' +import { BrilinkMerchantUserRefreshToken } from './entity/brilink_merchant_user_refresh_token' import { BrilinkTerminal } from './entity/brilink_terminals' import { BrilinkTerminalMenu } from './entity/brilink_terminal_menus' import { BrilinkMerchantSite } from './entity/brilink_merchant_sites' @@ -247,6 +249,8 @@ export { BrilinkMerchantStatus, BrilinkTerminalType, BrilinkTerminalCondition, BrilinkTerminalOnline, BrilinkMerchant, + BrilinkMerchantUser, + BrilinkMerchantUserRefreshToken, BrilinkTerminal, BrilinkTerminalMenu, BrilinkMerchantSite,