mirror of
https://github.com/IT4Change/gradido.git
synced 2026-04-06 01:25:28 +00:00
Add balance for seeded users
This commit is contained in:
parent
7282330528
commit
4717b0ba4c
@ -19,6 +19,6 @@ export class Balance extends BaseEntity {
|
|||||||
amount: number
|
amount: number
|
||||||
|
|
||||||
@OneToOne(() => User, { nullable: false })
|
@OneToOne(() => User, { nullable: false })
|
||||||
@JoinColumn({ name: 'user_id' })
|
@JoinColumn({ name: 'state_user_id' })
|
||||||
user: User
|
user: User
|
||||||
}
|
}
|
||||||
|
|||||||
18
database/src/factories/balance.factory.ts
Normal file
18
database/src/factories/balance.factory.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
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
|
||||||
|
})
|
||||||
@ -60,11 +60,11 @@ const run = async (command: string) => {
|
|||||||
root: process.cwd(),
|
root: process.cwd(),
|
||||||
configName: 'ormconfig.js',
|
configName: 'ormconfig.js',
|
||||||
})
|
})
|
||||||
|
await runSeeder(DecayStartBlockSeed)
|
||||||
await runSeeder(CreatePeterLustigSeed)
|
await runSeeder(CreatePeterLustigSeed)
|
||||||
await runSeeder(CreateBibiBloxbergSeed)
|
await runSeeder(CreateBibiBloxbergSeed)
|
||||||
await runSeeder(CreateRaeuberHotzenplotzSeed)
|
await runSeeder(CreateRaeuberHotzenplotzSeed)
|
||||||
await runSeeder(CreateBobBaumeisterSeed)
|
await runSeeder(CreateBobBaumeisterSeed)
|
||||||
await runSeeder(DecayStartBlockSeed)
|
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unsupported command ${command}`)
|
throw new Error(`Unsupported command ${command}`)
|
||||||
|
|||||||
@ -27,4 +27,10 @@ export interface UserInterface {
|
|||||||
modified?: Date
|
modified?: Date
|
||||||
// flag for admin
|
// flag for admin
|
||||||
isAdmin?: boolean
|
isAdmin?: boolean
|
||||||
|
// flag for balance
|
||||||
|
addBalance?: boolean
|
||||||
|
// balance
|
||||||
|
balanceModified?: Date
|
||||||
|
recordDate?: Date
|
||||||
|
amount?: number
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,16 +5,18 @@ import {
|
|||||||
ServerUserContext,
|
ServerUserContext,
|
||||||
LoginUserRolesContext,
|
LoginUserRolesContext,
|
||||||
} from '../../interface/UserContext'
|
} from '../../interface/UserContext'
|
||||||
|
import { BalanceContext } from '../../interface/TransactionContext'
|
||||||
import { UserInterface } from '../../interface/UserInterface'
|
import { UserInterface } from '../../interface/UserInterface'
|
||||||
import { User } from '../../../entity/User'
|
import { User } from '../../../entity/User'
|
||||||
import { LoginUser } from '../../../entity/LoginUser'
|
import { LoginUser } from '../../../entity/LoginUser'
|
||||||
import { LoginUserBackup } from '../../../entity/LoginUserBackup'
|
import { LoginUserBackup } from '../../../entity/LoginUserBackup'
|
||||||
import { ServerUser } from '../../../entity/ServerUser'
|
import { ServerUser } from '../../../entity/ServerUser'
|
||||||
import { LoginUserRoles } from '../../../entity/LoginUserRoles'
|
import { LoginUserRoles } from '../../../entity/LoginUserRoles'
|
||||||
|
import { Balance } from '../../../entity/Balance'
|
||||||
import { Factory } from 'typeorm-seeding'
|
import { Factory } from 'typeorm-seeding'
|
||||||
|
|
||||||
export const userSeeder = async (factory: Factory, userData: UserInterface): Promise<void> => {
|
export const userSeeder = async (factory: Factory, userData: UserInterface): Promise<void> => {
|
||||||
await factory(User)(createUserContext(userData)).create()
|
const user = await factory(User)(createUserContext(userData)).create()
|
||||||
const loginUser = await factory(LoginUser)(createLoginUserContext(userData)).create()
|
const loginUser = await factory(LoginUser)(createLoginUserContext(userData)).create()
|
||||||
await factory(LoginUserBackup)(createLoginUserBackupContext(userData, loginUser)).create()
|
await factory(LoginUserBackup)(createLoginUserBackupContext(userData, loginUser)).create()
|
||||||
|
|
||||||
@ -25,9 +27,13 @@ export const userSeeder = async (factory: Factory, userData: UserInterface): Pro
|
|||||||
// It works with LoginRoles empty!!
|
// It works with LoginRoles empty!!
|
||||||
await factory(LoginUserRoles)(createLoginUserRolesContext(loginUser)).create()
|
await factory(LoginUserRoles)(createLoginUserRolesContext(loginUser)).create()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (userData.addBalance) {
|
||||||
|
await factory(Balance)(createBalanceContext(userData, user)).create()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createUserContext = (context: UserInterface): UserContext => {
|
const createUserContext = (context: UserInterface): UserContext => {
|
||||||
return {
|
return {
|
||||||
pubkey: context.pubKey,
|
pubkey: context.pubKey,
|
||||||
email: context.email,
|
email: context.email,
|
||||||
@ -38,7 +44,7 @@ export const createUserContext = (context: UserInterface): UserContext => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createLoginUserContext = (context: UserInterface): LoginUserContext => {
|
const createLoginUserContext = (context: UserInterface): LoginUserContext => {
|
||||||
return {
|
return {
|
||||||
email: context.email,
|
email: context.email,
|
||||||
firstName: context.firstName,
|
firstName: context.firstName,
|
||||||
@ -59,7 +65,7 @@ export const createLoginUserContext = (context: UserInterface): LoginUserContext
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createLoginUserBackupContext = (
|
const createLoginUserBackupContext = (
|
||||||
context: UserInterface,
|
context: UserInterface,
|
||||||
loginUser: LoginUser,
|
loginUser: LoginUser,
|
||||||
): LoginUserBackupContext => {
|
): LoginUserBackupContext => {
|
||||||
@ -70,7 +76,7 @@ export const createLoginUserBackupContext = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createServerUserContext = (context: UserInterface): ServerUserContext => {
|
const createServerUserContext = (context: UserInterface): ServerUserContext => {
|
||||||
return {
|
return {
|
||||||
role: context.role,
|
role: context.role,
|
||||||
username: context.username,
|
username: context.username,
|
||||||
@ -83,9 +89,18 @@ export const createServerUserContext = (context: UserInterface): ServerUserConte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createLoginUserRolesContext = (loginUser: LoginUser): LoginUserRolesContext => {
|
const createLoginUserRolesContext = (loginUser: LoginUser): LoginUserRolesContext => {
|
||||||
return {
|
return {
|
||||||
userId: loginUser.id,
|
userId: loginUser.id,
|
||||||
roleId: 1,
|
roleId: 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const createBalanceContext = (context: UserInterface, user: User): BalanceContext => {
|
||||||
|
return {
|
||||||
|
modified: context.balanceModified,
|
||||||
|
recordDate: context.recordDate,
|
||||||
|
amount: context.amount,
|
||||||
|
user,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -22,4 +22,8 @@ export const bibiBloxberg = {
|
|||||||
'knife normal level all hurdle crucial color avoid warrior stadium road bachelor affair topple hawk pottery right afford immune two ceiling budget glance hour ',
|
'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,
|
mnemonicType: 2,
|
||||||
isAdmin: false,
|
isAdmin: false,
|
||||||
|
addBalance: true,
|
||||||
|
balanceModified: new Date('2021-11-30T10:37:11'),
|
||||||
|
recordDate: new Date('2021-11-30T10:37:11'),
|
||||||
|
amount: 10000000,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,4 +22,8 @@ export const bobBaumeister = {
|
|||||||
'detail master source effort unable waste tilt flush domain orchard art truck hint barrel response gate impose peanut secret merry three uncle wink resource ',
|
'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,
|
mnemonicType: 2,
|
||||||
isAdmin: false,
|
isAdmin: false,
|
||||||
|
addBalance: true,
|
||||||
|
balanceModified: new Date('2021-11-30T10:37:14'),
|
||||||
|
recordDate: new Date('2021-11-30T10:37:14'),
|
||||||
|
amount: 10000000,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,4 +22,8 @@ export const raeuberHotzenplotz = {
|
|||||||
'gospel trip tenant mouse spider skill auto curious man video chief response same little over expire drum display fancy clinic keen throw urge basket ',
|
'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,
|
mnemonicType: 2,
|
||||||
isAdmin: false,
|
isAdmin: false,
|
||||||
|
addBalance: true,
|
||||||
|
balanceModified: new Date('2021-11-30T10:37:13'),
|
||||||
|
recordDate: new Date('2021-11-30T10:37:13'),
|
||||||
|
amount: 10000000,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user