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.pubkey = context.pubkey || randomBytes(32)
|
||||||
transaction.creationIdentHash = context.creationIdentHash || randomBytes(32)
|
transaction.creationIdentHash = context.creationIdentHash || randomBytes(32)
|
||||||
transaction.creationDate = context.creationDate || new Date()
|
transaction.creationDate = context.creationDate || new Date()
|
||||||
transaction.sendReceiverPublicKey = context.sendReceiverPublicKey || null
|
// transaction.sendReceiverPublicKey = context.sendReceiverPublicKey || null
|
||||||
transaction.sendReceiverUserId = context.sendReceiverUserId || null
|
transaction.linkedUserId = context.sendReceiverUserId || null
|
||||||
transaction.sendSenderFinalBalance = context.sendSenderFinalBalance || null
|
transaction.sendSenderFinalBalance = context.sendSenderFinalBalance || null
|
||||||
|
|
||||||
return transaction
|
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'
|
import { User } from '../../entity/User'
|
||||||
|
|
||||||
export interface TransactionContext {
|
export interface TransactionContext {
|
||||||
|
transactionId: number
|
||||||
transactionTypeId: number
|
transactionTypeId: number
|
||||||
userId: number
|
userId: number
|
||||||
|
balance: BigInt
|
||||||
|
balanceDate: Date
|
||||||
amount: BigInt
|
amount: BigInt
|
||||||
txHash?: Buffer
|
txHash?: Buffer
|
||||||
memo: string
|
memo: string
|
||||||
@ -33,13 +36,3 @@ export interface TransactionSendCoinContext {
|
|||||||
senderFinalBalance?: number
|
senderFinalBalance?: number
|
||||||
transaction?: Transaction
|
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 { UserContext, ServerUserContext } from '../../interface/UserContext'
|
||||||
import {
|
import { BalanceContext, TransactionContext } from '../../interface/TransactionContext'
|
||||||
BalanceContext,
|
|
||||||
TransactionContext,
|
|
||||||
UserTransactionContext,
|
|
||||||
} from '../../interface/TransactionContext'
|
|
||||||
import { UserInterface } from '../../interface/UserInterface'
|
import { UserInterface } from '../../interface/UserInterface'
|
||||||
import { User } from '../../../entity/User'
|
import { User } from '../../../entity/User'
|
||||||
import { ServerUser } from '../../../entity/ServerUser'
|
import { ServerUser } from '../../../entity/ServerUser'
|
||||||
import { Balance } from '../../../entity/Balance'
|
import { Balance } from '../../../entity/Balance'
|
||||||
import { Transaction } from '../../../entity/Transaction'
|
import { Transaction } from '../../../entity/Transaction'
|
||||||
import { UserTransaction } from '../../../entity/UserTransaction'
|
|
||||||
import { Factory } from 'typeorm-seeding'
|
import { Factory } from 'typeorm-seeding'
|
||||||
|
import { randomInt } from 'crypto'
|
||||||
|
|
||||||
export const userSeeder = async (factory: Factory, userData: UserInterface): Promise<void> => {
|
export const userSeeder = async (factory: Factory, userData: UserInterface): Promise<void> => {
|
||||||
const user = await factory(User)(createUserContext(userData)).create()
|
const user = await factory(User)(createUserContext(userData)).create()
|
||||||
@ -22,12 +18,9 @@ export const userSeeder = async (factory: Factory, userData: UserInterface): Pro
|
|||||||
if (userData.addBalance) {
|
if (userData.addBalance) {
|
||||||
// create some GDD for the user
|
// create some GDD for the user
|
||||||
await factory(Balance)(createBalanceContext(userData, user)).create()
|
await factory(Balance)(createBalanceContext(userData, user)).create()
|
||||||
const transaction = await factory(Transaction)(
|
await factory(Transaction)(
|
||||||
createTransactionContext(userData, user, 1, 'Herzlich Willkommen bei Gradido!'),
|
createTransactionContext(userData, user, 1, 'Herzlich Willkommen bei Gradido!'),
|
||||||
).create()
|
).create()
|
||||||
await factory(UserTransaction)(
|
|
||||||
createUserTransactionContext(userData, user, transaction),
|
|
||||||
).create()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,27 +69,16 @@ const createTransactionContext = (
|
|||||||
memo: string,
|
memo: string,
|
||||||
): TransactionContext => {
|
): TransactionContext => {
|
||||||
return {
|
return {
|
||||||
|
transactionId: randomInt(999999),
|
||||||
transactionTypeId: type,
|
transactionTypeId: type,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
amount: BigInt(context.amount || 100000),
|
amount: BigInt(context.amount || 100000),
|
||||||
|
balance: BigInt(context.amount || 100000),
|
||||||
|
balanceDate: new Date(context.recordDate || Date.now()),
|
||||||
txHash: context.creationTxHash,
|
txHash: context.creationTxHash,
|
||||||
memo,
|
memo,
|
||||||
received: context.recordDate,
|
received: context.recordDate,
|
||||||
creationDate: context.creationDate,
|
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,
|
signature: context.signature,
|
||||||
pubkey: context.pubKey,
|
pubkey: context.pubKey,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user