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 { getConnectionManager, Repository } from 'typeorm';
|
||||||
import { config } from '../config';
|
import { config } from '../config';
|
||||||
import { InvalidCredentialsError } from '../errors/AuthError';
|
import { InvalidCredentialsError } from '../errors/AuthError';
|
||||||
import { RunnerNotFoundError } from '../errors/RunnerErrors';
|
import { RunnerEmailNeededError, RunnerNotFoundError } from '../errors/RunnerErrors';
|
||||||
import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors';
|
import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors';
|
||||||
|
import { CreateSelfServiceCitizenRunner } from '../models/actions/create/CreateSelfServiceCitizenRunner';
|
||||||
import { CreateSelfServiceRunner } from '../models/actions/create/CreateSelfServiceRunner';
|
import { CreateSelfServiceRunner } from '../models/actions/create/CreateSelfServiceRunner';
|
||||||
import { Runner } from '../models/entities/Runner';
|
import { Runner } from '../models/entities/Runner';
|
||||||
import { RunnerGroup } from '../models/entities/RunnerGroup';
|
import { RunnerGroup } from '../models/entities/RunnerGroup';
|
||||||
@ -36,14 +37,10 @@ export class RunnerSelfServiceController {
|
|||||||
|
|
||||||
@Post('/register')
|
@Post('/register')
|
||||||
@ResponseSchema(ResponseSelfServiceRunner)
|
@ResponseSchema(ResponseSelfServiceRunner)
|
||||||
@ResponseSchema(RunnerGroupNotFoundError, { statusCode: 404 })
|
@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> In the future we\'ll implement email verification.' })
|
@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: CreateSelfServiceRunner) {
|
async registerRunner(@Body({ validate: true }) createRunner: CreateSelfServiceCitizenRunner) {
|
||||||
const org = await this.groupRepository.findOne({ id: 1 });
|
let runner = await createRunner.toEntity();
|
||||||
if (!org) { throw new RunnerGroupNotFoundError(); }
|
|
||||||
|
|
||||||
createRunner.team = null;
|
|
||||||
let runner = await createRunner.toEntity(org);
|
|
||||||
|
|
||||||
runner = await this.runnerRepository.save(runner);
|
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'] }));
|
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."
|
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.
|
* Error to throw when a runner still has distance donations associated.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user