From 1b59d58c6023803a5b729b0a274c6d17013219d7 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Thu, 17 Dec 2020 16:32:29 +0100 Subject: [PATCH] Abstracted a little bit more for potential company runner import --- src/controllers/ImportController.ts | 3 ++- src/models/actions/ImportRunner.ts | 4 +++- src/models/actions/ImportSchoolRunner.ts | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/controllers/ImportController.ts b/src/controllers/ImportController.ts index 746fbe8..18a5991 100644 --- a/src/controllers/ImportController.ts +++ b/src/controllers/ImportController.ts @@ -1,6 +1,7 @@ import { Body, ContentType, Controller, Post, Req, UseBefore } from 'routing-controllers'; import { OpenAPI } from 'routing-controllers-openapi'; 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'; @@ -20,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: ImportSchoolRunner[]) { + async postJSON(@Body({ validate: true, type: ImportSchoolRunner }) importRunners: ImportRunner[]) { let responseRunners: ResponseRunner[] = new Array(); for await (let runner of importRunners) { responseRunners.push(await this.runnerController.post(await runner.toCreateRunner(1))); diff --git a/src/models/actions/ImportRunner.ts b/src/models/actions/ImportRunner.ts index 2adb5cc..ba7daa2 100644 --- a/src/models/actions/ImportRunner.ts +++ b/src/models/actions/ImportRunner.ts @@ -1,6 +1,6 @@ import { IsNotEmpty, IsOptional, IsString } from 'class-validator'; -export class ImportRunner { +export abstract class ImportRunner { /** * The new runner's first name. @@ -23,4 +23,6 @@ export class ImportRunner { @IsString() @IsNotEmpty() lastname: string; + + public abstract toCreateRunner(groupID?: number); } \ No newline at end of file diff --git a/src/models/actions/ImportSchoolRunner.ts b/src/models/actions/ImportSchoolRunner.ts index 9964442..18db259 100644 --- a/src/models/actions/ImportSchoolRunner.ts +++ b/src/models/actions/ImportSchoolRunner.ts @@ -18,13 +18,13 @@ export class ImportSchoolRunner extends ImportRunner { @IsNotEmpty() class: string; - public async toCreateRunner(orgID: number): Promise { + public async toCreateRunner(groupID: number): Promise { let newRunner: CreateRunner = new CreateRunner(); newRunner.firstname = this.firstname; newRunner.middlename = this.middlename; newRunner.lastname = this.lastname; - newRunner.group = (await this.getGroup(orgID)).id; + newRunner.group = (await this.getGroup(groupID)).id; console.log(newRunner.group) return newRunner;