Moded track controller related models to a new file
This commit is contained in:
parent
a86465c554
commit
da4597fa62
@ -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
21
src/models/CreateTrack.ts
Normal 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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user