53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { Column, CreateDateColumn, Entity, OneToMany, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
|
|
import { ColumnBigIntTransformer } from '../../../utils/ColumnBigIntTransformer';
|
|
import { ColumnNumericTransformer } from '../../../utils/ColumnNumericTransformer';
|
|
import { PaymentMethod } from '../types/PaymentMethod';
|
|
import { InvoiceReason } from '../types/InvoiceReason';
|
|
import { InvoiceBtcDetails } from './InvoiceBtcDetails';
|
|
import { InvoiceMoneroDetails } from './InvoiceMoneroDetails';
|
|
import { InvoicePayment } from './InvoicePayment';
|
|
|
|
@Entity('invoices')
|
|
export class Invoice {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id: string;
|
|
|
|
@Column({ type: 'enum', enum: InvoiceReason })
|
|
reason: InvoiceReason;
|
|
|
|
@Column({ type: 'enum', enum: PaymentMethod })
|
|
paymentMethod: PaymentMethod;
|
|
|
|
@Column({
|
|
type: 'numeric',
|
|
precision: 12,
|
|
scale: 2,
|
|
transformer: new ColumnNumericTransformer()
|
|
})
|
|
amountFiat: number;
|
|
|
|
@Column({ length: 3 })
|
|
fiatCurrency: string;
|
|
|
|
@Column({ type: 'timestamptz' })
|
|
expiresAt: Date;
|
|
|
|
@Column({ type: 'varchar', length: 255, unique: true })
|
|
paymentAddress: string;
|
|
|
|
@Column({ type: 'bigint', transformer: new ColumnBigIntTransformer() })
|
|
expectedTotalAtomic: string;
|
|
|
|
@OneToMany(() => InvoicePayment, payment => payment.invoice, { cascade: true })
|
|
payments: InvoicePayment[];
|
|
|
|
@OneToOne(() => InvoiceMoneroDetails, moneroDetails => moneroDetails.invoice, { cascade: true })
|
|
moneroDetails: InvoiceMoneroDetails | null;
|
|
|
|
@OneToOne(() => InvoiceBtcDetails, btcDetails => btcDetails.invoice, { cascade: true })
|
|
btcDetails: InvoiceBtcDetails | null;
|
|
|
|
@CreateDateColumn()
|
|
createdAt: Date;
|
|
}
|