|
|
import { |
|
|
Entity, |
|
|
PrimaryGeneratedColumn, |
|
|
Column, |
|
|
CreateDateColumn, |
|
|
UpdateDateColumn, |
|
|
OneToOne, |
|
|
OneToMany, |
|
|
Index, |
|
|
} from 'typeorm'; |
|
|
import { User } from './User'; |
|
|
import { Transaction } from './Transaction'; |
|
|
|
|
|
@Entity('wallets') |
|
|
@Index(['userId']) |
|
|
export class Wallet { |
|
|
@PrimaryGeneratedColumn('uuid') |
|
|
id: string; |
|
|
|
|
|
@OneToOne(() => User, (user) => user.wallet) |
|
|
user: User; |
|
|
|
|
|
@Column({ unique: true }) |
|
|
userId: string; |
|
|
|
|
|
@Column('decimal', { precision: 15, scale: 2, default: 0 }) |
|
|
balance: number; |
|
|
|
|
|
@Column({ default: 0 }) |
|
|
freeTasksUsed: number; |
|
|
|
|
|
@OneToMany(() => Transaction, (transaction) => transaction.wallet) |
|
|
transactions: Transaction[]; |
|
|
|
|
|
@CreateDateColumn() |
|
|
createdAt: Date; |
|
|
|
|
|
@UpdateDateColumn() |
|
|
updatedAt: Date; |
|
|
} |
|
|
|