Runners can now be imported into a org
This commit is contained in:
parent
4801e010b4
commit
97494aeaf7
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue