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,4 +1,5 @@
import { IsInt, IsObject, IsOptional } from 'class-validator';
import { IsBoolean, IsInt, IsNotEmpty, IsObject, IsOptional } from 'class-validator';
import * as uuid from 'uuid';
import { Address } from '../../entities/Address';
import { RunnerOrganisation } from '../../entities/RunnerOrganisation';
import { CreateRunnerGroup } from '../create/CreateRunnerGroup';
@@ -22,6 +23,13 @@ export class UpdateRunnerOrganisation extends CreateRunnerGroup {
@IsObject()
address?: Address;
/**
* Is registration enabled for the updated organisation?
*/
@IsNotEmpty()
@IsBoolean()
registrtionEnabled: boolean;
/**
* Updates a provided RunnerOrganisation entity based on this.
*/
@@ -33,6 +41,13 @@ export class UpdateRunnerOrganisation extends CreateRunnerGroup {
else { organisation.address = this.address; }
Address.validate(organisation.address);
if (this.registrtionEnabled) {
organisation.key = uuid.v4().toUpperCase();
}
else {
organisation.key = null;
}
return organisation;
}
}