From a6bd7235114e63298f2534636fa1c6fa0f08ddf5 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Thu, 26 Nov 2020 13:43:11 +0100 Subject: [PATCH] Now using class validator annotations ref #3 --- src/models/Track.ts | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/models/Track.ts b/src/models/Track.ts index 8d2b57c..dc83239 100644 --- a/src/models/Track.ts +++ b/src/models/Track.ts @@ -1,14 +1,26 @@ import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; +import { + IsInt, + IsNotEmpty, + IsOptional, + IsPositive, + IsString, +} from "class-validator"; @Entity() export class Track { - @PrimaryGeneratedColumn() - id: number; + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + id: number; - @Column() - name: string; + @Column() + @IsString() + @IsNotEmpty() + name: string; - //Length in meters - @Column() - length: string; + @Column() + @IsInt() + @IsPositive() + length: string; }