@@ -1,7 +1,7 @@
|
||||
import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post } from 'routing-controllers';
|
||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { getConnectionManager, Repository } from 'typeorm';
|
||||
import { StatsClientIdsNotMatchingError, StatsClientNotFoundError } from '../errors/StatsClientErrors';
|
||||
import { StatsClientNotFoundError } from '../errors/StatsClientErrors';
|
||||
import { TrackNotFoundError } from "../errors/TrackErrors";
|
||||
import { CreateStatsClient } from '../models/actions/CreateStatsClient';
|
||||
import { StatsClient } from '../models/entities/StatsClient';
|
||||
@@ -23,7 +23,7 @@ export class StatsClientController {
|
||||
@Get()
|
||||
@Authorized("STATSCLIENT:GET")
|
||||
@ResponseSchema(ResponseStatsClient, { isArray: true })
|
||||
@OpenAPI({ description: 'Lists all stats clients. Please remember that the key can only be viewed on creation and update.' })
|
||||
@OpenAPI({ description: 'Lists all stats clients. Please remember that the key can only be viewed on creation.' })
|
||||
async getAll() {
|
||||
let responseClients: ResponseStatsClient[] = new Array<ResponseStatsClient>();
|
||||
const clients = await this.clientRepository.find();
|
||||
@@ -38,7 +38,7 @@ export class StatsClientController {
|
||||
@ResponseSchema(ResponseStatsClient)
|
||||
@ResponseSchema(StatsClientNotFoundError, { statusCode: 404 })
|
||||
@OnUndefined(StatsClientNotFoundError)
|
||||
@OpenAPI({ description: "Lists all information about the stats client whose id got provided. Please remember that the key can only be viewed on creation and update" })
|
||||
@OpenAPI({ description: "Lists all information about the stats client whose id got provided. Please remember that the key can only be viewed on creation." })
|
||||
async getOne(@Param('id') id: number) {
|
||||
let client = await this.clientRepository.findOne({ id: id });
|
||||
if (!client) { throw new TrackNotFoundError(); }
|
||||
@@ -48,39 +48,17 @@ export class StatsClientController {
|
||||
@Post()
|
||||
@Authorized("STATSCLIENT:CREATE")
|
||||
@ResponseSchema(ResponseStatsClient)
|
||||
@OpenAPI({ description: "Create a new stats client. <br> Please remember that the client\'s key will be generated automaticly and that it can only be viewed on creation and update." })
|
||||
@OpenAPI({ description: "Create a new stats client. <br> Please remember that the client\'s key will be generated automaticly and that it can only be viewed on creation." })
|
||||
async post(
|
||||
@Body({ validate: true })
|
||||
client: CreateStatsClient
|
||||
) {
|
||||
let newClient = await this.clientRepository.save(await client.toStatsClient());
|
||||
let responseClient = new ResponseStatsClient(newClient);
|
||||
responseClient.key = newClient.key;
|
||||
responseClient.key = newClient.cleartextkey;
|
||||
return responseClient;
|
||||
}
|
||||
|
||||
|
||||
// @Put('/:id')
|
||||
// @Authorized("STATSCLIENT:UPDATE")
|
||||
// @ResponseSchema(ResponseStatsClient)
|
||||
// @ResponseSchema(StatsClientNotFoundError, { statusCode: 404 })
|
||||
// @ResponseSchema(StatsClientIdsNotMatchingError, { statusCode: 406 })
|
||||
// @OpenAPI({ description: "Update the stats client whose id you provided. <br> Please remember that ids can't be changed." })
|
||||
// async put(@Param('id') id: number, @EntityFromBody() track: Track) {
|
||||
// let oldTrack = await this.trackRepository.findOne({ id: id });
|
||||
|
||||
// if (!oldTrack) {
|
||||
// throw new StatsClientNotFoundError();
|
||||
// }
|
||||
|
||||
// if (oldTrack.id != track.id) {
|
||||
// throw new StatsClientIdsNotMatchingError();
|
||||
// }
|
||||
|
||||
// await this.trackRepository.save(track);
|
||||
// return new ResponseTrack(track);
|
||||
// }
|
||||
|
||||
@Delete('/:id')
|
||||
@Authorized("STATSCLIENT:DELETE")
|
||||
@ResponseSchema(ResponseStatsClient)
|
||||
|
||||
Reference in New Issue
Block a user