mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 00:24:54 +00:00
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { Column, CreateDateColumn, Entity, Index, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
|
|
import { Card } from './card.entity';
|
|
import { Transaction } from './transaction.entity';
|
|
|
|
@Entity('accounts')
|
|
export class Account {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id!: string;
|
|
|
|
@Column('varchar', { length: 255, nullable: false, unique: true, name: 'account_reference' })
|
|
@Index({ unique: true })
|
|
accountReference!: string;
|
|
|
|
@Index({ unique: true })
|
|
@Column('varchar', { length: 255, nullable: false, name: 'account_number' })
|
|
accountNumber!: string;
|
|
|
|
@Index({ unique: true })
|
|
@Column('varchar', { length: 255, nullable: false, name: 'iban' })
|
|
iban!: string;
|
|
|
|
@Column('varchar', { length: 255, nullable: false, name: 'currency' })
|
|
currency!: string;
|
|
|
|
@Column('decimal', {
|
|
precision: 10,
|
|
scale: 2,
|
|
default: 0.0,
|
|
name: 'balance',
|
|
transformer: {
|
|
to: (value: number) => value,
|
|
from: (value: string) => parseFloat(value),
|
|
},
|
|
})
|
|
balance!: number;
|
|
|
|
@Column('decimal', {
|
|
precision: 10,
|
|
scale: 2,
|
|
default: 0.0,
|
|
name: 'reserved_balance',
|
|
transformer: {
|
|
to: (value: number) => value,
|
|
from: (value: string) => parseFloat(value),
|
|
},
|
|
})
|
|
reservedBalance!: number;
|
|
|
|
@OneToMany(() => Card, (card) => card.account, { cascade: true })
|
|
cards!: Card[];
|
|
|
|
@OneToMany(() => Transaction, (transaction) => transaction.account, { cascade: true })
|
|
transactions!: Transaction[];
|
|
|
|
@CreateDateColumn({ name: 'created_at', type: 'timestamp with time zone' })
|
|
createdAt!: Date;
|
|
|
|
@UpdateDateColumn({ name: 'updated_at', type: 'timestamp with time zone' })
|
|
updatedAt!: Date;
|
|
}
|