parent
dee36395a6
commit
d490247d1e
|
@ -6,24 +6,26 @@ import { config } from '../config';
|
||||||
import { InvalidCredentialsError } from '../errors/AuthError';
|
import { InvalidCredentialsError } from '../errors/AuthError';
|
||||||
import { RunnerEmailNeededError, RunnerNotFoundError } from '../errors/RunnerErrors';
|
import { RunnerEmailNeededError, RunnerNotFoundError } from '../errors/RunnerErrors';
|
||||||
import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors';
|
import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors';
|
||||||
|
import { RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors';
|
||||||
import { CreateSelfServiceCitizenRunner } from '../models/actions/create/CreateSelfServiceCitizenRunner';
|
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';
|
||||||
|
import { RunnerOrganisation } from '../models/entities/RunnerOrganisation';
|
||||||
import { ResponseSelfServiceRunner } from '../models/responses/ResponseSelfServiceRunner';
|
import { ResponseSelfServiceRunner } from '../models/responses/ResponseSelfServiceRunner';
|
||||||
|
|
||||||
|
|
||||||
@JsonController('/runners')
|
@JsonController('/runners')
|
||||||
export class RunnerSelfServiceController {
|
export class RunnerSelfServiceController {
|
||||||
private runnerRepository: Repository<Runner>;
|
private runnerRepository: Repository<Runner>;
|
||||||
private groupRepository: Repository<RunnerGroup>;
|
private orgRepository: Repository<RunnerOrganisation>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the repository of this controller's model/entity.
|
* Gets the repository of this controller's model/entity.
|
||||||
*/
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
this.runnerRepository = getConnectionManager().get().getRepository(Runner);
|
this.runnerRepository = getConnectionManager().get().getRepository(Runner);
|
||||||
this.groupRepository = getConnectionManager().get().getRepository(RunnerGroup);
|
this.orgRepository = getConnectionManager().get().getRepository(RunnerOrganisation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('/me/:jwt')
|
@Get('/me/:jwt')
|
||||||
|
@ -50,7 +52,7 @@ export class RunnerSelfServiceController {
|
||||||
@ResponseSchema(ResponseSelfServiceRunner)
|
@ResponseSchema(ResponseSelfServiceRunner)
|
||||||
@ResponseSchema(RunnerGroupNotFoundError, { statusCode: 404 })
|
@ResponseSchema(RunnerGroupNotFoundError, { statusCode: 404 })
|
||||||
@OpenAPI({ description: 'Create a new selfservice runner in a provided org. <br> The orgs get provided and authorized via api tokens that can be optained via the /organisations endpoint.' })
|
@OpenAPI({ description: 'Create a new selfservice runner in a provided org. <br> The orgs get provided and authorized via api tokens that can be optained via the /organisations endpoint.' })
|
||||||
async registerOrganisationRunner(@Param('token') token: number, @Body({ validate: true }) createRunner: CreateSelfServiceRunner) {
|
async registerOrganisationRunner(@Param('token') token: string, @Body({ validate: true }) createRunner: CreateSelfServiceRunner) {
|
||||||
const org = await this.getOrgansisation(token);
|
const org = await this.getOrgansisation(token);
|
||||||
|
|
||||||
let runner = await createRunner.toEntity(org);
|
let runner = await createRunner.toEntity(org);
|
||||||
|
@ -76,8 +78,16 @@ export class RunnerSelfServiceController {
|
||||||
return runner;
|
return runner;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getOrgansisation(token: number): Promise<RunnerGroup> {
|
/**
|
||||||
//TODO: Implement the real token checker
|
* Get's a runner org by a provided registration api key.
|
||||||
return await this.groupRepository.findOne({ id: token });
|
* @param token The organisation's registration api token.
|
||||||
|
*/
|
||||||
|
private async getOrgansisation(token: string): Promise<RunnerGroup> {
|
||||||
|
token = Buffer.from(token, 'base64').toString();
|
||||||
|
|
||||||
|
const organisation = await this.orgRepository.findOne({ key: token });
|
||||||
|
if (!organisation) { throw new RunnerOrganisationNotFoundError; }
|
||||||
|
|
||||||
|
return organisation;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
import { IsInt, IsOptional } from "class-validator";
|
import { IsInt, IsOptional, IsString } from "class-validator";
|
||||||
import { ChildEntity, Column, OneToMany } from "typeorm";
|
import { ChildEntity, Column, OneToMany } from "typeorm";
|
||||||
import { ResponseRunnerOrganisation } from '../responses/ResponseRunnerOrganisation';
|
import { ResponseRunnerOrganisation } from '../responses/ResponseRunnerOrganisation';
|
||||||
import { Address } from './Address';
|
import { Address } from './Address';
|
||||||
|
@ -27,6 +27,16 @@ export class RunnerOrganisation extends RunnerGroup {
|
||||||
@OneToMany(() => RunnerTeam, team => team.parentGroup, { nullable: true })
|
@OneToMany(() => RunnerTeam, team => team.parentGroup, { nullable: true })
|
||||||
teams: RunnerTeam[];
|
teams: RunnerTeam[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The organisation's api key for self-service registration.
|
||||||
|
* The api key can be used for the /runners/register/:token endpoint.
|
||||||
|
* Is has to be base64 encoded if used via the api (to keep url-safety).
|
||||||
|
*/
|
||||||
|
@Column({ nullable: true })
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
key?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all runners associated with this organisation (directly or indirectly via teams).
|
* Returns all runners associated with this organisation (directly or indirectly via teams).
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user