parent
67ba489fe2
commit
9df9d9ae80
|
@ -0,0 +1,73 @@
|
|||
import { Connection } from 'typeorm';
|
||||
import { Factory, Seeder } from 'typeorm-seeding';
|
||||
import { CreateRunner } from '../models/actions/create/CreateRunner';
|
||||
import { CreateRunnerOrganisation } from '../models/actions/create/CreateRunnerOrganisation';
|
||||
import { CreateRunnerTeam } from '../models/actions/create/CreateRunnerTeam';
|
||||
import { Address } from '../models/entities/Address';
|
||||
import { Runner } from '../models/entities/Runner';
|
||||
import { RunnerGroup } from '../models/entities/RunnerGroup';
|
||||
import { RunnerOrganisation } from '../models/entities/RunnerOrganisation';
|
||||
import { RunnerTeam } from '../models/entities/RunnerTeam';
|
||||
|
||||
/**
|
||||
* Seeds a test runner org with a test runner team ans some test runners.
|
||||
* Usefull for testing or demo instances.
|
||||
*/
|
||||
export default class SeedTestRunners implements Seeder {
|
||||
public async run(factory: Factory, connection: Connection): Promise<any> {
|
||||
let testOrg: RunnerOrganisation = await this.createTestOrg(connection);
|
||||
let testTeam: RunnerTeam = await this.createTestTeam(connection, testOrg);
|
||||
await this.createTestRunners(connection, testTeam);
|
||||
}
|
||||
|
||||
public async createTestOrg(connection: Connection): Promise<RunnerOrganisation> {
|
||||
let testOrg = new CreateRunnerOrganisation();
|
||||
testOrg.name = "Test Org";
|
||||
|
||||
testOrg.address = new Address();
|
||||
testOrg.address.address1 = "Test street 1";
|
||||
testOrg.address.city = "Herzogenaurach";
|
||||
testOrg.address.country = "Germany";
|
||||
testOrg.address.postalcode = "90174";
|
||||
|
||||
return await connection.getRepository(RunnerOrganisation).save(await testOrg.toEntity());
|
||||
}
|
||||
|
||||
public async createTestTeam(connection: Connection, org: RunnerOrganisation): Promise<RunnerTeam> {
|
||||
let testTeam = new CreateRunnerTeam();
|
||||
testTeam.name = "Test Team";
|
||||
testTeam.parentGroup = org.id;
|
||||
|
||||
return await connection.getRepository(RunnerTeam).save(await testTeam.toEntity());
|
||||
}
|
||||
|
||||
public async createTestRunners(connection: Connection, group: RunnerGroup) {
|
||||
for (let first of this.firstnames) {
|
||||
for (let last of this.lastnames) {
|
||||
let runner = new CreateRunner;
|
||||
runner.firstname = first;
|
||||
runner.lastname = last;
|
||||
runner.middlename = group.name;
|
||||
runner.group = group.id;
|
||||
await connection.getRepository(Runner).save(await runner.toEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private firstnames = [
|
||||
"Peter",
|
||||
"Matze",
|
||||
"Tine",
|
||||
"Uta",
|
||||
"Fabian",
|
||||
"Unicode:ÖÄ?✔⚠"
|
||||
]
|
||||
|
||||
private lastnames = [
|
||||
"Muster",
|
||||
"Example",
|
||||
"Müller",
|
||||
"Unicode:搆Ǩ>ÙՠƳ|"
|
||||
]
|
||||
|
||||
}
|
Loading…
Reference in New Issue