mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
have database building again
This commit is contained in:
parent
32dea81a36
commit
f3f2d547a3
@ -1,5 +1,5 @@
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, OneToOne } from 'typeorm'
|
||||
import { Balance } from '../Balance'
|
||||
import { Balance } from './Balance'
|
||||
|
||||
// Moriz: I do not like the idea of having two user tables
|
||||
@Entity('state_users', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' })
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
import Faker from 'faker'
|
||||
import { define } from 'typeorm-seeding'
|
||||
import { Balance } from '../../entity/Balance'
|
||||
import { BalanceContext } from '../interface/TransactionContext'
|
||||
|
||||
define(Balance, (faker: typeof Faker, context?: BalanceContext) => {
|
||||
if (!context || !context.user) {
|
||||
throw new Error('Balance: No user present!')
|
||||
}
|
||||
|
||||
const balance = new Balance()
|
||||
balance.modified = context.modified ? context.modified : faker.date.recent()
|
||||
balance.recordDate = context.recordDate ? context.recordDate : faker.date.recent()
|
||||
balance.amount = context.amount ? context.amount : 10000000
|
||||
balance.user = context.user
|
||||
|
||||
return balance
|
||||
})
|
||||
@ -16,7 +16,6 @@ define(Transaction, (faker: typeof Faker, context?: TransactionContext) => {
|
||||
transaction.creationDate = context.creationDate || new Date()
|
||||
// transaction.sendReceiverPublicKey = context.sendReceiverPublicKey || null
|
||||
transaction.linkedUserId = context.sendReceiverUserId || null
|
||||
transaction.sendSenderFinalBalance = context.sendSenderFinalBalance || null
|
||||
|
||||
return transaction
|
||||
})
|
||||
|
||||
@ -1,20 +1,12 @@
|
||||
import { User } from '../../entity/User'
|
||||
import Decimal from "decimal.js-light";
|
||||
|
||||
export interface TransactionContext {
|
||||
typeId: number
|
||||
userId: number
|
||||
balance: BigInt
|
||||
balance: Decimal
|
||||
balanceDate: Date
|
||||
amount: BigInt
|
||||
amount: Decimal
|
||||
memo: string
|
||||
creationDate?: Date
|
||||
sendReceiverUserId?: number
|
||||
sendSenderFinalBalance?: BigInt
|
||||
}
|
||||
|
||||
export interface BalanceContext {
|
||||
modified?: Date
|
||||
recordDate?: Date
|
||||
amount?: number
|
||||
user?: User
|
||||
}
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import Decimal from 'decimal.js-light'
|
||||
|
||||
export interface UserInterface {
|
||||
// from user
|
||||
email?: string
|
||||
@ -24,10 +26,7 @@ export interface UserInterface {
|
||||
// flag for balance (creation of 1000 GDD)
|
||||
addBalance?: boolean
|
||||
// balance
|
||||
balanceModified?: Date
|
||||
recordDate?: Date
|
||||
creationDate?: Date
|
||||
amount?: number
|
||||
creationTxHash?: Buffer
|
||||
signature?: Buffer
|
||||
amount?: Decimal
|
||||
}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import { UserContext, ServerUserContext } from '../../interface/UserContext'
|
||||
import { BalanceContext, TransactionContext } from '../../interface/TransactionContext'
|
||||
import { 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 { Factory } from 'typeorm-seeding'
|
||||
import Decimal from 'decimal.js-light'
|
||||
|
||||
export const userSeeder = async (factory: Factory, userData: UserInterface): Promise<void> => {
|
||||
const user = await factory(User)(createUserContext(userData)).create()
|
||||
@ -16,7 +16,6 @@ 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()
|
||||
await factory(Transaction)(
|
||||
createTransactionContext(userData, user, 1, 'Herzlich Willkommen bei Gradido!'),
|
||||
).create()
|
||||
@ -52,15 +51,6 @@ const createServerUserContext = (context: UserInterface): ServerUserContext => {
|
||||
}
|
||||
}
|
||||
|
||||
const createBalanceContext = (context: UserInterface, user: User): BalanceContext => {
|
||||
return {
|
||||
modified: context.balanceModified,
|
||||
recordDate: context.recordDate,
|
||||
amount: context.amount,
|
||||
user,
|
||||
}
|
||||
}
|
||||
|
||||
const createTransactionContext = (
|
||||
context: UserInterface,
|
||||
user: User,
|
||||
@ -70,8 +60,8 @@ const createTransactionContext = (
|
||||
return {
|
||||
typeId: type,
|
||||
userId: user.id,
|
||||
amount: BigInt(context.amount || 100000),
|
||||
balance: BigInt(context.amount || 100000),
|
||||
amount: context.amount || new Decimal(1000),
|
||||
balance: context.amount || new Decimal(1000),
|
||||
balanceDate: new Date(context.recordDate || Date.now()),
|
||||
memo,
|
||||
creationDate: context.creationDate,
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { UserInterface } from '../../interface/UserInterface'
|
||||
|
||||
export const bibiBloxberg: UserInterface = {
|
||||
@ -19,16 +20,7 @@ export const bibiBloxberg: UserInterface = {
|
||||
'knife normal level all hurdle crucial color avoid warrior stadium road bachelor affair topple hawk pottery right afford immune two ceiling budget glance hour ',
|
||||
isAdmin: false,
|
||||
addBalance: true,
|
||||
balanceModified: new Date('2021-11-30T10:37:11'),
|
||||
recordDate: new Date('2021-11-30T10:37:11'),
|
||||
creationDate: new Date('2021-08-01 00:00:00'),
|
||||
amount: 10000000,
|
||||
creationTxHash: Buffer.from(
|
||||
'51103dc0fc2ca5d5d75a9557a1e899304e5406cfdb1328d8df6414d527b0118100000000000000000000000000000000',
|
||||
'hex',
|
||||
),
|
||||
signature: Buffer.from(
|
||||
'2a2c71f3e41adc060bbc3086577e2d57d24eeeb0a7727339c3f85aad813808f601d7e1df56a26e0929d2e67fc054fca429ccfa283ed2782185c7f009fe008f0c',
|
||||
'hex',
|
||||
),
|
||||
amount: new Decimal(1000),
|
||||
}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { UserInterface } from '../../interface/UserInterface'
|
||||
|
||||
export const bobBaumeister: UserInterface = {
|
||||
@ -19,16 +20,7 @@ export const bobBaumeister: UserInterface = {
|
||||
'detail master source effort unable waste tilt flush domain orchard art truck hint barrel response gate impose peanut secret merry three uncle wink resource ',
|
||||
isAdmin: false,
|
||||
addBalance: true,
|
||||
balanceModified: new Date('2021-11-30T10:37:14'),
|
||||
recordDate: new Date('2021-11-30T10:37:14'),
|
||||
creationDate: new Date('2021-08-01 00:00:00'),
|
||||
amount: 10000000,
|
||||
creationTxHash: Buffer.from(
|
||||
'be095dc87acb94987e71168fee8ecbf50ecb43a180b1006e75d573b35725c69c00000000000000000000000000000000',
|
||||
'hex',
|
||||
),
|
||||
signature: Buffer.from(
|
||||
'1fbd6b9a3d359923b2501557f3bc79fa7e428127c8090fb16bc490b4d87870ab142b3817ddd902d22f0b26472a483233784a0e460c0622661752a13978903905',
|
||||
'hex',
|
||||
),
|
||||
amount: new Decimal(1000),
|
||||
}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { UserInterface } from '../../interface/UserInterface'
|
||||
|
||||
export const raeuberHotzenplotz: UserInterface = {
|
||||
@ -19,16 +20,7 @@ export const raeuberHotzenplotz: UserInterface = {
|
||||
'gospel trip tenant mouse spider skill auto curious man video chief response same little over expire drum display fancy clinic keen throw urge basket ',
|
||||
isAdmin: false,
|
||||
addBalance: true,
|
||||
balanceModified: new Date('2021-11-30T10:37:13'),
|
||||
recordDate: new Date('2021-11-30T10:37:13'),
|
||||
creationDate: new Date('2021-08-01 00:00:00'),
|
||||
amount: 10000000,
|
||||
creationTxHash: Buffer.from(
|
||||
'23ba44fd84deb59b9f32969ad0cb18bfa4588be1bdb99c396888506474c16c1900000000000000000000000000000000',
|
||||
'hex',
|
||||
),
|
||||
signature: Buffer.from(
|
||||
'756d3da061687c575d1dbc5073908f646aa5f498b0927b217c83b48af471450e571dfe8421fb8e1f1ebd1104526b7e7c6fa78684e2da59c8f7f5a8dc3d9e5b0b',
|
||||
'hex',
|
||||
),
|
||||
amount: new Decimal(1000),
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user