Implemented the citizen runner self-registration endpoint

ref #112
This commit is contained in:
Nicolai Ort 2021-01-21 16:47:13 +01:00
parent 5288c701c1
commit 1b5465bea8
1 changed files with 15 additions and 0 deletions

View File

@ -34,6 +34,21 @@ export class RunnerSelfServiceController {
return (new ResponseSelfServiceRunner(await this.getRunner(token)));
}
@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(); }
let runner = await createRunner.toEntity(org);
runner.group = org;
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'] }));
}
@Post('/register/:token')
@ResponseSchema(ResponseSelfServiceRunner)
@ResponseSchema(RunnerGroupNotFoundError, { statusCode: 404 })