From 7b948f0380e6cc8e3d4a8b2ef54ffa34931d7f07 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 25 Nov 2020 20:22:58 +0100 Subject: [PATCH] gets now use the db ref #4 --- src/controllers/TrackController.ts | 62 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/src/controllers/TrackController.ts b/src/controllers/TrackController.ts index 9ee15fe..2b8011a 100644 --- a/src/controllers/TrackController.ts +++ b/src/controllers/TrackController.ts @@ -1,11 +1,11 @@ import { - JsonController, - Param, - Body, - Get, - Post, - Put, - Delete, + JsonController, + Param, + Body, + Get, + Post, + Put, + Delete, } from "routing-controllers"; import { OpenAPI } from "routing-controllers-openapi"; import { getConnection, Repository } from "typeorm"; @@ -13,34 +13,32 @@ import { Track } from "../models/Track"; @JsonController("/track") export class TrackController { - private repo: Repository; + private repo(): Repository { + return getConnection().getRepository(Track); + } - public async TrackController() { - const trackManager = await getConnection().getRepository(Track); - } + @Get("/track") + async getAll() { + return await this.repo().find(); + } - @Get("/track") - async getAll() { - return await this.repo.count(); - } + @Get("/track/:id") + async getOne(@Param("id") id: number) { + return await this.repo().findOne({ id: id }); + } - @Get("/track/:id") - getOne(@Param("id") id: number) { - return "This action returns user #" + id; - } + @Post("/track") + post(@Body() user: any) { + return "Saving user..."; + } - @Post("/track") - post(@Body() user: any) { - return "Saving user..."; - } + @Put("/track/:id") + put(@Param("id") id: number, @Body() user: any) { + return "Updating a user..."; + } - @Put("/track/:id") - put(@Param("id") id: number, @Body() user: any) { - return "Updating a user..."; - } - - @Delete("/track/:id") - remove(@Param("id") id: number) { - return "Removing user..."; - } + @Delete("/track/:id") + remove(@Param("id") id: number) { + return "Removing user..."; + } }