seed peter lustig as admin

This commit is contained in:
Moriz Wahl 2021-11-26 09:47:13 +01:00
parent 2ca75ba8fc
commit 56e95718e1
8 changed files with 65 additions and 11 deletions

View File

@ -8,8 +8,8 @@ export class ServerUser extends BaseEntity {
@Column({ length: 50 })
username: string
@Column({ type: 'bigint', unsigned: true })
password: BigInt
@Column({ length: 255 })
password: string
@Column({ length: 50, unique: true })
email: string
@ -23,9 +23,9 @@ export class ServerUser extends BaseEntity {
@Column({ name: 'last_login', default: null, nullable: true })
lastLogin: Date
@Column({ name: 'created', default: () => 'CURRENT_TIMESTAMP' })
@Column({ default: () => 'CURRENT_TIMESTAMP' })
created: Date
@Column({ name: 'created', default: () => 'CURRENT_TIMESTAMP' })
@Column({ default: () => 'CURRENT_TIMESTAMP' })
modified: Date
}

View File

@ -0,0 +1,13 @@
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column } from 'typeorm'
@Entity('login_user_roles')
export class LoginUserRoles extends BaseEntity {
@PrimaryGeneratedColumn('increment', { unsigned: true })
id: number
@Column({ name: 'user_id' })
userId: number
@Column({ name: 'role_id' })
roleId: number
}

View File

@ -0,0 +1 @@
export { LoginUserRoles } from './0003-login_server_tables/LoginUserRoles'

View File

@ -2,6 +2,7 @@ import { Balance } from './Balance'
import { LoginElopageBuys } from './LoginElopageBuys'
import { LoginEmailOptIn } from './LoginEmailOptIn'
import { LoginUser } from './LoginUser'
import { LoginUserRoles } from './LoginUserRoles'
import { LoginUserBackup } from './LoginUserBackup'
import { Migration } from './Migration'
import { ServerUser } from './ServerUser'
@ -17,6 +18,7 @@ export const entities = [
LoginElopageBuys,
LoginEmailOptIn,
LoginUser,
LoginUserRoles,
LoginUserBackup,
Migration,
ServerUser,

View File

@ -10,7 +10,7 @@ interface LoginUserBackupContext {
define(LoginUserBackup, (faker: typeof Faker, context?: LoginUserBackupContext) => {
if (!context) context = {}
if (!context.userId) throw new Error('LoginUserBackup: No iserId present!')
if (!context.userId) throw new Error('LoginUserBackup: No userId present!')
const userBackup = new LoginUserBackup()
// TODO: Get the real passphrase

View File

@ -0,0 +1,20 @@
import Faker from 'faker'
import { define } from 'typeorm-seeding'
import { LoginUserRoles } from '../../entity/LoginUserRoles'
interface LoginUserRolesContext {
userId?: number
roleId?: number
}
define(LoginUserRoles, (faker: typeof Faker, context?: LoginUserRolesContext) => {
if (!context) context = {}
if (!context.userId) throw new Error('LoginUserRoles: No userId present!')
if (!context.roleId) throw new Error('LoginUserRoles: No roleId present!')
const userRoles = new LoginUserRoles()
userRoles.userId = context.userId
userRoles.roleId = context.roleId
return userRoles
})

View File

@ -4,7 +4,7 @@ import { ServerUser } from '../../entity/ServerUser'
interface ServerUserContext {
username?: string
password?: BigInt
password?: string
email?: string
role?: string
activated?: number
@ -18,7 +18,7 @@ define(ServerUser, (faker: typeof Faker, context?: ServerUserContext) => {
const user = new ServerUser()
user.username = context.username ? context.username : faker.internet.userName()
user.password = context.password ? context.password : BigInt(0)
user.password = context.password ? context.password : faker.internet.password()
user.email = context.email ? context.email : faker.internet.email()
user.role = context.role ? context.role : 'admin'
user.activated = context.activated ? context.activated : 0

View File

@ -2,7 +2,8 @@ import { Factory, Seeder } from 'typeorm-seeding'
import { User } from '../../../entity/User'
import { LoginUser } from '../../../entity/LoginUser'
import { LoginUserBackup } from '../../../entity/LoginUserBackup'
// import { ServerUser } from '../../../entity/ServerUser'
import { ServerUser } from '../../../entity/ServerUser'
import { LoginUserRoles } from '../../../entity/LoginUserRoles'
const peterLustig = {
email: 'peter@lustig.de',
@ -17,7 +18,7 @@ const peterLustig = {
'hex',
),
emailHash: Buffer.from('9f700e6f6ec351a140b674c0edd4479509697b023bd8bee8826915ef6c2af036', 'hex'),
createdAt: new Date('2021-11-25T10:48:43'),
createdAt: new Date('2020-11-25T10:48:43'),
emailChecked: true,
passphraseShown: false,
language: 'de',
@ -28,9 +29,10 @@ const peterLustig = {
'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',
activated: 0,
serverUserPassword: '$2y$10$TzIWLeZoKs251gwrhSQmHeKhKI/EQ4EV5ClfAT8Ufnb4lcUXPa5X.',
activated: 1,
lastLogin: new Date('2021-10-27T12:25:57'),
modified: new Date('2021-10-27T12:25:57'),
modified: new Date('2021-09-27T12:25:57'),
isAdmin: true,
}
@ -69,5 +71,21 @@ export class CreatePeterLustigSeed implements Seeder {
mnemonicType: peterLustig.mnemonicType,
userId: loginUser.id,
}).create()
await factory(ServerUser)({
role: peterLustig.role,
username: peterLustig.username,
password: peterLustig.serverUserPassword,
email: peterLustig.email,
activated: peterLustig.activated,
created: peterLustig.createdAt,
lastLogin: peterLustig.lastLogin,
modified: peterLustig.modified,
}).create()
await factory(LoginUserRoles)({
userId: loginUser.id,
roleId: 1,
}).create()
}
}