fixed seeds

This commit is contained in:
Ulf Gebhardt 2022-02-20 04:02:05 +01:00
parent bfde22b261
commit 6b78161182
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
11 changed files with 54 additions and 108 deletions

View File

@ -49,7 +49,7 @@ export class Transaction extends BaseEntity {
nullable: true,
default: null,
})
sendReceiverPublicKey: Buffer
sendReceiverPublicKey: Buffer | null
@Column({
name: 'send_receiver_user_id',
@ -58,8 +58,8 @@ export class Transaction extends BaseEntity {
nullable: true,
default: null,
})
sendReceiverUserId: number
sendReceiverUserId: number | null
@Column({ name: 'send_sender_final_balance', length: 20, nullable: true, default: null })
sendSenderFinalBalance: BigInt
sendSenderFinalBalance: BigInt | null
}

View File

@ -1,18 +0,0 @@
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
})

View File

@ -5,17 +5,24 @@ import { TransactionContext } from '../interface/TransactionContext'
import { randomBytes } from 'crypto'
define(Transaction, (faker: typeof Faker, context?: TransactionContext) => {
if (!context) context = {}
if (!context) {
throw new Error('TransactionContext not well defined.')
}
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 === '' ? context.memo : faker.lorem.sentence()
transaction.received = context.received ? context.received : new Date()
transaction.signature = context.signature ? context.signature : randomBytes(64)
transaction.pubkey = context.signaturePubkey ? context.signaturePubkey : randomBytes(32)
if (context.transactionSendCoin) transaction.transactionSendCoin = context.transactionSendCoin
if (context.transactionCreation) transaction.transactionCreation = context.transactionCreation
transaction.transactionTypeId = context.transactionTypeId // || 2
transaction.userId = context.userId
transaction.amount = context.amount
transaction.txHash = context.txHash || randomBytes(48)
transaction.memo = context.memo
transaction.received = context.received || new Date()
transaction.signature = context.signature || randomBytes(64)
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.sendSenderFinalBalance = context.sendSenderFinalBalance || null
return transaction
})

View File

@ -1,18 +1,20 @@
import { Transaction } from '../../entity/Transaction'
import { TransactionSendCoin } from '../../entity/TransactionSendCoin'
import { TransactionCreation } from '../../entity/TransactionCreation'
import { User } from '../../entity/User'
export interface TransactionContext {
transactionTypeId?: number
transactionTypeId: number
userId: number
amount: BigInt
txHash?: Buffer
memo?: string
memo: string
received?: Date
blockchainTypeId?: number
signature?: Buffer
signaturePubkey?: Buffer
transactionSendCoin?: TransactionSendCoin
transactionCreation?: TransactionCreation
pubkey?: Buffer
creationIdentHash?: Buffer
creationDate?: Date
sendReceiverPublicKey?: Buffer
sendReceiverUserId?: number
sendSenderFinalBalance?: BigInt
}
export interface BalanceContext {
@ -32,13 +34,6 @@ export interface TransactionSendCoinContext {
transaction?: Transaction
}
export interface TransactionCreationContext {
userId?: number
amount?: number
targetDate?: Date
transaction?: Transaction
}
export interface UserTransactionContext {
userId?: number
transactionId?: number

View File

@ -11,7 +11,6 @@ export interface UserInterface {
emailChecked?: boolean
language?: string
deletedAt?: Date
groupId?: number
publisherId?: number
passphrase?: string
// from server user
@ -27,9 +26,8 @@ export interface UserInterface {
// balance
balanceModified?: Date
recordDate?: Date
targetDate?: Date
creationDate?: Date
amount?: number
creationTxHash?: Buffer
signature?: Buffer
signaturePubkey?: Buffer
}

View File

@ -2,7 +2,6 @@ import { UserContext, ServerUserContext } from '../../interface/UserContext'
import {
BalanceContext,
TransactionContext,
TransactionCreationContext,
UserTransactionContext,
} from '../../interface/TransactionContext'
import { UserInterface } from '../../interface/UserInterface'
@ -11,7 +10,6 @@ import { ServerUser } from '../../../entity/ServerUser'
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> => {
@ -25,10 +23,7 @@ export const userSeeder = async (factory: Factory, userData: UserInterface): Pro
// 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),
createTransactionContext(userData, user, 1, 'Herzlich Willkommen bei Gradido!'),
).create()
await factory(UserTransaction)(
createUserTransactionContext(userData, user, transaction),
@ -76,27 +71,18 @@ const createBalanceContext = (context: UserInterface, user: User): BalanceContex
const createTransactionContext = (
context: UserInterface,
user: User,
type: number,
memo: string,
): TransactionContext => {
return {
transactionTypeId: type,
userId: user.id,
amount: BigInt(context.amount || 100000),
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,
creationDate: context.creationDate,
}
}
@ -112,6 +98,6 @@ const createUserTransactionContext = (
balance: context.amount,
balanceDate: context.recordDate,
signature: context.signature,
pubkey: context.signaturePubkey,
pubkey: context.pubKey,
}
}

View File

@ -1,8 +1,9 @@
export const bibiBloxberg = {
import { UserInterface } from '../../interface/UserInterface'
export const bibiBloxberg: UserInterface = {
email: 'bibi@bloxberg.de',
firstName: 'Bibi',
lastName: 'Bloxberg',
username: 'bibi',
// description: 'Hex Hex',
password: BigInt('12825419584724616625'),
pubKey: Buffer.from('42de7e4754625b730018c3b4ea745a4d043d9d867af352d0f08871793dfa6743', 'hex'),
@ -14,16 +15,13 @@ export const bibiBloxberg = {
createdAt: new Date('2021-11-26T11:32:16'),
emailChecked: true,
language: 'de',
disabled: false,
groupId: 1,
passphrase:
'knife normal level all hurdle crucial color avoid warrior stadium road bachelor affair topple hawk pottery right afford immune two ceiling budget glance hour ',
mnemonicType: 2,
isAdmin: false,
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'),
creationDate: new Date('2021-08-01 00:00:00'),
amount: 10000000,
creationTxHash: Buffer.from(
'51103dc0fc2ca5d5d75a9557a1e899304e5406cfdb1328d8df6414d527b0118100000000000000000000000000000000',
@ -33,8 +31,4 @@ export const bibiBloxberg = {
'2a2c71f3e41adc060bbc3086577e2d57d24eeeb0a7727339c3f85aad813808f601d7e1df56a26e0929d2e67fc054fca429ccfa283ed2782185c7f009fe008f0c',
'hex',
),
signaturePubkey: Buffer.from(
'7281e0ee3258b08801f3ec73e431b4519677f65c03b0382c63a913b5784ee770',
'hex',
),
}

View File

@ -1,8 +1,9 @@
export const bobBaumeister = {
import { UserInterface } from '../../interface/UserInterface'
export const bobBaumeister: UserInterface = {
email: 'bob@baumeister.de',
firstName: 'Bob',
lastName: 'der Baumeister',
username: 'bob',
// description: 'Können wir das schaffen? Ja, wir schaffen das!',
password: BigInt('3296644341468822636'),
pubKey: Buffer.from('a509d9a146374fc975e3677db801ae8a4a83bff9dea96da64053ff6de6b2dd7e', 'hex'),
@ -14,16 +15,13 @@ export const bobBaumeister = {
createdAt: new Date('2021-11-26T11:36:31'),
emailChecked: true,
language: 'de',
disabled: false,
groupId: 1,
passphrase:
'detail master source effort unable waste tilt flush domain orchard art truck hint barrel response gate impose peanut secret merry three uncle wink resource ',
mnemonicType: 2,
isAdmin: false,
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'),
creationDate: new Date('2021-08-01 00:00:00'),
amount: 10000000,
creationTxHash: Buffer.from(
'be095dc87acb94987e71168fee8ecbf50ecb43a180b1006e75d573b35725c69c00000000000000000000000000000000',
@ -33,8 +31,4 @@ export const bobBaumeister = {
'1fbd6b9a3d359923b2501557f3bc79fa7e428127c8090fb16bc490b4d87870ab142b3817ddd902d22f0b26472a483233784a0e460c0622661752a13978903905',
'hex',
),
signaturePubkey: Buffer.from(
'7281e0ee3258b08801f3ec73e431b4519677f65c03b0382c63a913b5784ee770',
'hex',
),
}

View File

@ -1,8 +1,9 @@
export const garrickOllivander = {
import { UserInterface } from '../../interface/UserInterface'
export const garrickOllivander: UserInterface = {
email: 'garrick@ollivander.com',
firstName: 'Garrick',
lastName: 'Ollivander',
username: 'garrick',
// description: `Curious ... curious ...
// Renowned wandmaker Mr Ollivander owns the wand shop Ollivanders: Makers of Fine Wands Since 382 BC in Diagon Alley. His shop is widely considered the best place to purchase a wand.`,
password: BigInt('0'),
@ -10,11 +11,8 @@ export const garrickOllivander = {
createdAt: new Date('2022-01-10T10:23:17'),
emailChecked: false,
language: 'en',
disabled: false,
groupId: 1,
passphrase:
'human glide theory clump wish history other duty door fringe neck industry ostrich equal plate diesel tornado neck people antenna door category moon hen ',
mnemonicType: 2,
isAdmin: false,
addBalance: false,
}

View File

@ -1,8 +1,9 @@
export const peterLustig = {
import { UserInterface } from '../../interface/UserInterface'
export const peterLustig: UserInterface = {
email: 'peter@lustig.de',
firstName: 'Peter',
lastName: 'Lustig',
username: 'peter',
// description: 'Latzhose und Nickelbrille',
password: BigInt('3917921995996627700'),
pubKey: Buffer.from('7281e0ee3258b08801f3ec73e431b4519677f65c03b0382c63a913b5784ee770', 'hex'),
@ -14,11 +15,8 @@ export const peterLustig = {
createdAt: new Date('2020-11-25T10:48:43'),
emailChecked: true,
language: 'de',
disabled: false,
groupId: 1,
passphrase:
'okay property choice naive calm present weird increase stuff royal vibrant frame attend wood one else tribe pull hedgehog woman kitchen hawk snack smart ',
mnemonicType: 2,
role: 'admin',
serverUserPassword: '$2y$10$TzIWLeZoKs251gwrhSQmHeKhKI/EQ4EV5ClfAT8Ufnb4lcUXPa5X.',
activated: 1,

View File

@ -1,8 +1,9 @@
export const raeuberHotzenplotz = {
import { UserInterface } from '../../interface/UserInterface'
export const raeuberHotzenplotz: UserInterface = {
email: 'raeuber@hotzenplotz.de',
firstName: 'Räuber',
lastName: 'Hotzenplotz',
username: 'räuber',
// description: 'Pfefferpistole',
password: BigInt('12123692783243004812'),
pubKey: Buffer.from('d7c70f94234dff071d982aa8f41583876c356599773b5911b39080da2b8c2d2b', 'hex'),
@ -14,16 +15,13 @@ export const raeuberHotzenplotz = {
createdAt: new Date('2021-11-26T11:32:16'),
emailChecked: true,
language: 'de',
disabled: false,
groupId: 1,
passphrase:
'gospel trip tenant mouse spider skill auto curious man video chief response same little over expire drum display fancy clinic keen throw urge basket ',
mnemonicType: 2,
isAdmin: false,
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'),
creationDate: new Date('2021-08-01 00:00:00'),
amount: 10000000,
creationTxHash: Buffer.from(
'23ba44fd84deb59b9f32969ad0cb18bfa4588be1bdb99c396888506474c16c1900000000000000000000000000000000',
@ -33,8 +31,4 @@ export const raeuberHotzenplotz = {
'756d3da061687c575d1dbc5073908f646aa5f498b0927b217c83b48af471450e571dfe8421fb8e1f1ebd1104526b7e7c6fa78684e2da59c8f7f5a8dc3d9e5b0b',
'hex',
),
signaturePubkey: Buffer.from(
'7281e0ee3258b08801f3ec73e431b4519677f65c03b0382c63a913b5784ee770',
'hex',
),
}