Added basic creation class
This commit is contained in:
parent
980ac64688
commit
7bbf769bdd
@ -1,23 +1,69 @@
|
|||||||
import { JsonController, Param, Body, Get, Post, Put, Delete, NotFoundError, OnUndefined, NotAcceptableError, Authorized } from 'routing-controllers';
|
import {
|
||||||
|
JsonController,
|
||||||
|
Param,
|
||||||
|
Body,
|
||||||
|
Get,
|
||||||
|
Post,
|
||||||
|
Put,
|
||||||
|
Delete,
|
||||||
|
NotFoundError,
|
||||||
|
OnUndefined,
|
||||||
|
NotAcceptableError,
|
||||||
|
Authorized
|
||||||
|
} from 'routing-controllers';
|
||||||
import { getConnectionManager, Repository } from 'typeorm';
|
import { getConnectionManager, Repository } from 'typeorm';
|
||||||
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
||||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||||
import { Runner } from '../models/Runner';
|
import { Runner } from '../models/Runner';
|
||||||
import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator';
|
import { IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsPositive, IsString } from 'class-validator';
|
||||||
import {RunnerIdsNotMatchingError, RunnerNotFoundError} from "../errors/RunnerErrors";
|
import { RunnerIdsNotMatchingError, RunnerNotFoundError } from '../errors/RunnerErrors';
|
||||||
|
|
||||||
class CreateRunner {
|
class CreateRunner {
|
||||||
|
/**
|
||||||
|
* The runners's first name.
|
||||||
|
*/
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsString()
|
||||||
|
firstname: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The runners's middle name.
|
||||||
|
* Optional
|
||||||
|
*/
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
middlename?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The runers's last name.
|
||||||
|
*/
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
name: string;
|
lastname: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The runner's phone number.
|
||||||
|
* Optional
|
||||||
|
*/
|
||||||
|
@IsOptional()
|
||||||
|
@IsPhoneNumber('DE')
|
||||||
|
phone?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The runner's email address.
|
||||||
|
* Optional
|
||||||
|
*/
|
||||||
|
@IsOptional()
|
||||||
|
@IsEmail()
|
||||||
|
email?: string;
|
||||||
|
|
||||||
@IsInt()
|
@IsInt()
|
||||||
@IsPositive()
|
@IsOptional()
|
||||||
length: number;
|
groupId?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonController('/runners')
|
@JsonController('/runners')
|
||||||
@Authorized("RUNNERS:read")
|
//@Authorized('RUNNERS:read')
|
||||||
export class RunnerController {
|
export class RunnerController {
|
||||||
private runnerRepository: Repository<Runner>;
|
private runnerRepository: Repository<Runner>;
|
||||||
|
|
||||||
@ -30,7 +76,7 @@ export class RunnerController {
|
|||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ResponseSchema(Runner, { isArray: true })
|
@ResponseSchema(Runner, { isArray: true })
|
||||||
@OpenAPI({ description: "Lists all runners." })
|
@OpenAPI({ description: 'Lists all runners.' })
|
||||||
getAll() {
|
getAll() {
|
||||||
return this.runnerRepository.find();
|
return this.runnerRepository.find();
|
||||||
}
|
}
|
||||||
@ -39,14 +85,14 @@ export class RunnerController {
|
|||||||
@ResponseSchema(Runner)
|
@ResponseSchema(Runner)
|
||||||
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
||||||
@OnUndefined(RunnerNotFoundError)
|
@OnUndefined(RunnerNotFoundError)
|
||||||
@OpenAPI({ description: "Returns a runner of a specified id (if it exists)" })
|
@OpenAPI({ description: 'Returns a runner of a specified id (if it exists)' })
|
||||||
getOne(@Param('id') id: number) {
|
getOne(@Param('id') id: number) {
|
||||||
return this.runnerRepository.findOne({ id: id });
|
return this.runnerRepository.findOne({ id: id });
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ResponseSchema(Runner)
|
@ResponseSchema(Runner)
|
||||||
@OpenAPI({ description: "Create a new runner object (id will be generated automagicly)." })
|
@OpenAPI({ description: 'Create a new runner object (id will be generated automagicly).' })
|
||||||
post(
|
post(
|
||||||
@Body({ validate: true })
|
@Body({ validate: true })
|
||||||
runner: CreateRunner
|
runner: CreateRunner
|
||||||
@ -77,7 +123,7 @@ export class RunnerController {
|
|||||||
@Delete('/:id')
|
@Delete('/:id')
|
||||||
@ResponseSchema(Runner)
|
@ResponseSchema(Runner)
|
||||||
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
|
||||||
@OpenAPI({description: "Delete a specified runner (if it exists)."})
|
@OpenAPI({ description: 'Delete a specified runner (if it exists).' })
|
||||||
async remove(@Param('id') id: number) {
|
async remove(@Param('id') id: number) {
|
||||||
let runner = await this.runnerRepository.findOne({ id: id });
|
let runner = await this.runnerRepository.findOne({ id: id });
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user