Citizen runners now have to provide an email address for verification
ref #112
This commit is contained in:
parent
6df195b6ec
commit
dee36395a6
|
@ -4,8 +4,9 @@ import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
|||
import { getConnectionManager, Repository } from 'typeorm';
|
||||
import { config } from '../config';
|
||||
import { InvalidCredentialsError } from '../errors/AuthError';
|
||||
import { RunnerNotFoundError } from '../errors/RunnerErrors';
|
||||
import { RunnerEmailNeededError, RunnerNotFoundError } from '../errors/RunnerErrors';
|
||||
import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors';
|
||||
import { CreateSelfServiceCitizenRunner } from '../models/actions/create/CreateSelfServiceCitizenRunner';
|
||||
import { CreateSelfServiceRunner } from '../models/actions/create/CreateSelfServiceRunner';
|
||||
import { Runner } from '../models/entities/Runner';
|
||||
import { RunnerGroup } from '../models/entities/RunnerGroup';
|
||||
|
@ -36,14 +37,10 @@ export class RunnerSelfServiceController {
|
|||
|
||||
@Post('/register')
|
||||
@ResponseSchema(ResponseSelfServiceRunner)
|
||||
@ResponseSchema(RunnerGroupNotFoundError, { statusCode: 404 })
|
||||
@OpenAPI({ description: 'Create a new selfservice runner in the citizen org. <br> This endpoint shoud be used to allow "everyday citizen" to register themselves. <br> In the future we\'ll implement email verification.' })
|
||||
async registerRunner(@Body({ validate: true }) createRunner: CreateSelfServiceRunner) {
|
||||
const org = await this.groupRepository.findOne({ id: 1 });
|
||||
if (!org) { throw new RunnerGroupNotFoundError(); }
|
||||
|
||||
createRunner.team = null;
|
||||
let runner = await createRunner.toEntity(org);
|
||||
@ResponseSchema(RunnerEmailNeededError, { statusCode: 406 })
|
||||
@OpenAPI({ description: 'Create a new selfservice runner in the citizen org. <br> This endpoint shoud be used to allow "everyday citizen" to register themselves. <br> You have to provide a mail address, b/c the future we\'ll implement email verification.' })
|
||||
async registerRunner(@Body({ validate: true }) createRunner: CreateSelfServiceCitizenRunner) {
|
||||
let runner = await createRunner.toEntity();
|
||||
|
||||
runner = await this.runnerRepository.save(runner);
|
||||
return new ResponseSelfServiceRunner(await this.runnerRepository.findOne(runner, { relations: ['scans', 'group', 'scans.track', 'cards', 'distanceDonations', 'distanceDonations.donor', 'distanceDonations.runner', 'distanceDonations.runner.scans', 'distanceDonations.runner.scans.track'] }));
|
||||
|
|
|
@ -35,6 +35,17 @@ export class RunnerGroupNeededError extends NotAcceptableError {
|
|||
message = "Runner's need to be part of one group (team or organisation)! \n You provided neither."
|
||||
}
|
||||
|
||||
/**
|
||||
* Error to throw when a citizen runner has no mail-address.
|
||||
*/
|
||||
export class RunnerEmailNeededError extends NotAcceptableError {
|
||||
@IsString()
|
||||
name = "RunnerEmailNeededError"
|
||||
|
||||
@IsString()
|
||||
message = "Citizenrunners have to provide an email address for verification and contacting."
|
||||
}
|
||||
|
||||
/**
|
||||
* Error to throw when a runner still has distance donations associated.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue