Added endpoints for runner import by json and csv

This commit is contained in:
Nicolai Ort 2020-12-16 19:03:27 +01:00
parent b9fd2379f4
commit 2e4a4f1661
1 changed files with 17 additions and 7 deletions

View File

@ -1,7 +1,8 @@
import { Body, ContentType, Controller, Post } from 'routing-controllers';
import { ContentType, Controller, Post, Req, UseBefore } from 'routing-controllers';
import { OpenAPI } from 'routing-controllers-openapi';
import RawBodyMiddleware from '../middlewares/RawBody';
@Controller('/import')
@Controller()
//@Authorized("IMPORT:read")
export class ImportController {
// private runnerRepository: Repository<Runner>;
@ -13,11 +14,20 @@ export class ImportController {
//this.runnerRepository = getConnectionManager().get().getRepository(Runner);
}
@Post()
@Post('/runners/import')
@ContentType("application.json")
@OpenAPI({ description: "Create new runners from json" })
postJSON(@Req() request: any) {
console.log(request.rawBody.toString())
return request.rawBody.toString();
}
@Post('/runners/import/csv')
@ContentType("text/csv")
@OpenAPI({ description: "Create new runners based on a csv file" })
async post(@Body() body: any) {
console.log(body)
return body;
@UseBefore(RawBodyMiddleware)
@OpenAPI({ description: "Create new runners from csv" })
postCSV(@Req() request: any) {
console.log(request.rawBody.toString())
return request.rawBody.toString();
}
}