Merge branch 'dev' into feature/111-runner_selfservic_info
All checks were successful
continuous-integration/drone/pr Build is passing
All checks were successful
continuous-integration/drone/pr Build is passing
This commit is contained in:
commit
0355bdbbab
@ -6,4 +6,5 @@ DB_USER=bla
|
||||
DB_PASSWORD=bla
|
||||
DB_NAME=bla
|
||||
NODE_ENV=production
|
||||
POSTALCODE_COUNTRYCODE=DE
|
||||
POSTALCODE_COUNTRYCODE=DE
|
||||
SEED_TEST_DATA=false
|
17
CHANGELOG.md
17
CHANGELOG.md
@ -2,8 +2,25 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. Dates are displayed in UTC.
|
||||
|
||||
#### [v0.2.0](https://git.odit.services/lfk/backend/compare/v0.2.0...v0.2.0)
|
||||
|
||||
- Merge pull request 'Implemented more seeding feature/110-seeding' (#114) from feature/110-seeding into dev [`886c109`](https://git.odit.services/lfk/backend/commit/886c1092d60f8e39357e3b841ed01bb082ede2c4)
|
||||
- Added a seeder for runner test data [`9df9d9a`](https://git.odit.services/lfk/backend/commit/9df9d9ae80277d5ccc753639badb48c4afb13088)
|
||||
- Added key-value like db table for config flags [`b15967f`](https://git.odit.services/lfk/backend/commit/b15967ff3162e9fe3a634a6f4fc5669f2314cc21)
|
||||
- Now creating a test contact [`1837336`](https://git.odit.services/lfk/backend/commit/1837336865893ca39d3bc628ff3c57e018a8555d)
|
||||
- The data seeding now only get's triggered on the first time thx to using the key-value [`7bc6030`](https://git.odit.services/lfk/backend/commit/7bc603028dc60d26ffc5327868afbce512966d4d)
|
||||
- Added a citizen org seeder [`2db6510`](https://git.odit.services/lfk/backend/commit/2db6510a8ad83300b286a3bd35ca4db103da72d1)
|
||||
- 📖New license file version [CI SKIP] [skip ci] [`d8b6669`](https://git.odit.services/lfk/backend/commit/d8b6669d126e64d9e434b5f841ae17a02117822b)
|
||||
- Fixed the bool converter for null values [`e12aedd`](https://git.odit.services/lfk/backend/commit/e12aedd1aad6de1f934e9593dda4607a303b2eb5)
|
||||
- Added a config option for test data seeding [`67ba489`](https://git.odit.services/lfk/backend/commit/67ba489fe2f2a2706d640a668cd0e675ded6a7df)
|
||||
- SEED_TEST_DATA is now false by default [`8870ebd`](https://git.odit.services/lfk/backend/commit/8870ebdb5e6d9045222440abc2c047929a74b520)
|
||||
- Added bool conversion for testdata seeding env var [`c18012f`](https://git.odit.services/lfk/backend/commit/c18012f65a704e07acd56870c9ed9f6d06cf97a9)
|
||||
- Now also seeding runners to the test org [`eab0e63`](https://git.odit.services/lfk/backend/commit/eab0e634a26c1a80e7fa2ccb9dc368f0760b2fd8)
|
||||
|
||||
#### [v0.2.0](https://git.odit.services/lfk/backend/compare/v0.1.1...v0.2.0)
|
||||
|
||||
> 20 January 2021
|
||||
|
||||
- Merge pull request 'Alpha Release 0.2.0' (#109) from dev into main [`dd3d93e`](https://git.odit.services/lfk/backend/commit/dd3d93edc7db7ca7f133cb2d8f60c3eaf30bcbf0)
|
||||
- Updated contact update tests [`c3d008e`](https://git.odit.services/lfk/backend/commit/c3d008ec0ff92f80addbdb93ffc1fa2b3278a8a6)
|
||||
- Added contact delete tests [`dd7e5da`](https://git.odit.services/lfk/backend/commit/dd7e5dae368a8decd79357f658dda2164fa6f1e7)
|
||||
|
@ -9,7 +9,8 @@ export const config = {
|
||||
jwt_secret: process.env.JWT_SECRET || "secretjwtsecret",
|
||||
phone_validation_countrycode: getPhoneCodeLocale(),
|
||||
postalcode_validation_countrycode: getPostalCodeLocale(),
|
||||
version: process.env.VERSION || require('../package.json').version
|
||||
version: process.env.VERSION || require('../package.json').version,
|
||||
seedTestData: getDataSeeding()
|
||||
}
|
||||
let errors = 0
|
||||
if (typeof config.internal_port !== "number") {
|
||||
@ -30,4 +31,11 @@ function getPostalCodeLocale(): any {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
function getDataSeeding(): Boolean {
|
||||
try {
|
||||
return JSON.parse(process.env.SEED_TEST_DATA);
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export let e = errors
|
@ -1,6 +1,9 @@
|
||||
import { createConnection } from "typeorm";
|
||||
import { runSeeder } from 'typeorm-seeding';
|
||||
import { User } from '../models/entities/User';
|
||||
import { config } from '../config';
|
||||
import { ConfigFlag } from '../models/entities/ConfigFlags';
|
||||
import SeedPublicOrg from '../seeds/SeedPublicOrg';
|
||||
import SeedTestRunners from '../seeds/SeedTestRunners';
|
||||
import SeedUsers from '../seeds/SeedUsers';
|
||||
/**
|
||||
* Loader for the database that creates the database connection and initializes the database tabels.
|
||||
@ -9,8 +12,20 @@ import SeedUsers from '../seeds/SeedUsers';
|
||||
export default async () => {
|
||||
const connection = await createConnection();
|
||||
await connection.synchronize();
|
||||
if (await connection.getRepository(User).count() === 0) {
|
||||
|
||||
//The data seeding part
|
||||
if (!(await connection.getRepository(ConfigFlag).findOne({ option: "seeded:user", value: "true" }))) {
|
||||
await runSeeder(SeedUsers);
|
||||
await connection.getRepository(ConfigFlag).save({ option: "seeded:user", value: "true" });
|
||||
}
|
||||
if (!(await connection.getRepository(ConfigFlag).findOne({ option: "seeded:citizenorg", value: "true" }))) {
|
||||
await runSeeder(SeedPublicOrg);
|
||||
await connection.getRepository(ConfigFlag).save({ option: "seeded:citizenorg", value: "true" });
|
||||
}
|
||||
if (!(await connection.getRepository(ConfigFlag).findOne({ option: "seeded:testdata", value: "true" })) && config.seedTestData == true) {
|
||||
await runSeeder(SeedTestRunners);
|
||||
await connection.getRepository(ConfigFlag).save({ option: "seeded:testdata", value: "true" });
|
||||
}
|
||||
|
||||
return connection;
|
||||
};
|
27
src/models/entities/ConfigFlags.ts
Normal file
27
src/models/entities/ConfigFlags.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import {
|
||||
IsNotEmpty,
|
||||
IsString
|
||||
} from "class-validator";
|
||||
import { Column, Entity, PrimaryColumn } from "typeorm";
|
||||
|
||||
/**
|
||||
* Defines the ConfigFlag entity.
|
||||
* This entity can be used to set some flags on db init.
|
||||
*/
|
||||
@Entity()
|
||||
export class ConfigFlag {
|
||||
/**
|
||||
* The flag's name (primary).
|
||||
*/
|
||||
@PrimaryColumn()
|
||||
@IsString()
|
||||
option: string;
|
||||
|
||||
/**
|
||||
* The flag's value.
|
||||
*/
|
||||
@Column()
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
value: string;
|
||||
}
|
15
src/seeds/SeedPublicOrg.ts
Normal file
15
src/seeds/SeedPublicOrg.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { Connection } from 'typeorm';
|
||||
import { Factory, Seeder } from 'typeorm-seeding';
|
||||
import { CreateRunnerOrganisation } from '../models/actions/create/CreateRunnerOrganisation';
|
||||
import { RunnerOrganisation } from '../models/entities/RunnerOrganisation';
|
||||
|
||||
/**
|
||||
* Seeds the public runner org (named: "Citizen" by default).
|
||||
*/
|
||||
export default class SeedPublicOrg implements Seeder {
|
||||
public async run(factory: Factory, connection: Connection): Promise<any> {
|
||||
let publicOrg = new CreateRunnerOrganisation();
|
||||
publicOrg.name = "Citizen";
|
||||
await connection.getRepository(RunnerOrganisation).save(await publicOrg.toEntity());
|
||||
}
|
||||
}
|
93
src/seeds/SeedTestRunners.ts
Normal file
93
src/seeds/SeedTestRunners.ts
Normal file
@ -0,0 +1,93 @@
|
||||
import { Connection } from 'typeorm';
|
||||
import { Factory, Seeder } from 'typeorm-seeding';
|
||||
import { CreateGroupContact } from '../models/actions/create/CreateGroupContact';
|
||||
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 { GroupContact } from '../models/entities/GroupContact';
|
||||
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.createTestContact(connection, testOrg);
|
||||
await this.createTestRunners(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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async createTestContact(connection: Connection, group: RunnerGroup) {
|
||||
let contact = new CreateGroupContact;
|
||||
contact.firstname = "Test";
|
||||
contact.lastname = "Contact";
|
||||
contact.email = "test.contact@dev.lauf-fuer-kaya.de";
|
||||
contact.groups = group.id;
|
||||
|
||||
contact.address = new Address();
|
||||
contact.address.address1 = "First Contact Street 100";
|
||||
contact.address.city = "Herzogenaurach";
|
||||
contact.address.country = "Germany";
|
||||
contact.address.postalcode = "90174";
|
||||
|
||||
await connection.getRepository(GroupContact).save(await contact.toEntity());
|
||||
}
|
||||
|
||||
private firstnames = [
|
||||
"Peter",
|
||||
"Matze",
|
||||
"Tine",
|
||||
"Uta",
|
||||
"Fabian",
|
||||
"Unicode:ÖÄ?✔⚠"
|
||||
]
|
||||
|
||||
private lastnames = [
|
||||
"Muster",
|
||||
"Example",
|
||||
"Müller",
|
||||
"Unicode:搆Ǩ>ÙՠƳ|"
|
||||
]
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user