feat(runners): Generate selfservice urls on runner if requested or create/update/get single

This commit is contained in:
2025-04-08 20:00:27 +02:00
parent 175ba52ffa
commit 5415cd38a7
2 changed files with 22 additions and 7 deletions

View File

@@ -1,7 +1,10 @@
import {
IsInt,
IsObject
IsObject,
IsOptional,
IsString
} from "class-validator";
import { JwtCreator } from '../../jwtcreator';
import { Runner } from '../entities/Runner';
import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';
@@ -30,14 +33,26 @@ export class ResponseRunner extends ResponseParticipant implements IResponse {
@IsObject()
group: ResponseRunnerGroup;
/**
* A selfservice link for our new runner.
*/
@IsOptional()
@IsString()
selfserviceLink: string;
/**
* Creates a ResponseRunner object from a runner.
* @param runner The user the response shall be build for.
*/
public constructor(runner: Runner) {
public constructor(runner: Runner, generateSelfServiceLink: boolean = false) {
super(runner);
if (!runner.scans) { this.distance = 0 }
else { this.distance = runner.validScans.reduce((sum, current) => sum + current.distance, 0); }
if (runner.group) { this.group = runner.group.toResponse(); }
if (generateSelfServiceLink) {
const token = JwtCreator.createSelfService(runner);
this.selfserviceLink = `${process.env.SELFSERVICE_URL}/profile/${token}`;
}
}
}