From dee36395a69da6c5e1bc4e94bd705b0418a6a3ff Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Thu, 21 Jan 2021 17:19:04 +0100 Subject: [PATCH] Citizen runners now have to provide an email address for verification ref #112 --- src/controllers/RunnerSelfServiceController.ts | 15 ++++++--------- src/errors/RunnerErrors.ts | 11 +++++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/controllers/RunnerSelfServiceController.ts b/src/controllers/RunnerSelfServiceController.ts index 825e62a..92628ba 100644 --- a/src/controllers/RunnerSelfServiceController.ts +++ b/src/controllers/RunnerSelfServiceController.ts @@ -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.
This endpoint shoud be used to allow "everyday citizen" to register themselves.
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.
This endpoint shoud be used to allow "everyday citizen" to register themselves.
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'] })); diff --git a/src/errors/RunnerErrors.ts b/src/errors/RunnerErrors.ts index 4dad85f..12621f0 100644 --- a/src/errors/RunnerErrors.ts +++ b/src/errors/RunnerErrors.ts @@ -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. */