Implemented registration key generation

ref #112
This commit is contained in:
2021-01-21 17:48:13 +01:00
parent d490247d1e
commit ad446500f9
3 changed files with 54 additions and 3 deletions

View File

@@ -1,8 +1,10 @@
import { IsObject, IsOptional } from 'class-validator';
import { IsBoolean, IsObject, IsOptional } from 'class-validator';
import * as uuid from 'uuid';
import { Address } from '../../entities/Address';
import { RunnerOrganisation } from '../../entities/RunnerOrganisation';
import { CreateRunnerGroup } from './CreateRunnerGroup';
/**
* This classed is used to create a new RunnerOrganisation entity from a json body (post request).
*/
@@ -14,6 +16,13 @@ export class CreateRunnerOrganisation extends CreateRunnerGroup {
@IsObject()
address?: Address;
/**
* Is registration enabled for the new organisation?
*/
@IsOptional()
@IsBoolean()
registrtionEnabled?: boolean = false;
/**
* Creates a new RunnerOrganisation entity from this.
*/
@@ -25,6 +34,10 @@ export class CreateRunnerOrganisation extends CreateRunnerGroup {
newRunnerOrganisation.address = this.address;
Address.validate(newRunnerOrganisation.address);
if (this.registrtionEnabled) {
newRunnerOrganisation.key = uuid.v4().toUpperCase();
}
return newRunnerOrganisation;
}
}