From 16bc4cd34da90989c3324146c2c00c96e1dc9f1d Mon Sep 17 00:00:00 2001 From: fro1991 Date: Sat, 18 Oct 2025 01:23:09 +0700 Subject: [PATCH] update --- src/entity/trx_customer_accounts.ts | 9 ++ src/entity/trx_customer_costs.ts | 77 +++++++++++++ src/entity/trx_customer_user_activities.ts | 63 +++++++++++ .../trx_customer_user_refresh_tokens.ts | 64 +++++++++++ src/entity/trx_customer_users.ts | 105 ++++++++++++++++++ src/entity/trx_customers.ts | 12 ++ src/schema/trx.ts | 4 + src/types/trx.ts | 6 + 8 files changed, 340 insertions(+) create mode 100644 src/entity/trx_customer_costs.ts create mode 100644 src/entity/trx_customer_user_activities.ts create mode 100644 src/entity/trx_customer_user_refresh_tokens.ts create mode 100644 src/entity/trx_customer_users.ts diff --git a/src/entity/trx_customer_accounts.ts b/src/entity/trx_customer_accounts.ts index 8ad1556..96ffe2b 100644 --- a/src/entity/trx_customer_accounts.ts +++ b/src/entity/trx_customer_accounts.ts @@ -57,11 +57,20 @@ export class TrxCustomerAccount { @CreateDateColumn() created_at: Date; + @Column({ nullable: true, length: 256 }) + created_by: string; + @Column({ nullable: true }) @UpdateDateColumn() updated_at: Date; + @Column({ nullable: true, length: 256 }) + updated_by: string; + @Column({ nullable: true }) @DeleteDateColumn() deleted_at: Date; + + @Column({ nullable: true, length: 256 }) + deleted_by: string; } diff --git a/src/entity/trx_customer_costs.ts b/src/entity/trx_customer_costs.ts new file mode 100644 index 0000000..0543263 --- /dev/null +++ b/src/entity/trx_customer_costs.ts @@ -0,0 +1,77 @@ +import { Column, CreateDateColumn, DeleteDateColumn, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm"; +import { Status } from "../types/status"; +import { TrxCostType, TrxCustomerType } from "../types/trx"; +import { TrxCustomer } from "./trx_customers"; + +@Entity("trx_customer_cost", { schema: "trx" }) +export class TrxCustomerCost { + @PrimaryGeneratedColumn("uuid") + id: string; + + @ManyToOne(() => TrxCustomer, { onDelete: "RESTRICT" }) + @JoinColumn() + customer: TrxCustomer; + + @Column({ + nullable: false, + length: 4096, + }) + type: TrxCostType; + + @Column({ + nullable: false, + type: "float8", + }) + min_amount: number; + + @Column({ + nullable: false, + type: "float8", + }) + max_amount: number; + + @Column({ + nullable: false, + type: "float8", + }) + percentage: number; + + @Column({ + nullable: true, + type: "float8", + }) + min_cost: number; + + @Column({ + nullable: true, + type: "float8", + }) + max_cost: number; + + @Column({ + nullable: false, + length: 64, + }) + status: Status; + + @Column() + @CreateDateColumn() + created_at: Date; + + @Column({ nullable: true, length: 256 }) + created_by: string; + + @Column({ nullable: true }) + @UpdateDateColumn() + updated_at: Date; + + @Column({ nullable: true, length: 256 }) + updated_by: string; + + @Column({ nullable: true }) + @DeleteDateColumn() + deleted_at: Date; + + @Column({ nullable: true, length: 256 }) + deleted_by: string; +} diff --git a/src/entity/trx_customer_user_activities.ts b/src/entity/trx_customer_user_activities.ts new file mode 100644 index 0000000..fd3c97e --- /dev/null +++ b/src/entity/trx_customer_user_activities.ts @@ -0,0 +1,63 @@ +import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Index, JoinColumn, ManyToOne } from "typeorm"; + +import { ActivityType } from "../types/action"; +import { TrxCustomerUser } from "./trx_customer_users"; + +@Entity("trx_customer_user_activities", { schema: "trx" }) +export class TrxCustomerUserActivity { + @PrimaryGeneratedColumn("uuid") + id: string; + + @ManyToOne(() => TrxCustomerUser, { onDelete: "NO ACTION", nullable: false }) + @JoinColumn() + user: TrxCustomerUser; + + @Index() + @Column({ + type: "uuid", + }) + refresh_token: string; + + @Index() + @Column({ + nullable: false, + length: 512, + }) + module: string; + + @Column({ + nullable: false, + length: 2048, + }) + description: string; + + @Column({ + nullable: true, + length: 1, + }) + action: ActivityType; + + @Column({ + nullable: false, + length: 2048, + }) + url: String; + + @Column({ + type: "text", + nullable: true, + }) + data_body: String; + + @Column() + @CreateDateColumn() + created_at: Date; + + @Column({ nullable: true }) + @UpdateDateColumn() + updated_at: Date; + + @Column({ nullable: true }) + @DeleteDateColumn() + deleted_at: Date; +} diff --git a/src/entity/trx_customer_user_refresh_tokens.ts b/src/entity/trx_customer_user_refresh_tokens.ts new file mode 100644 index 0000000..85df43c --- /dev/null +++ b/src/entity/trx_customer_user_refresh_tokens.ts @@ -0,0 +1,64 @@ +import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Index } from "typeorm"; + +@Entity("trx_customer_user_refresh_tokens", { schema: "trx" }) +export class TrxCustomerUserRefreshToken { + @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; +} diff --git a/src/entity/trx_customer_users.ts b/src/entity/trx_customer_users.ts new file mode 100644 index 0000000..58587e7 --- /dev/null +++ b/src/entity/trx_customer_users.ts @@ -0,0 +1,105 @@ +import bcrypt from "bcryptjs"; +import { Column, CreateDateColumn, DeleteDateColumn, Entity, Index, JoinTable, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm"; + +import { Status } from "../types/status"; +import { TrxCustomer } from "./trx_customers"; + +@Entity("trx_customer_users", { schema: "trx" }) +export class TrxCustomerUser { + @PrimaryGeneratedColumn("uuid") + id: string; + + @ManyToOne(() => TrxCustomer, { onDelete: "RESTRICT" }) + @JoinTable() + customer: TrxCustomer; + + @Column({ + nullable: false, + unique: true, + length: 64, + }) + email: string; + + @Column({ + nullable: false, + unique: true, + length: 256, + }) + phone: string; + + @Column({ + nullable: false, + length: 64, + select: false, + }) + password: string; + + @Column({ + nullable: false, + unique: true, + length: 64, + }) + username: string; + + @Column({ + nullable: false, + length: 64, + unique: false, + }) + name: string; + + @Column({ + nullable: false, + length: 256, + }) + file: string; + + @Column({ + type: "jsonb", + nullable: true, + }) + level: string[]; + + @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, length: 256 }) + created_by: string; + + @Column({ nullable: true }) + @UpdateDateColumn() + updated_at: Date; + + @Column({ nullable: true, length: 256 }) + updated_by: string; + + @Column({ nullable: true }) + @DeleteDateColumn() + deleted_at: Date; + + @Column({ nullable: true, length: 256 }) + deleted_by: string; + + hashPassword() { + this.password = bcrypt.hashSync(this.password, 8); + } + + checkIfPasswordMatch(unencryptedPassword: string) { + return bcrypt.compareSync(unencryptedPassword, this.password); + } +} diff --git a/src/entity/trx_customers.ts b/src/entity/trx_customers.ts index b30a09a..d745c42 100644 --- a/src/entity/trx_customers.ts +++ b/src/entity/trx_customers.ts @@ -53,6 +53,18 @@ export class TrxCustomer { }) pic_email: string; + @Column({ + nullable: false, + length: 256, + }) + pic_file: string; + + @Column({ + nullable: false, + length: 256, + }) + cover: string; + @Column({ nullable: false, length: 256, diff --git a/src/schema/trx.ts b/src/schema/trx.ts index 9832459..5cd264f 100644 --- a/src/schema/trx.ts +++ b/src/schema/trx.ts @@ -45,4 +45,8 @@ export * from "../entity/trx_partner_users"; export * from "../entity/trx_customers"; export * from "../entity/trx_customer_accounts"; +export * from "../entity/trx_customer_users"; +export * from "../entity/trx_customer_user_refresh_tokens"; +export * from "../entity/trx_customer_user_activities"; +export * from "../entity/trx_customer_costs"; export * from "../types/trx"; diff --git a/src/types/trx.ts b/src/types/trx.ts index 507b76d..c3f4984 100644 --- a/src/types/trx.ts +++ b/src/types/trx.ts @@ -3,6 +3,12 @@ export enum TrxCustomerType { "business" = "business", } +export enum TrxCostType { + "domestic" = "domestic", + "remittance" = "remittance", + "swift" = "swift", +} + export enum TrxTransactionStatus { "verify" = "verify", "open" = "open",