From f0a7cbbcae140fba469634ef79a63f677cb994c7 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Fri, 27 Nov 2020 22:19:07 +0100 Subject: [PATCH] Adjusted the comments for tsdoc ref #8 #3 --- src/controllers/TrackController.ts | 6 +++--- src/errors/TrackErrors.ts | 13 +++++++++++-- src/models/Track.ts | 14 ++++++++++---- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/controllers/TrackController.ts b/src/controllers/TrackController.ts index c6327a9..d0b3a0c 100644 --- a/src/controllers/TrackController.ts +++ b/src/controllers/TrackController.ts @@ -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); diff --git a/src/errors/TrackErrors.ts b/src/errors/TrackErrors.ts index 5b1a33a..6c0d803 100644 --- a/src/errors/TrackErrors.ts +++ b/src/errors/TrackErrors.ts @@ -1,6 +1,10 @@ import { JsonController, Param, Body, Get, Post, Put, Delete, NotFoundError, OnUndefined, NotAcceptableError } from 'routing-controllers'; import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator'; +/** + * Error to throw when a track couldn't be found. + * Implemented this ways to work with the json-schema conversion for openapi. + */ export class TrackNotFoundError extends NotFoundError { @IsString() name = "TrackNotFoundError" @@ -9,9 +13,14 @@ export class TrackNotFoundError extends NotFoundError { message = "Track not found!" } -export class TrackIdChangeNotAllowedError extends NotAcceptableError { +/** + * Error to throw when two tracks' ids don't match. + * Usually occurs when a user tries to change a track's id. + * Implemented this ways to work with the json-schema conversion for openapi. + */ +export class TrackIdsNotMatchingError extends NotAcceptableError { @IsString() - name = "TrackIdChangeNotAllowed" + name = "TrackIdsNotMatchingError" @IsString() message = "The id's don't match!! \n And if you wanted to change a track's id: This isn't allowed" diff --git a/src/models/Track.ts b/src/models/Track.ts index b0a789b..ea09063 100644 --- a/src/models/Track.ts +++ b/src/models/Track.ts @@ -8,23 +8,29 @@ import { } 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 + * Defines a track of given length. */ @Entity() export class Track { + /** + * Autogenerated unique id (primary key). + */ @PrimaryGeneratedColumn() @IsOptional() @IsInt() id: number; + /** + * The track's name. + */ @Column() @IsString() @IsNotEmpty() name: string; + /** + * The track's length in meters. + */ @Column() @IsInt() @IsPositive()