backend/src/models/actions/CreateTrack.ts
Nicolai Ort 48bef8db60
Some checks failed
continuous-integration/drone/pr Build is failing
Second part of the action comment refactoring
ref #39
2020-12-21 16:21:12 +01:00

33 lines
722 B
TypeScript

import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator';
import { Track } from '../entities/Track';
/**
* This classed is used to create a new Track entity from a json body (post request).
*/
export class CreateTrack {
/**
* The new track's name.
*/
@IsString()
@IsNotEmpty()
name: string;
/**
* The new track's distance in meters (must be greater than 0).
*/
@IsInt()
@IsPositive()
distance: number;
/**
* Creates a new Track entity from this.
*/
public toTrack(): Track {
let newTrack: Track = new Track();
newTrack.name = this.name;
newTrack.distance = this.distance;
return newTrack;
}
}