@@ -4,7 +4,7 @@ import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { Track } from '../models/Track';
|
||||
import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator';
|
||||
import {TrackIdChangeNotAllowedError, TrackNotFoundError} from "../errors/TrackErrors";
|
||||
import {TrackIdsNotMatchingError, TrackNotFoundError} from "../errors/TrackErrors";
|
||||
|
||||
class CreateTrack {
|
||||
@IsString()
|
||||
@@ -57,7 +57,7 @@ export class TrackController {
|
||||
@Put('/:id')
|
||||
@ResponseSchema(Track)
|
||||
@ResponseSchema(TrackNotFoundError, {statusCode: 404})
|
||||
@ResponseSchema(TrackIdChangeNotAllowedError, {statusCode: 406})
|
||||
@ResponseSchema(TrackIdsNotMatchingError, {statusCode: 406})
|
||||
@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 });
|
||||
@@ -67,7 +67,7 @@ export class TrackController {
|
||||
}
|
||||
|
||||
if(oldTrack.id != track.id){
|
||||
throw new TrackIdChangeNotAllowedError();
|
||||
throw new TrackIdsNotMatchingError();
|
||||
}
|
||||
|
||||
await this.trackRepository.update(oldTrack, track);
|
||||
|
||||
Reference in New Issue
Block a user