Consolidated the json import for a cleaner result

ref #22
This commit is contained in:
2020-12-17 17:25:17 +01:00
parent 71228fbf33
commit 0d8fbf1eca
3 changed files with 59 additions and 62 deletions

View File

@@ -3,7 +3,6 @@ import { OpenAPI } from 'routing-controllers-openapi';
import { RunnerGroupNeededError } from '../errors/RunnerErrors';
import RawBodyMiddleware from '../middlewares/RawBody';
import { ImportRunner } from '../models/actions/ImportRunner';
import { ImportSchoolRunner } from '../models/actions/ImportSchoolRunner';
import { ResponseRunner } from '../models/responses/ResponseRunner';
import { RunnerController } from './RunnerController';
@@ -22,7 +21,7 @@ export class ImportController {
@Post('/runners/import')
@ContentType("application/json")
@OpenAPI({ description: "Create new runners from json" })
async postJSON(@Body({ validate: true, type: ImportSchoolRunner }) importRunners: ImportRunner[], @QueryParam("group") groupID: number) {
async postJSON(@Body({ validate: true, type: ImportRunner }) importRunners: ImportRunner[], @QueryParam("group") groupID: number) {
if (!groupID) { throw new RunnerGroupNeededError(); }
let responseRunners: ResponseRunner[] = new Array<ResponseRunner>();
for await (let runner of importRunners) {
@@ -34,14 +33,14 @@ export class ImportController {
@Post('/organisations/:id/import')
@ContentType("application/json")
@OpenAPI({ description: "Create new runners from json" })
async postOrgsJSON(@Body({ validate: true, type: ImportSchoolRunner }) importRunners: ImportRunner[], @Param('id') id: number) {
async postOrgsJSON(@Body({ validate: true, type: ImportRunner }) importRunners: ImportRunner[], @Param('id') id: number) {
return await this.postJSON(importRunners, id)
}
@Post('/teams/:id/import')
@ContentType("application/json")
@OpenAPI({ description: "Create new runners from json" })
async postTeamsJSON(@Body({ validate: true, type: ImportSchoolRunner }) importRunners: ImportRunner[], @Param('id') id: number) {
async postTeamsJSON(@Body({ validate: true, type: ImportRunner }) importRunners: ImportRunner[], @Param('id') id: number) {
return await this.postJSON(importRunners, id)
}