mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add userTransactions, transactionCreation and transaction
This commit is contained in:
parent
66e629daa2
commit
2a5b0e49fe
18
database/src/factories/transaction-creation.factory.ts
Normal file
18
database/src/factories/transaction-creation.factory.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import Faker from 'faker'
|
||||
import { define } from 'typeorm-seeding'
|
||||
import { TransactionCreation } from '../../entity/TransactionCreation'
|
||||
import { TransactionCreationContext } from '../interface/TransactionContext'
|
||||
|
||||
define(TransactionCreation, (faker: typeof Faker, context?: TransactionCreationContext) => {
|
||||
if (!context || !context.userId || !context.transaction) {
|
||||
throw new Error('TransactionCreation: No userId and/or transaction present!')
|
||||
}
|
||||
|
||||
const transactionCreation = new TransactionCreation()
|
||||
transactionCreation.userId = context.userId
|
||||
transactionCreation.amount = context.amount ? context.amount : 100000
|
||||
transactionCreation.targetDate = context.targetDate ? context.targetDate : new Date()
|
||||
transactionCreation.transaction = context.transaction
|
||||
|
||||
return transactionCreation
|
||||
})
|
||||
19
database/src/factories/user-transaction.factory.ts
Normal file
19
database/src/factories/user-transaction.factory.ts
Normal file
@ -0,0 +1,19 @@
|
||||
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
|
||||
})
|
||||
@ -36,3 +36,11 @@ export interface TransactionCreationContext {
|
||||
targetDate?: Timestamp
|
||||
transaction?: Transaction
|
||||
}
|
||||
|
||||
export interface UserTransactionContext {
|
||||
userId?: number
|
||||
transactionId?: number
|
||||
transactionTypeId?: number
|
||||
balance?: number
|
||||
balanceDate?: Date
|
||||
}
|
||||
|
||||
@ -27,10 +27,12 @@ export interface UserInterface {
|
||||
modified?: Date
|
||||
// flag for admin
|
||||
isAdmin?: boolean
|
||||
// flag for balance
|
||||
// flag for balance (creation of 1000 GDD)
|
||||
addBalance?: boolean
|
||||
// balance
|
||||
balanceModified?: Date
|
||||
recordDate?: Date
|
||||
targetDate?: Date
|
||||
amount?: number
|
||||
creationTxHash?: Buffer
|
||||
}
|
||||
|
||||
@ -5,7 +5,12 @@ import {
|
||||
ServerUserContext,
|
||||
LoginUserRolesContext,
|
||||
} from '../../interface/UserContext'
|
||||
import { BalanceContext } from '../../interface/TransactionContext'
|
||||
import {
|
||||
BalanceContext,
|
||||
TransactionContext,
|
||||
TransactionCreationContext,
|
||||
UserTransactionContext,
|
||||
} from '../../interface/TransactionContext'
|
||||
import { UserInterface } from '../../interface/UserInterface'
|
||||
import { User } from '../../../entity/User'
|
||||
import { LoginUser } from '../../../entity/LoginUser'
|
||||
@ -13,6 +18,9 @@ import { LoginUserBackup } from '../../../entity/LoginUserBackup'
|
||||
import { ServerUser } from '../../../entity/ServerUser'
|
||||
import { LoginUserRoles } from '../../../entity/LoginUserRoles'
|
||||
import { Balance } from '../../../entity/Balance'
|
||||
import { Transaction } from '../../../entity/Transaction'
|
||||
import { UserTransaction } from '../../../entity/UserTransaction'
|
||||
import { TransactionCreation } from '../../../entity/TransactionCreation'
|
||||
import { Factory } from 'typeorm-seeding'
|
||||
|
||||
export const userSeeder = async (factory: Factory, userData: UserInterface): Promise<void> => {
|
||||
@ -29,7 +37,17 @@ 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)(
|
||||
createTransactionContext(userData, 1, 'Herzlich Willkommen bei Gradido!'),
|
||||
).create()
|
||||
await factory(TransactionCreation)(
|
||||
createTransactionCreationContext(userData, user, transaction),
|
||||
).create()
|
||||
await factory(UserTransaction)(
|
||||
createUserTransactionContext(userData, user, transaction),
|
||||
).create()
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,3 +122,43 @@ const createBalanceContext = (context: UserInterface, user: User): BalanceContex
|
||||
user,
|
||||
}
|
||||
}
|
||||
|
||||
const createTransactionContext = (
|
||||
context: UserInterface,
|
||||
type: number,
|
||||
memo: string,
|
||||
): TransactionContext => {
|
||||
return {
|
||||
transactionTypeId: type,
|
||||
txHash: context.creationTxHash,
|
||||
memo,
|
||||
received: context.recordDate,
|
||||
}
|
||||
}
|
||||
|
||||
const createTransactionCreationContext = (
|
||||
context: UserInterface,
|
||||
user: User,
|
||||
transaction: Transaction,
|
||||
): TransactionCreationContext => {
|
||||
return {
|
||||
userId: user.id,
|
||||
amount: context.amount,
|
||||
targetDate: context.targetDate,
|
||||
transaction,
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,5 +25,10 @@ export const bibiBloxberg = {
|
||||
addBalance: true,
|
||||
balanceModified: new Date('2021-11-30T10:37:11'),
|
||||
recordDate: new Date('2021-11-30T10:37:11'),
|
||||
targetDate: new Date('2021-08-01 00:00:00'),
|
||||
amount: 10000000,
|
||||
creationTxHash: Buffer.from(
|
||||
'51103dc0fc2ca5d5d75a9557a1e899304e5406cfdb1328d8df6414d527b0118100000000000000000000000000000000',
|
||||
'hex',
|
||||
),
|
||||
}
|
||||
|
||||
@ -25,5 +25,10 @@ export const bobBaumeister = {
|
||||
addBalance: true,
|
||||
balanceModified: new Date('2021-11-30T10:37:14'),
|
||||
recordDate: new Date('2021-11-30T10:37:14'),
|
||||
targetDate: new Date('2021-08-01 00:00:00'),
|
||||
amount: 10000000,
|
||||
creationTxHash: Buffer.from(
|
||||
'be095dc87acb94987e71168fee8ecbf50ecb43a180b1006e75d573b35725c69c00000000000000000000000000000000',
|
||||
'hex',
|
||||
),
|
||||
}
|
||||
|
||||
@ -25,5 +25,10 @@ export const raeuberHotzenplotz = {
|
||||
addBalance: true,
|
||||
balanceModified: new Date('2021-11-30T10:37:13'),
|
||||
recordDate: new Date('2021-11-30T10:37:13'),
|
||||
targetDate: new Date('2021-08-01 00:00:00'),
|
||||
amount: 10000000,
|
||||
creationTxHash: Buffer.from(
|
||||
'23ba44fd84deb59b9f32969ad0cb18bfa4588be1bdb99c396888506474c16c1900000000000000000000000000000000',
|
||||
'hex',
|
||||
),
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user