mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
further refactoring
This commit is contained in:
parent
e2f8de0acb
commit
ae8fc914fb
@ -12,7 +12,6 @@
|
||||
"clean": "tsc --build --clean",
|
||||
"up": "cd build && node src/index.js up",
|
||||
"down": "cd build && node src/index.js down",
|
||||
"reset": "cd build && node src/index.js reset",
|
||||
"dev_up": "nodemon -w ./ --ext ts --exec ts-node src/index.ts up",
|
||||
"dev_down": "nodemon -w ./ --ext ts --exec ts-node src/index.ts down",
|
||||
"dev_reset": "nodemon -w ./ --ext ts --exec ts-node src/index.ts reset",
|
||||
|
||||
@ -47,9 +47,11 @@ const run = async (command: string) => {
|
||||
await migration.down() // use for downgrade script
|
||||
break
|
||||
case 'reset':
|
||||
// TODO protect from production
|
||||
await migration.reset() // use for resetting database
|
||||
break
|
||||
case 'seed':
|
||||
// TODO protect from production
|
||||
await useSeeding({
|
||||
root: process.cwd(),
|
||||
configName: 'ormconfig.js',
|
||||
|
||||
@ -6,7 +6,26 @@ import {
|
||||
LoginUserRolesContext,
|
||||
} from '../../interface/UserContext'
|
||||
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 { LoginUserRoles } from '../../../entity/LoginUserRoles'
|
||||
import { Factory } from 'typeorm-seeding'
|
||||
|
||||
export const userSeeder = async (factory: Factory, userData: UserInterface): Promise<void> => {
|
||||
await factory(User)(createUserContext(userData)).create()
|
||||
const loginUser = await factory(LoginUser)(createLoginUserContext(userData)).create()
|
||||
await factory(LoginUserBackup)(createLoginUserBackupContext(userData, loginUser)).create()
|
||||
|
||||
if (userData.isAdmin) {
|
||||
await factory(ServerUser)(createServerUserContext(userData)).create()
|
||||
|
||||
// This is crazy: we just need the relation to roleId but no role at all
|
||||
// It works with LoginRoles empty!!
|
||||
await factory(LoginUserRoles)(createLoginUserRolesContext(loginUser)).create()
|
||||
}
|
||||
}
|
||||
|
||||
export const createUserContext = (context: UserInterface): UserContext => {
|
||||
return {
|
||||
|
||||
@ -1,32 +1,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 { LoginUserRoles } from '../../../entity/LoginUserRoles'
|
||||
import {
|
||||
createUserContext,
|
||||
createLoginUserContext,
|
||||
createLoginUserBackupContext,
|
||||
createServerUserContext,
|
||||
createLoginUserRolesContext,
|
||||
} from '../helpers/user-helpers'
|
||||
import { peterLustig } from './peter-lustig'
|
||||
|
||||
const userData = peterLustig
|
||||
|
||||
export class CreatePeterLustigSeed implements Seeder {
|
||||
public async run(factory: Factory): Promise<void> {
|
||||
await factory(User)(createUserContext(userData)).create()
|
||||
const loginUser = await factory(LoginUser)(createLoginUserContext(userData)).create()
|
||||
await factory(LoginUserBackup)(createLoginUserBackupContext(userData, loginUser)).create()
|
||||
|
||||
if (userData.isAdmin) {
|
||||
await factory(ServerUser)(createServerUserContext(userData)).create()
|
||||
|
||||
// This is crazy: we just need the relation to roleId but no role at all
|
||||
// It works with LoginRoles empty!!
|
||||
await factory(LoginUserRoles)(createLoginUserRolesContext(loginUser)).create()
|
||||
}
|
||||
await userSeeder(factory, peterLustig)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user