From 92f1044ec194768d799ed0bf0629ac86bdba9721 Mon Sep 17 00:00:00 2001 From: fro1991 Date: Wed, 15 Jan 2025 23:53:24 +0700 Subject: [PATCH] update --- src/entity/credit_application_chats.ts | 45 +++++++++++ src/entity/credit_application_forms.ts | 6 ++ src/entity/credit_applications.ts | 5 ++ src/entity/credit_companies.ts | 36 ++++++++- .../credit_company_user_refresh_token.ts | 64 +++++++++++++++ src/entity/credit_company_users.ts | 77 +++++++++++++++++++ src/index.ts | 8 ++ 7 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 src/entity/credit_application_chats.ts create mode 100644 src/entity/credit_company_user_refresh_token.ts create mode 100644 src/entity/credit_company_users.ts diff --git a/src/entity/credit_application_chats.ts b/src/entity/credit_application_chats.ts new file mode 100644 index 0000000..6dcc5dc --- /dev/null +++ b/src/entity/credit_application_chats.ts @@ -0,0 +1,45 @@ +import { Column, CreateDateColumn, DeleteDateColumn, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'; + +import { CreditApplication } from './credit_applications'; +import { CreditTypeForms } from './credit_type_forms'; +import { CreditCompanyUser } from './credit_company_users'; + +@Entity('credit_application_chats') +export class CreditApplicationChat { + @PrimaryGeneratedColumn('uuid') + id: string; + + @ManyToOne(() => CreditApplication, { onDelete: "RESTRICT" }) + @JoinColumn() + application: CreditApplication + + @Column({ + nullable: true, + length: 4096 + }) + name: string; + + @Column({ + nullable: true, + length: 4096 + }) + company: string; + + @Column({ + nullable: true, + length: 4096 + }) + message: string; + + @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/credit_application_forms.ts b/src/entity/credit_application_forms.ts index dc41dc5..f014dae 100644 --- a/src/entity/credit_application_forms.ts +++ b/src/entity/credit_application_forms.ts @@ -22,6 +22,12 @@ export class CreditApplicationForm { }) value: string; + @Column({ + nullable: true, + length: 256 + }) + status: string; + @Column() @CreateDateColumn() created_at: Date; diff --git a/src/entity/credit_applications.ts b/src/entity/credit_applications.ts index 5d5f65d..817e0f5 100644 --- a/src/entity/credit_applications.ts +++ b/src/entity/credit_applications.ts @@ -3,6 +3,7 @@ import { Column, CreateDateColumn, DeleteDateColumn, Entity, JoinColumn, ManyToO import { CreditApplicationStatus } from '../types/credit'; import { CreditCompany } from './credit_companies'; import { CreditDebtor } from './credit_debtors'; +import { CreditCompanyUser } from './credit_company_users'; @Entity('credit_applications') export class CreditApplication { @@ -17,6 +18,10 @@ export class CreditApplication { @JoinColumn() company: CreditCompany + @ManyToOne(() => CreditCompanyUser) + @JoinColumn() + user: CreditCompanyUser + @Column({ nullable: true, length: 256 diff --git a/src/entity/credit_companies.ts b/src/entity/credit_companies.ts index 9e00004..19444a0 100644 --- a/src/entity/credit_companies.ts +++ b/src/entity/credit_companies.ts @@ -8,11 +8,19 @@ export class CreditCompany { id: string; @Column({ - nullable: true, + nullable: false, + unique: true, length: 256 }) name: string; + @Column({ + nullable: false, + unique: true, + length: 256 + }) + code: string; + @Column({ nullable: true, length: 4096 @@ -25,6 +33,32 @@ export class CreditCompany { }) status: Status; + @Column({ + nullable: true, + length: 256 + }) + type: string; + + @Column({ + nullable: false, + length: 256 + }) + pic_name: string; + + @Column({ + nullable: false, + unique: true, + length: 256 + }) + pic_phone: string; + + @Column({ + nullable: false, + unique: true, + length: 256 + }) + pic_email: string; + @Column() @CreateDateColumn() created_at: Date; diff --git a/src/entity/credit_company_user_refresh_token.ts b/src/entity/credit_company_user_refresh_token.ts new file mode 100644 index 0000000..3005372 --- /dev/null +++ b/src/entity/credit_company_user_refresh_token.ts @@ -0,0 +1,64 @@ +import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Index } from 'typeorm'; + +@Entity('credit_company_user_refresh_tokens') +export class CreditCompanyUserRefreshToken { + @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/credit_company_users.ts b/src/entity/credit_company_users.ts new file mode 100644 index 0000000..c7777ef --- /dev/null +++ b/src/entity/credit_company_users.ts @@ -0,0 +1,77 @@ +import bcrypt from 'bcryptjs'; +import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Index, OneToOne, JoinColumn, ManyToOne, OneToMany, ManyToMany, JoinTable } from 'typeorm'; + +import { Status } from '../types/status'; +import { CreditCompany } from './credit_companies'; + +@Entity('credit_company_users') +export class CreditCompanyUser { + @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: true, + length: 64, + unique: false, + }) + name: string; + + @ManyToOne(() => CreditCompany, { onDelete: 'CASCADE' }) + @JoinTable() + company: CreditCompany + + @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 548d075..643d076 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,6 +46,9 @@ import { CreditTypeForms } from "./entity/credit_type_forms"; import { CreditApplication } from "./entity/credit_applications"; import { CreditApplicationStatus } from "./types/credit"; import { CreditApplicationForm } from "./entity/credit_application_forms"; +import { CreditCompanyUser } from "./entity/credit_company_users"; +import { CreditCompanyUserRefreshToken } from "./entity/credit_company_user_refresh_token"; +import { CreditApplicationChat } from "./entity/credit_application_chats"; import { Application } from "./entity/application"; import { AssetClassification } from "./entity/asset_classification" import { FixedAssetClassification } from "./entity/fixed_assets_classification"; @@ -65,6 +68,8 @@ import { AssetJournalEntry } from "./entity/journal_entries"; import { PaymentApproval } from "./entity/payment_approval"; import { FinanceMemo } from "./entity/finance_memo"; + + export { User, // UserRole, @@ -136,5 +141,8 @@ export { CreditApplication, CreditApplicationStatus, CreditApplicationForm, + CreditCompanyUser, + CreditCompanyUserRefreshToken, + CreditApplicationChat, Application, };