48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import {
|
|
Entity,
|
|
PrimaryGeneratedColumn,
|
|
Column,
|
|
ManyToOne,
|
|
JoinColumn,
|
|
Index,
|
|
} from 'typeorm';
|
|
import { Transaction } from './transaction.entity';
|
|
import { Product } from '../../products/entities/product.entity';
|
|
|
|
@Entity('transaction_items')
|
|
export class TransactionItem {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id: string;
|
|
|
|
@Column({ type: 'uuid' })
|
|
@Index('idx_transaction_items_transaction')
|
|
transactionId: string;
|
|
|
|
@Column({ type: 'uuid' })
|
|
@Index('idx_transaction_items_product')
|
|
productId: string;
|
|
|
|
@Column({ type: 'varchar', length: 255 })
|
|
productName: string;
|
|
|
|
@Column({ type: 'decimal', precision: 10, scale: 2 })
|
|
price: number;
|
|
|
|
@Column({ type: 'int' })
|
|
quantity: number;
|
|
|
|
@Column({ type: 'decimal', precision: 10, scale: 2 })
|
|
lineTotal: number;
|
|
|
|
// Relationships
|
|
@ManyToOne(() => Transaction, (transaction) => transaction.items, {
|
|
onDelete: 'CASCADE',
|
|
})
|
|
@JoinColumn({ name: 'transactionId' })
|
|
transaction: Transaction;
|
|
|
|
@ManyToOne(() => Product, (product) => product.transactionItems)
|
|
@JoinColumn({ name: 'productId' })
|
|
product: Product;
|
|
}
|