mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add transaction factory
This commit is contained in:
parent
0b67da3d2c
commit
43b9f9394b
20
database/src/factories/transaction.factory.ts
Normal file
20
database/src/factories/transaction.factory.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import Faker from 'faker'
|
||||||
|
import { define } from 'typeorm-seeding'
|
||||||
|
import { Transaction } from '../../entity/Transaction'
|
||||||
|
import { TransactionContext } from '../interface/TransactionContext'
|
||||||
|
import { randomBytes } from 'crypto'
|
||||||
|
|
||||||
|
define(Transaction, (faker: typeof Faker, context?: TransactionContext) => {
|
||||||
|
if (!context) context = {}
|
||||||
|
|
||||||
|
const transaction = new Transaction()
|
||||||
|
transaction.transactionTypeId = context.transactionTypeId ? context.transactionTypeId : 2
|
||||||
|
transaction.txHash = context.txHash ? context.txHash : randomBytes(48)
|
||||||
|
transaction.memo = context.memo ? context.memo : faker.lorem.sentence()
|
||||||
|
transaction.received = context.received ? context.received : new Date()
|
||||||
|
transaction.blockchainTypeId = context.blockchainTypeId ? context.blockchainTypeId : 1
|
||||||
|
if (context.transactionSendCoin) transaction.transactionSendCoin = context.transactionSendCoin
|
||||||
|
if (context.transactionCreation) transaction.transactionCreation = context.transactionCreation
|
||||||
|
|
||||||
|
return transaction
|
||||||
|
})
|
||||||
12
database/src/interface/TransactionContext.ts
Normal file
12
database/src/interface/TransactionContext.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { TransactionSendCoin } from '../../entity/TransactionSendCoin'
|
||||||
|
import { TransactionCreation } from '../../entity/TransactionCreation'
|
||||||
|
|
||||||
|
export interface TransactionContext {
|
||||||
|
transactionTypeId?: number
|
||||||
|
txHash?: Buffer
|
||||||
|
memo?: string
|
||||||
|
received?: Date
|
||||||
|
blockchainTypeId?: number
|
||||||
|
transactionSendCoin?: TransactionSendCoin
|
||||||
|
transactionCreation?: TransactionCreation
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user