Implemented the get part of the runner selfservice (no jwts are availdable yet (tm)

ref #111
This commit is contained in:
Nicolai Ort 2021-01-20 20:05:07 +01:00
parent 4ee807973e
commit da1fe34249
1 changed files with 4 additions and 6 deletions

View File

@ -6,7 +6,7 @@ import { config } from '../config';
import { InvalidCredentialsError } from '../errors/AuthError';
import { RunnerNotFoundError } from '../errors/RunnerErrors';
import { Runner } from '../models/entities/Runner';
import { ResponseUser } from '../models/responses/ResponseUser';
import { ResponseSelfServiceRunner } from '../models/responses/ResponseSelfServiceRunner';
@JsonController('/runners')
@ -21,12 +21,12 @@ export class RunnerSelfServiceController {
}
@Get('/me/:jwt')
@ResponseSchema(ResponseUser)
@ResponseSchema(ResponseSelfServiceRunner)
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
@OnUndefined(RunnerNotFoundError)
@OpenAPI({ description: 'Lists all information about yourself. <br> Please provide your runner jwt for auth.' })
async get(@Param('jwt') token: string) {
//TODO
return (new ResponseSelfServiceRunner(await this.getRunner(token)));
}
/**
@ -41,9 +41,7 @@ export class RunnerSelfServiceController {
throw new InvalidCredentialsError();
}
console.log(jwtPayload);
const runner = await this.runnerRepository.findOne({ id: jwtPayload["id"] });
const runner = await this.runnerRepository.findOne({ id: jwtPayload["id"] }, { relations: ['scans', 'group', 'scans.track', 'cards', 'distanceDonations', 'distanceDonations.donor', 'distanceDonations.runner', 'distanceDonations.runner.scans', 'distanceDonations.runner.scans.track'] });
if (!runner) { throw new RunnerNotFoundError() }
return runner;
}