Moded track controller related models to a new file

This commit is contained in:
Nicolai Ort 2020-12-03 17:43:24 +01:00
parent a86465c554
commit da4597fa62
2 changed files with 32 additions and 20 deletions

View File

@ -5,19 +5,10 @@ import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { Track } from '../models/Track';
import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator';
import { TrackIdsNotMatchingError, TrackNotFoundError } from "../errors/TrackErrors";
class CreateTrack {
@IsString()
@IsNotEmpty()
name: string;
@IsInt()
@IsPositive()
length: number;
}
import { CreateTrack } from '../models/CreateTrack';
@JsonController('/tracks')
@Authorized("TRACKS:read")
//@Authorized("TRACKS:read")
export class TrackController {
private trackRepository: Repository<Track>;
@ -51,7 +42,7 @@ export class TrackController {
@Body({ validate: true })
track: CreateTrack
) {
return this.trackRepository.save(track);
return this.trackRepository.save(track.getTrack());
}
@Put('/:id')

21
src/models/CreateTrack.ts Normal file
View File

@ -0,0 +1,21 @@
import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator';
import { Track } from './Track';
export class CreateTrack {
@IsString()
@IsNotEmpty()
name: string;
@IsInt()
@IsPositive()
distance: number;
public getTrack(): Track {
let newTrack: Track = new Track();
newTrack.name = this.name;
newTrack.distance = this.distance;
return newTrack;
}
}