diff --git a/database/src/factories/login-user.factory.ts b/database/src/factories/login-user.factory.ts deleted file mode 100644 index b3c0312f3..000000000 --- a/database/src/factories/login-user.factory.ts +++ /dev/null @@ -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 -}) diff --git a/database/src/factories/user.factory.ts b/database/src/factories/user.factory.ts index 1f684f23f..338a854f1 100644 --- a/database/src/factories/user.factory.ts +++ b/database/src/factories/user.factory.ts @@ -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 }) diff --git a/database/src/interface/UserContext.ts b/database/src/interface/UserContext.ts index eb4323aee..a23a50109 100644 --- a/database/src/interface/UserContext.ts +++ b/database/src/interface/UserContext.ts @@ -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 } diff --git a/database/src/interface/UserInterface.ts b/database/src/interface/UserInterface.ts index 63804af6b..235dd2dd0 100644 --- a/database/src/interface/UserInterface.ts +++ b/database/src/interface/UserInterface.ts @@ -1,5 +1,6 @@ export interface UserInterface { - // from login user (contains state user) + // from user + loginUserId?: number email?: string firstName?: string lastName?: string diff --git a/database/src/seeds/helpers/user-helpers.ts b/database/src/seeds/helpers/user-helpers.ts index f205ccb00..2d0b7788b 100644 --- a/database/src/seeds/helpers/user-helpers.ts +++ b/database/src/seeds/helpers/user-helpers.ts @@ -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 => { 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).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, diff --git a/database/src/seeds/users/bibi-bloxberg.ts b/database/src/seeds/users/bibi-bloxberg.ts index 221349cb7..86fae0300 100644 --- a/database/src/seeds/users/bibi-bloxberg.ts +++ b/database/src/seeds/users/bibi-bloxberg.ts @@ -1,4 +1,5 @@ export const bibiBloxberg = { + loginUserId: 1, email: 'bibi@bloxberg.de', firstName: 'Bibi', lastName: 'Bloxberg', diff --git a/database/src/seeds/users/bob-baumeister.ts b/database/src/seeds/users/bob-baumeister.ts index 013636079..a42993a1d 100644 --- a/database/src/seeds/users/bob-baumeister.ts +++ b/database/src/seeds/users/bob-baumeister.ts @@ -1,4 +1,5 @@ export const bobBaumeister = { + loginUserId: 2, email: 'bob@baumeister.de', firstName: 'Bob', lastName: 'der Baumeister', diff --git a/database/src/seeds/users/garrick-ollivander.ts b/database/src/seeds/users/garrick-ollivander.ts index 1c7bbb9fc..d84cd02db 100644 --- a/database/src/seeds/users/garrick-ollivander.ts +++ b/database/src/seeds/users/garrick-ollivander.ts @@ -1,4 +1,5 @@ export const garrickOllivander = { + loginUserId: 3, email: 'garrick@ollivander.com', firstName: 'Garrick', lastName: 'Ollivander', diff --git a/database/src/seeds/users/peter-lustig.ts b/database/src/seeds/users/peter-lustig.ts index c96b28a65..96b44cda4 100644 --- a/database/src/seeds/users/peter-lustig.ts +++ b/database/src/seeds/users/peter-lustig.ts @@ -1,4 +1,5 @@ export const peterLustig = { + loginUserId: 4, email: 'peter@lustig.de', firstName: 'Peter', lastName: 'Lustig', diff --git a/database/src/seeds/users/raeuber-hotzenplotz.ts b/database/src/seeds/users/raeuber-hotzenplotz.ts index c1f31b490..0df964167 100644 --- a/database/src/seeds/users/raeuber-hotzenplotz.ts +++ b/database/src/seeds/users/raeuber-hotzenplotz.ts @@ -1,4 +1,5 @@ export const raeuberHotzenplotz = { + loginUserId: 5, email: 'raeuber@hotzenplotz.de', firstName: 'Räuber', lastName: 'Hotzenplotz',