parent
04813173e4
commit
b53b5cf91f
@ -1,7 +1,7 @@
|
|||||||
import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post } from 'routing-controllers';
|
import { Authorized, Body, Delete, Get, JsonController, OnUndefined, Param, Post } from 'routing-controllers';
|
||||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||||
import { getConnectionManager, Repository } from 'typeorm';
|
import { getConnectionManager, Repository } from 'typeorm';
|
||||||
import { StatsClientIdsNotMatchingError, StatsClientNotFoundError } from '../errors/StatsClientErrors';
|
import { StatsClientNotFoundError } from '../errors/StatsClientErrors';
|
||||||
import { TrackNotFoundError } from "../errors/TrackErrors";
|
import { TrackNotFoundError } from "../errors/TrackErrors";
|
||||||
import { CreateStatsClient } from '../models/actions/CreateStatsClient';
|
import { CreateStatsClient } from '../models/actions/CreateStatsClient';
|
||||||
import { StatsClient } from '../models/entities/StatsClient';
|
import { StatsClient } from '../models/entities/StatsClient';
|
||||||
@ -23,7 +23,7 @@ export class StatsClientController {
|
|||||||
@Get()
|
@Get()
|
||||||
@Authorized("STATSCLIENT:GET")
|
@Authorized("STATSCLIENT:GET")
|
||||||
@ResponseSchema(ResponseStatsClient, { isArray: true })
|
@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() {
|
async getAll() {
|
||||||
let responseClients: ResponseStatsClient[] = new Array<ResponseStatsClient>();
|
let responseClients: ResponseStatsClient[] = new Array<ResponseStatsClient>();
|
||||||
const clients = await this.clientRepository.find();
|
const clients = await this.clientRepository.find();
|
||||||
@ -38,7 +38,7 @@ export class StatsClientController {
|
|||||||
@ResponseSchema(ResponseStatsClient)
|
@ResponseSchema(ResponseStatsClient)
|
||||||
@ResponseSchema(StatsClientNotFoundError, { statusCode: 404 })
|
@ResponseSchema(StatsClientNotFoundError, { statusCode: 404 })
|
||||||
@OnUndefined(StatsClientNotFoundError)
|
@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) {
|
async getOne(@Param('id') id: number) {
|
||||||
let client = await this.clientRepository.findOne({ id: id });
|
let client = await this.clientRepository.findOne({ id: id });
|
||||||
if (!client) { throw new TrackNotFoundError(); }
|
if (!client) { throw new TrackNotFoundError(); }
|
||||||
@ -48,39 +48,17 @@ export class StatsClientController {
|
|||||||
@Post()
|
@Post()
|
||||||
@Authorized("STATSCLIENT:CREATE")
|
@Authorized("STATSCLIENT:CREATE")
|
||||||
@ResponseSchema(ResponseStatsClient)
|
@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(
|
async post(
|
||||||
@Body({ validate: true })
|
@Body({ validate: true })
|
||||||
client: CreateStatsClient
|
client: CreateStatsClient
|
||||||
) {
|
) {
|
||||||
let newClient = await this.clientRepository.save(await client.toStatsClient());
|
let newClient = await this.clientRepository.save(await client.toStatsClient());
|
||||||
let responseClient = new ResponseStatsClient(newClient);
|
let responseClient = new ResponseStatsClient(newClient);
|
||||||
responseClient.key = newClient.key;
|
responseClient.key = newClient.cleartextkey;
|
||||||
return responseClient;
|
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')
|
@Delete('/:id')
|
||||||
@Authorized("STATSCLIENT:DELETE")
|
@Authorized("STATSCLIENT:DELETE")
|
||||||
@ResponseSchema(ResponseStatsClient)
|
@ResponseSchema(ResponseStatsClient)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as argon2 from "argon2";
|
import * as argon2 from "argon2";
|
||||||
import { IsBoolean, IsOptional, IsString } from 'class-validator';
|
import { IsOptional, IsString } from 'class-validator';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import * as uuid from 'uuid';
|
import * as uuid from 'uuid';
|
||||||
import { StatsClient } from '../entities/StatsClient';
|
import { StatsClient } from '../entities/StatsClient';
|
||||||
@ -15,13 +15,6 @@ export class CreateStatsClient {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
description?: string;
|
description?: string;
|
||||||
|
|
||||||
/**
|
|
||||||
* Is the new client enabled.
|
|
||||||
*/
|
|
||||||
@IsBoolean()
|
|
||||||
@IsOptional()
|
|
||||||
enabled?: boolean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts this to a StatsClient entity.
|
* Converts this to a StatsClient entity.
|
||||||
*/
|
*/
|
||||||
@ -35,9 +28,6 @@ export class CreateStatsClient {
|
|||||||
newClient.key = await argon2.hash(newClient.prefix + "." + newUUID);
|
newClient.key = await argon2.hash(newClient.prefix + "." + newUUID);
|
||||||
newClient.cleartextkey = newClient.prefix + "." + newUUID;
|
newClient.cleartextkey = newClient.prefix + "." + newUUID;
|
||||||
|
|
||||||
if (this.enabled === undefined || this.enabled === null) { newClient.enabled = true; }
|
|
||||||
else { newClient.enabled = this.enabled }
|
|
||||||
|
|
||||||
return newClient;
|
return newClient;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import { IsBoolean, IsInt, IsOptional, IsString } from "class-validator";
|
import { IsInt, IsOptional, IsString } from "class-validator";
|
||||||
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||||
/**
|
/**
|
||||||
* Defines the StatsClient entity.
|
* Defines the StatsClient entity.
|
||||||
@ -22,14 +22,6 @@ export class StatsClient {
|
|||||||
@IsString()
|
@IsString()
|
||||||
description?: string;
|
description?: string;
|
||||||
|
|
||||||
/**
|
|
||||||
* Is the client enabled (for fraud and setup reasons)?
|
|
||||||
* Default: true
|
|
||||||
*/
|
|
||||||
@Column()
|
|
||||||
@IsBoolean()
|
|
||||||
enabled: boolean = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The client's api key prefix.
|
* The client's api key prefix.
|
||||||
* This is used identitfy a client by it's api key.
|
* This is used identitfy a client by it's api key.
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import {
|
import {
|
||||||
IsBoolean,
|
|
||||||
|
|
||||||
IsInt,
|
IsInt,
|
||||||
|
|
||||||
@ -27,12 +26,6 @@ export class ResponseStatsClient {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
description?: string;
|
description?: string;
|
||||||
|
|
||||||
/**
|
|
||||||
* Is the client enabled?
|
|
||||||
*/
|
|
||||||
@IsBoolean()
|
|
||||||
enabled: boolean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The client's api key.
|
* The client's api key.
|
||||||
* Only visible on creation or regeneration.
|
* Only visible on creation or regeneration.
|
||||||
@ -55,8 +48,7 @@ export class ResponseStatsClient {
|
|||||||
public constructor(client: StatsClient) {
|
public constructor(client: StatsClient) {
|
||||||
this.id = client.id;
|
this.id = client.id;
|
||||||
this.description = client.description;
|
this.description = client.description;
|
||||||
this.enabled = client.enabled;
|
|
||||||
this.prefix = client.prefix;
|
this.prefix = client.prefix;
|
||||||
this.key = "Only visible on creation/update.";
|
this.key = "Only visible on creation.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user