Compare commits

..

No commits in common. "b267d87ba66e19e61fc04a64dee5056e3cad91e5" and "24d890f638b2298ac2588786897490797a405ee5" have entirely different histories.

2 changed files with 3 additions and 16 deletions

View File

@ -1,7 +1,7 @@
import { JsonController, Param, Body, Get, Post, Put, Delete, NotFoundError, OnUndefined, NotAcceptableError } from 'routing-controllers';
import { JsonController, Param, Body, Get, Post, Put, Delete, NotFoundError, OnUndefined } from 'routing-controllers';
import { getConnectionManager, Repository } from 'typeorm';
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { ResponseSchema } from 'routing-controllers-openapi';
import { Track } from '../models/Track';
import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator';
@ -25,16 +25,12 @@ export class TrackNotFoundError extends NotFoundError {
export class TrackController {
private trackRepository: Repository<Track>;
/**
* Gets the repository of this controller's model/entity.
*/
constructor() {
this.trackRepository = getConnectionManager().get().getRepository(Track);
}
@Get()
@ResponseSchema(Track, { isArray: true })
@OpenAPI({description: "Lists all tracks."})
getAll() {
return this.trackRepository.find();
}
@ -42,14 +38,12 @@ export class TrackController {
@Get('/:id')
@ResponseSchema(Track)
@OnUndefined(TrackNotFoundError)
@OpenAPI({description: "Returns a track of a specified id (if it exists)"})
getOne(@Param('id') id: number) {
return this.trackRepository.findOne({ id: id });
}
@Post()
@ResponseSchema(Track)
@OpenAPI({description: "Create a new track object (id will be generated automagicly)."})
post(
@Body({ validate: true })
track: CreateTrack
@ -59,7 +53,6 @@ export class TrackController {
@Put('/:id')
@ResponseSchema(Track)
@OpenAPI({description: "Update a track object (id can't be changed)."})
async put(@Param('id') id: number, @EntityFromBody() track: Track) {
let oldTrack = await this.trackRepository.findOne({ id: id });
@ -73,7 +66,7 @@ export class TrackController {
@Delete('/:id')
@ResponseSchema(Track)
@OpenAPI({description: "Delete a specified track (if it exists)."})
@OnUndefined(TrackNotFoundError)
async remove(@Param('id') id: number) {
let track = await this.trackRepository.findOne({ id: id });

View File

@ -7,12 +7,6 @@ import {
IsString,
} from "class-validator";
/**
* @classdesc Defines a track of given length.
* @property {number} id - Autogenerated unique id
* @property {string} name - The track's name
* @property {number} lenth - The track's length in meters
*/
@Entity()
export class Track {
@PrimaryGeneratedColumn()