Runners can now be imported into a org

This commit is contained in:
Nicolai Ort 2020-12-17 16:46:00 +01:00
parent 4801e010b4
commit 97494aeaf7
1 changed files with 10 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import { Body, ContentType, Controller, Post, Req, UseBefore } from 'routing-controllers';
import { Body, ContentType, Controller, Param, Post, QueryParam, Req, UseBefore } from 'routing-controllers';
import { OpenAPI } from 'routing-controllers-openapi';
import RawBodyMiddleware from '../middlewares/RawBody';
import { ImportRunner } from '../models/actions/ImportRunner';
@ -21,14 +21,21 @@ 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[]) {
async postJSON(@Body({ validate: true, type: ImportSchoolRunner }) importRunners: ImportRunner[], @QueryParam("org") orgID: number) {
let responseRunners: ResponseRunner[] = new Array<ResponseRunner>();
for await (let runner of importRunners) {
responseRunners.push(await this.runnerController.post(await runner.toCreateRunner(1)));
responseRunners.push(await this.runnerController.post(await runner.toCreateRunner(orgID)));
}
return responseRunners;
}
@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) {
return await this.postJSON(importRunners, id)
}
@Post('/runners/import/csv')
@ContentType("text/csv")
@UseBefore(RawBodyMiddleware)