Now organisations and teams can import runners
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Body, ContentType, Controller, Param, Post, QueryParam, Req, UseBefore } from 'routing-controllers';
|
||||
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';
|
||||
@@ -21,10 +22,11 @@ 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("org") orgID: number) {
|
||||
async postJSON(@Body({ validate: true, type: ImportSchoolRunner }) importRunners: ImportRunner[], @QueryParam("group") groupID: number) {
|
||||
if (!groupID) { throw new RunnerGroupNeededError(); }
|
||||
let responseRunners: ResponseRunner[] = new Array<ResponseRunner>();
|
||||
for await (let runner of importRunners) {
|
||||
responseRunners.push(await this.runnerController.post(await runner.toCreateRunner(orgID)));
|
||||
responseRunners.push(await this.runnerController.post(await runner.toCreateRunner(groupID)));
|
||||
}
|
||||
return responseRunners;
|
||||
}
|
||||
@@ -36,6 +38,13 @@ export class ImportController {
|
||||
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) {
|
||||
return await this.postJSON(importRunners, id)
|
||||
}
|
||||
|
||||
@Post('/runners/import/csv')
|
||||
@ContentType("text/csv")
|
||||
@UseBefore(RawBodyMiddleware)
|
||||
|
||||
Reference in New Issue
Block a user