mirror of
https://github.com/IT4Change/gradido.git
synced 2026-03-01 12:44:43 +00:00
fixed seed (untested, just building)
This commit is contained in:
parent
d7cd4d32c0
commit
fa7c782672
@ -1,30 +0,0 @@
|
||||
import Faker from 'faker'
|
||||
import { define } from 'typeorm-seeding'
|
||||
import { LoginUser } from '../../entity/LoginUser'
|
||||
import { randomBytes } from 'crypto'
|
||||
import { LoginUserContext } from '../interface/UserContext'
|
||||
|
||||
define(LoginUser, (faker: typeof Faker, context?: LoginUserContext) => {
|
||||
if (!context) context = {}
|
||||
|
||||
const user = new LoginUser()
|
||||
user.email = context.email ? context.email : faker.internet.email()
|
||||
user.firstName = context.firstName ? context.firstName : faker.name.firstName()
|
||||
user.lastName = context.lastName ? context.lastName : faker.name.lastName()
|
||||
user.username = context.username ? context.username : faker.internet.userName()
|
||||
user.description = context.description ? context.description : faker.random.words(4)
|
||||
// TODO Create real password and keys/hash
|
||||
user.password = context.password ? context.password : BigInt(0)
|
||||
user.pubKey = context.pubKey ? context.pubKey : randomBytes(32)
|
||||
user.privKey = context.privKey ? context.privKey : randomBytes(80)
|
||||
user.emailHash = context.emailHash ? context.emailHash : randomBytes(32)
|
||||
user.createdAt = context.createdAt ? context.createdAt : faker.date.recent()
|
||||
user.emailChecked = context.emailChecked === undefined ? false : context.emailChecked
|
||||
user.passphraseShown = context.passphraseShown ? context.passphraseShown : false
|
||||
user.language = context.language ? context.language : 'en'
|
||||
user.disabled = context.disabled ? context.disabled : false
|
||||
user.groupId = context.groupId ? context.groupId : 1
|
||||
user.publisherId = context.publisherId ? context.publisherId : 0
|
||||
|
||||
return user
|
||||
})
|
||||
@ -1,21 +1,31 @@
|
||||
import Faker from 'faker'
|
||||
import { define } from 'typeorm-seeding'
|
||||
import { User } from '../../entity/User'
|
||||
import { randomBytes } from 'crypto'
|
||||
import { randomBytes, randomInt } from 'crypto'
|
||||
import { UserContext } from '../interface/UserContext'
|
||||
|
||||
define(User, (faker: typeof Faker, context?: UserContext) => {
|
||||
if (!context) context = {}
|
||||
|
||||
const user = new User()
|
||||
user.pubkey = context.pubkey ? context.pubkey : randomBytes(32)
|
||||
user.pubKey = context.pubKey ? context.pubKey : randomBytes(32)
|
||||
user.email = context.email ? context.email : faker.internet.email()
|
||||
user.firstName = context.firstName ? context.firstName : faker.name.firstName()
|
||||
user.lastName = context.lastName ? context.lastName : faker.name.lastName()
|
||||
user.username = context.username ? context.username : faker.internet.userName()
|
||||
user.disabled = context.disabled ? context.disabled : false
|
||||
user.groupId = 0
|
||||
user.loginUserId = context.loginUserId ? context.loginUserId : randomInt(999999)
|
||||
user.indexId = 0
|
||||
user.description = context.description ? context.description : faker.random.words(4)
|
||||
// TODO Create real password and keys/hash
|
||||
user.password = context.password ? context.password : BigInt(0)
|
||||
user.privKey = context.privKey ? context.privKey : randomBytes(80)
|
||||
user.emailHash = context.emailHash ? context.emailHash : randomBytes(32)
|
||||
user.createdAt = context.createdAt ? context.createdAt : faker.date.recent()
|
||||
user.emailChecked = context.emailChecked === undefined ? false : context.emailChecked
|
||||
user.passphraseShown = context.passphraseShown ? context.passphraseShown : false
|
||||
user.language = context.language ? context.language : 'en'
|
||||
user.publisherId = context.publisherId ? context.publisherId : 0
|
||||
|
||||
return user
|
||||
})
|
||||
|
||||
@ -1,28 +1,19 @@
|
||||
export interface UserContext {
|
||||
pubkey?: Buffer
|
||||
loginUserId?: number
|
||||
pubKey?: Buffer
|
||||
email?: string
|
||||
firstName?: string
|
||||
lastName?: string
|
||||
username?: string
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
export interface LoginUserContext {
|
||||
email?: string
|
||||
firstName?: string
|
||||
lastName?: string
|
||||
username?: string
|
||||
description?: string
|
||||
password?: BigInt
|
||||
pubKey?: Buffer
|
||||
privKey?: Buffer
|
||||
emailHash?: Buffer
|
||||
createdAt?: Date
|
||||
emailChecked?: boolean
|
||||
passphraseShown?: boolean
|
||||
language?: string
|
||||
disabled?: boolean
|
||||
groupId?: number
|
||||
publisherId?: number
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
export interface UserInterface {
|
||||
// from login user (contains state user)
|
||||
// from user
|
||||
loginUserId?: number
|
||||
email?: string
|
||||
firstName?: string
|
||||
lastName?: string
|
||||
|
||||
@ -1,10 +1,4 @@
|
||||
import {
|
||||
UserContext,
|
||||
LoginUserContext,
|
||||
LoginUserBackupContext,
|
||||
ServerUserContext,
|
||||
LoginUserRolesContext,
|
||||
} from '../../interface/UserContext'
|
||||
import { UserContext, LoginUserBackupContext, ServerUserContext } from '../../interface/UserContext'
|
||||
import {
|
||||
BalanceContext,
|
||||
TransactionContext,
|
||||
@ -13,7 +7,6 @@ import {
|
||||
} from '../../interface/TransactionContext'
|
||||
import { UserInterface } from '../../interface/UserInterface'
|
||||
import { User } from '../../../entity/User'
|
||||
import { LoginUser } from '../../../entity/LoginUser'
|
||||
import { LoginUserBackup } from '../../../entity/LoginUserBackup'
|
||||
import { ServerUser } from '../../../entity/ServerUser'
|
||||
import { Balance } from '../../../entity/Balance'
|
||||
@ -24,9 +17,9 @@ import { Factory } from 'typeorm-seeding'
|
||||
|
||||
export const userSeeder = async (factory: Factory, userData: UserInterface): Promise<void> => {
|
||||
const user = await factory(User)(createUserContext(userData)).create()
|
||||
if (!userData.email) userData.email = user.email
|
||||
const loginUser = await factory(LoginUser)(createLoginUserContext(userData)).create()
|
||||
await factory(LoginUserBackup)(createLoginUserBackupContext(userData, loginUser)).create()
|
||||
await factory(LoginUserBackup)(
|
||||
createLoginUserBackupContext(userData, (<User>user).loginUserId),
|
||||
).create()
|
||||
|
||||
if (userData.isAdmin) {
|
||||
await factory(ServerUser)(createServerUserContext(userData)).create()
|
||||
@ -49,44 +42,33 @@ export const userSeeder = async (factory: Factory, userData: UserInterface): Pro
|
||||
|
||||
const createUserContext = (context: UserInterface): UserContext => {
|
||||
return {
|
||||
pubkey: context.pubKey,
|
||||
pubKey: context.pubKey,
|
||||
email: context.email,
|
||||
loginUserId: context.loginUserId,
|
||||
firstName: context.firstName,
|
||||
lastName: context.lastName,
|
||||
username: context.username,
|
||||
disabled: context.disabled,
|
||||
}
|
||||
}
|
||||
|
||||
const createLoginUserContext = (context: UserInterface): LoginUserContext => {
|
||||
return {
|
||||
email: context.email,
|
||||
firstName: context.firstName,
|
||||
lastName: context.lastName,
|
||||
username: context.username,
|
||||
description: context.description,
|
||||
password: context.password,
|
||||
pubKey: context.pubKey,
|
||||
privKey: context.privKey,
|
||||
emailHash: context.emailHash,
|
||||
createdAt: context.createdAt,
|
||||
emailChecked: context.emailChecked,
|
||||
passphraseShown: context.passphraseShown,
|
||||
language: context.language,
|
||||
disabled: context.disabled,
|
||||
groupId: context.groupId,
|
||||
publisherId: context.publisherId,
|
||||
}
|
||||
}
|
||||
|
||||
const createLoginUserBackupContext = (
|
||||
context: UserInterface,
|
||||
loginUser: LoginUser,
|
||||
loginUserId: number,
|
||||
): LoginUserBackupContext => {
|
||||
return {
|
||||
passphrase: context.passphrase,
|
||||
mnemonicType: context.mnemonicType,
|
||||
userId: loginUser.id,
|
||||
userId: loginUserId,
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,13 +85,6 @@ const createServerUserContext = (context: UserInterface): ServerUserContext => {
|
||||
}
|
||||
}
|
||||
|
||||
const createLoginUserRolesContext = (loginUser: LoginUser): LoginUserRolesContext => {
|
||||
return {
|
||||
userId: loginUser.id,
|
||||
roleId: 1,
|
||||
}
|
||||
}
|
||||
|
||||
const createBalanceContext = (context: UserInterface, user: User): BalanceContext => {
|
||||
return {
|
||||
modified: context.balanceModified,
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
export const bibiBloxberg = {
|
||||
loginUserId: 1,
|
||||
email: 'bibi@bloxberg.de',
|
||||
firstName: 'Bibi',
|
||||
lastName: 'Bloxberg',
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
export const bobBaumeister = {
|
||||
loginUserId: 2,
|
||||
email: 'bob@baumeister.de',
|
||||
firstName: 'Bob',
|
||||
lastName: 'der Baumeister',
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
export const garrickOllivander = {
|
||||
loginUserId: 3,
|
||||
email: 'garrick@ollivander.com',
|
||||
firstName: 'Garrick',
|
||||
lastName: 'Ollivander',
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
export const peterLustig = {
|
||||
loginUserId: 4,
|
||||
email: 'peter@lustig.de',
|
||||
firstName: 'Peter',
|
||||
lastName: 'Lustig',
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
export const raeuberHotzenplotz = {
|
||||
loginUserId: 5,
|
||||
email: 'raeuber@hotzenplotz.de',
|
||||
firstName: 'Räuber',
|
||||
lastName: 'Hotzenplotz',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user