Added responseschemas and content types
All checks were successful
continuous-integration/drone/pr Build is passing
All checks were successful
continuous-integration/drone/pr Build is passing
ref #22
This commit is contained in:
parent
9db4344153
commit
15ed9f58d5
@ -1,7 +1,8 @@
|
||||
import csv from 'csvtojson';
|
||||
import { Body, ContentType, Controller, Param, Post, QueryParam, Req, UseBefore } from 'routing-controllers';
|
||||
import { OpenAPI } from 'routing-controllers-openapi';
|
||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { RunnerGroupNeededError } from '../errors/RunnerErrors';
|
||||
import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors';
|
||||
import RawBodyMiddleware from '../middlewares/RawBody';
|
||||
import { ImportRunner } from '../models/actions/ImportRunner';
|
||||
import { ResponseRunner } from '../models/responses/ResponseRunner';
|
||||
@ -21,6 +22,9 @@ export class ImportController {
|
||||
|
||||
@Post('/runners/import')
|
||||
@ContentType("application/json")
|
||||
@ResponseSchema(ResponseRunner, { isArray: true })
|
||||
@ResponseSchema(RunnerGroupNotFoundError)
|
||||
@ResponseSchema(RunnerGroupNeededError)
|
||||
@OpenAPI({ description: "Create new runners from json and insert them (or their teams) into the provided group" })
|
||||
async postJSON(@Body({ validate: true, type: ImportRunner }) importRunners: ImportRunner[], @QueryParam("group") groupID: number) {
|
||||
if (!groupID) { throw new RunnerGroupNeededError(); }
|
||||
@ -33,6 +37,9 @@ export class ImportController {
|
||||
|
||||
@Post('/organisations/:id/import')
|
||||
@ContentType("application/json")
|
||||
@ResponseSchema(ResponseRunner, { isArray: true })
|
||||
@ResponseSchema(RunnerGroupNotFoundError)
|
||||
@ResponseSchema(RunnerGroupNeededError)
|
||||
@OpenAPI({ description: "Create new runners from json and insert them (or their teams) into the provided org" })
|
||||
async postOrgsJSON(@Body({ validate: true, type: ImportRunner }) importRunners: ImportRunner[], @Param('id') id: number) {
|
||||
return await this.postJSON(importRunners, id)
|
||||
@ -40,13 +47,20 @@ export class ImportController {
|
||||
|
||||
@Post('/teams/:id/import')
|
||||
@ContentType("application/json")
|
||||
@ResponseSchema(ResponseRunner, { isArray: true })
|
||||
@ResponseSchema(RunnerGroupNotFoundError)
|
||||
@ResponseSchema(RunnerGroupNeededError)
|
||||
@OpenAPI({ description: "Create new runners from json and insert them into the provided team" })
|
||||
async postTeamsJSON(@Body({ validate: true, type: ImportRunner }) importRunners: ImportRunner[], @Param('id') id: number) {
|
||||
return await this.postJSON(importRunners, id)
|
||||
}
|
||||
|
||||
@Post('/import/csv')
|
||||
@ContentType("application/json")
|
||||
@UseBefore(RawBodyMiddleware)
|
||||
@ResponseSchema(ResponseRunner, { isArray: true })
|
||||
@ResponseSchema(RunnerGroupNotFoundError)
|
||||
@ResponseSchema(RunnerGroupNeededError)
|
||||
@OpenAPI({ description: "Create new runners from csv and insert them (or their teams) into the provided group" })
|
||||
async postCSV(@Req() request: any, @QueryParam("group") groupID: number) {
|
||||
let csvParse = await csv({ delimiter: [",", ";"], trim: true }).fromString(request.rawBody.toString());
|
||||
@ -64,14 +78,22 @@ export class ImportController {
|
||||
}
|
||||
|
||||
@Post('/organisations/:id/import/csv')
|
||||
@ContentType("application/json")
|
||||
@UseBefore(RawBodyMiddleware)
|
||||
@ResponseSchema(ResponseRunner, { isArray: true })
|
||||
@ResponseSchema(RunnerGroupNotFoundError)
|
||||
@ResponseSchema(RunnerGroupNeededError)
|
||||
@OpenAPI({ description: "Create new runners from csv and insert them (or their teams) into the provided org" })
|
||||
async postOrgsCSV(@Req() request: any, @Param("id") id: number) {
|
||||
return await this.postCSV(request, id);
|
||||
}
|
||||
|
||||
@Post('/teams/:id/import/csv')
|
||||
@ContentType("application/json")
|
||||
@UseBefore(RawBodyMiddleware)
|
||||
@ResponseSchema(ResponseRunner, { isArray: true })
|
||||
@ResponseSchema(RunnerGroupNotFoundError)
|
||||
@ResponseSchema(RunnerGroupNeededError)
|
||||
@OpenAPI({ description: "Create new runners from csv and insert them into the provided team" })
|
||||
async postTeamsCSV(@Req() request: any, @Param("id") id: number) {
|
||||
return await this.postCSV(request, id);
|
||||
|
Loading…
x
Reference in New Issue
Block a user