mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
fixed database build
This commit is contained in:
parent
ab1df1c35d
commit
4bb9f12783
@ -20,8 +20,8 @@ define(Transaction, (faker: typeof Faker, context?: TransactionContext) => {
|
||||
transaction.pubkey = context.pubkey || randomBytes(32)
|
||||
transaction.creationIdentHash = context.creationIdentHash || randomBytes(32)
|
||||
transaction.creationDate = context.creationDate || new Date()
|
||||
transaction.sendReceiverPublicKey = context.sendReceiverPublicKey || null
|
||||
transaction.sendReceiverUserId = context.sendReceiverUserId || null
|
||||
// transaction.sendReceiverPublicKey = context.sendReceiverPublicKey || null
|
||||
transaction.linkedUserId = context.sendReceiverUserId || null
|
||||
transaction.sendSenderFinalBalance = context.sendSenderFinalBalance || null
|
||||
|
||||
return transaction
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
import Faker from 'faker'
|
||||
import { define } from 'typeorm-seeding'
|
||||
import { UserTransaction } from '../../entity/UserTransaction'
|
||||
import { UserTransactionContext } from '../interface/TransactionContext'
|
||||
|
||||
define(UserTransaction, (faker: typeof Faker, context?: UserTransactionContext) => {
|
||||
if (!context || !context.userId || !context.transactionId) {
|
||||
throw new Error('UserTransaction: No userId and/or transactionId present!')
|
||||
}
|
||||
|
||||
const userTransaction = new UserTransaction()
|
||||
userTransaction.userId = context.userId
|
||||
userTransaction.transactionId = context.transactionId
|
||||
userTransaction.transactionTypeId = context.transactionTypeId ? context.transactionTypeId : 1
|
||||
userTransaction.balance = context.balance ? context.balance : 100000
|
||||
userTransaction.balanceDate = context.balanceDate ? context.balanceDate : new Date()
|
||||
|
||||
return userTransaction
|
||||
})
|
||||
@ -2,8 +2,11 @@ import { Transaction } from '../../entity/Transaction'
|
||||
import { User } from '../../entity/User'
|
||||
|
||||
export interface TransactionContext {
|
||||
transactionId: number
|
||||
transactionTypeId: number
|
||||
userId: number
|
||||
balance: BigInt
|
||||
balanceDate: Date
|
||||
amount: BigInt
|
||||
txHash?: Buffer
|
||||
memo: string
|
||||
@ -33,13 +36,3 @@ export interface TransactionSendCoinContext {
|
||||
senderFinalBalance?: number
|
||||
transaction?: Transaction
|
||||
}
|
||||
|
||||
export interface UserTransactionContext {
|
||||
userId?: number
|
||||
transactionId?: number
|
||||
transactionTypeId?: number
|
||||
balance?: number
|
||||
balanceDate?: Date
|
||||
signature?: Buffer
|
||||
pubkey?: Buffer
|
||||
}
|
||||
|
||||
@ -1,16 +1,12 @@
|
||||
import { UserContext, ServerUserContext } from '../../interface/UserContext'
|
||||
import {
|
||||
BalanceContext,
|
||||
TransactionContext,
|
||||
UserTransactionContext,
|
||||
} from '../../interface/TransactionContext'
|
||||
import { BalanceContext, TransactionContext } from '../../interface/TransactionContext'
|
||||
import { UserInterface } from '../../interface/UserInterface'
|
||||
import { User } from '../../../entity/User'
|
||||
import { ServerUser } from '../../../entity/ServerUser'
|
||||
import { Balance } from '../../../entity/Balance'
|
||||
import { Transaction } from '../../../entity/Transaction'
|
||||
import { UserTransaction } from '../../../entity/UserTransaction'
|
||||
import { Factory } from 'typeorm-seeding'
|
||||
import { randomInt } from 'crypto'
|
||||
|
||||
export const userSeeder = async (factory: Factory, userData: UserInterface): Promise<void> => {
|
||||
const user = await factory(User)(createUserContext(userData)).create()
|
||||
@ -22,12 +18,9 @@ export const userSeeder = async (factory: Factory, userData: UserInterface): Pro
|
||||
if (userData.addBalance) {
|
||||
// create some GDD for the user
|
||||
await factory(Balance)(createBalanceContext(userData, user)).create()
|
||||
const transaction = await factory(Transaction)(
|
||||
await factory(Transaction)(
|
||||
createTransactionContext(userData, user, 1, 'Herzlich Willkommen bei Gradido!'),
|
||||
).create()
|
||||
await factory(UserTransaction)(
|
||||
createUserTransactionContext(userData, user, transaction),
|
||||
).create()
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,27 +69,16 @@ const createTransactionContext = (
|
||||
memo: string,
|
||||
): TransactionContext => {
|
||||
return {
|
||||
transactionId: randomInt(999999),
|
||||
transactionTypeId: type,
|
||||
userId: user.id,
|
||||
amount: BigInt(context.amount || 100000),
|
||||
balance: BigInt(context.amount || 100000),
|
||||
balanceDate: new Date(context.recordDate || Date.now()),
|
||||
txHash: context.creationTxHash,
|
||||
memo,
|
||||
received: context.recordDate,
|
||||
creationDate: context.creationDate,
|
||||
}
|
||||
}
|
||||
|
||||
const createUserTransactionContext = (
|
||||
context: UserInterface,
|
||||
user: User,
|
||||
transaction: Transaction,
|
||||
): UserTransactionContext => {
|
||||
return {
|
||||
userId: user.id,
|
||||
transactionId: transaction.id,
|
||||
transactionTypeId: transaction.transactionTypeId,
|
||||
balance: context.amount,
|
||||
balanceDate: context.recordDate,
|
||||
signature: context.signature,
|
||||
pubkey: context.pubKey,
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user