parent
913033373b
commit
8beb658bcc
@ -5,7 +5,7 @@ import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
|||||||
import { RunnerGroupNeededError, RunnerGroupNotFoundError, RunnerIdsNotMatchingError, RunnerNotFoundError, RunnerOnlyOneGroupAllowedError } from '../errors/RunnerErrors';
|
import { RunnerGroupNeededError, RunnerGroupNotFoundError, RunnerIdsNotMatchingError, RunnerNotFoundError, RunnerOnlyOneGroupAllowedError } from '../errors/RunnerErrors';
|
||||||
import { CreateRunner } from '../models/creation/CreateRunner';
|
import { CreateRunner } from '../models/creation/CreateRunner';
|
||||||
import { Runner } from '../models/entities/Runner';
|
import { Runner } from '../models/entities/Runner';
|
||||||
|
import { ResponseRunner } from '../models/responses/ResponseRunner';
|
||||||
|
|
||||||
@JsonController('/runners')
|
@JsonController('/runners')
|
||||||
//@Authorized('RUNNERS:read')
|
//@Authorized('RUNNERS:read')
|
||||||
@ -20,10 +20,15 @@ export class RunnerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ResponseSchema(Runner, { isArray: true })
|
@ResponseSchema(ResponseRunner, { isArray: true })
|
||||||
@OpenAPI({ description: 'Lists all runners.' })
|
@OpenAPI({ description: 'Lists all runners.' })
|
||||||
getAll() {
|
async getAll() {
|
||||||
return this.runnerRepository.find();
|
let responseRunners: ResponseRunner[] = new Array<ResponseRunner>();
|
||||||
|
const runners = await this.runnerRepository.find();
|
||||||
|
runners.forEach(runner => {
|
||||||
|
responseRunners.push(new ResponseRunner(runner));
|
||||||
|
});
|
||||||
|
return responseRunners;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('/:id')
|
@Get('/:id')
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { Entity, Column, OneToMany, ManyToOne, ChildEntity } from "typeorm";
|
import { IsInt, IsNotEmpty } from "class-validator";
|
||||||
import { IsInt, IsNotEmpty, } from "class-validator";
|
import { ChildEntity, getConnectionManager, ManyToOne, OneToMany } from "typeorm";
|
||||||
import { Participant } from "./Participant";
|
|
||||||
import { RunnerGroup } from "./RunnerGroup";
|
|
||||||
import { DistanceDonation } from "./DistanceDonation";
|
import { DistanceDonation } from "./DistanceDonation";
|
||||||
|
import { Participant } from "./Participant";
|
||||||
import { RunnerCard } from "./RunnerCard";
|
import { RunnerCard } from "./RunnerCard";
|
||||||
|
import { RunnerGroup } from "./RunnerGroup";
|
||||||
import { Scan } from "./Scan";
|
import { Scan } from "./Scan";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,7 +38,11 @@ export class Runner extends Participant {
|
|||||||
|
|
||||||
@IsInt()
|
@IsInt()
|
||||||
public get distance(): number {
|
public get distance(): number {
|
||||||
return this.scans.filter(scan => scan.valid === true).reduce((sum, current) => sum + current.distance, 0);
|
getConnectionManager().get().getRepository(Scan).find({ runner: this })
|
||||||
|
.then(myScans => {
|
||||||
|
return myScans.reduce((sum, current) => sum + current.distance, 0);
|
||||||
|
})
|
||||||
|
.catch(err => { throw err })
|
||||||
|
.finally(do => { return -1; });
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
78
src/models/responses/ResponseRunner.ts
Normal file
78
src/models/responses/ResponseRunner.ts
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
import {
|
||||||
|
IsInt,
|
||||||
|
|
||||||
|
IsObject,
|
||||||
|
|
||||||
|
IsString
|
||||||
|
} from "class-validator";
|
||||||
|
import { Runner } from '../entities/Runner';
|
||||||
|
import { RunnerGroup } from '../entities/RunnerGroup';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines a track of given length.
|
||||||
|
*/
|
||||||
|
export class ResponseRunner {
|
||||||
|
/**
|
||||||
|
* Autogenerated unique id (primary key).
|
||||||
|
*/
|
||||||
|
@IsInt()
|
||||||
|
id: number;;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The runner's first name.
|
||||||
|
*/
|
||||||
|
@IsString()
|
||||||
|
firstname: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The runner's middle name.
|
||||||
|
* Optional.
|
||||||
|
*/
|
||||||
|
@IsString()
|
||||||
|
middlename?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The runner's last name.
|
||||||
|
*/
|
||||||
|
@IsString()
|
||||||
|
lastname: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The runner's phone number.
|
||||||
|
* Optional.
|
||||||
|
*/
|
||||||
|
@IsString()
|
||||||
|
phone?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The runner's e-mail address.
|
||||||
|
* Optional.
|
||||||
|
*/
|
||||||
|
@IsString()
|
||||||
|
email?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The runner's currently ran distance in meters.
|
||||||
|
* Optional.
|
||||||
|
*/
|
||||||
|
@IsInt()
|
||||||
|
distance: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The runner's group.
|
||||||
|
*/
|
||||||
|
@IsObject()
|
||||||
|
group: RunnerGroup;
|
||||||
|
|
||||||
|
|
||||||
|
public constructor(runner: Runner) {
|
||||||
|
this.id = runner.id;
|
||||||
|
this.firstname = runner.firstname;
|
||||||
|
this.middlename = runner.middlename;
|
||||||
|
this.lastname = runner.lastname;
|
||||||
|
this.phone = runner.phone;
|
||||||
|
this.email = runner.email;
|
||||||
|
this.distance = runner.distance;
|
||||||
|
this.group = runner.group;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user