From fcfc10f7d123130a5abfb877035c0e073c885021 Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Sun, 6 Dec 2020 11:21:10 +0100 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9C=85=20phone=20countrycode=20validatio?= =?UTF-8?q?n=20in=20env=20vars?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ref #18 #16 --- src/config.ts | 3 ++- src/models/creation/CreateGroupContact.ts | 3 ++- src/models/entities/GroupContact.ts | 3 ++- src/models/entities/Participant.ts | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/config.ts b/src/config.ts index 5f54ce3..5dd7d19 100644 --- a/src/config.ts +++ b/src/config.ts @@ -3,5 +3,6 @@ dotenvSafe.config(); export const config = { internal_port: process.env.APP_PORT || 4010, development: process.env.NODE_ENV === "production", - jwt_secret: process.env.JWT_SECRET || "secretjwtsecret" + jwt_secret: process.env.JWT_SECRET || "secretjwtsecret", + phone_validation_countrycode: process.env.PHONE_COUNTRYCODE || "ZZ" } \ No newline at end of file diff --git a/src/models/creation/CreateGroupContact.ts b/src/models/creation/CreateGroupContact.ts index 73f43d0..d8aa815 100644 --- a/src/models/creation/CreateGroupContact.ts +++ b/src/models/creation/CreateGroupContact.ts @@ -1,5 +1,6 @@ import { IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString } from 'class-validator'; import { getConnectionManager } from 'typeorm'; +import { config } from '../../config'; import { AddressNotFoundError, AddressWrongTypeError } from '../../errors/AddressErrors'; import { Address } from '../entities/Address'; import { GroupContact } from '../entities/GroupContact'; @@ -40,7 +41,7 @@ export class CreateGroupContact { * Optional */ @IsOptional() - @IsPhoneNumber("DE") + @IsPhoneNumber(config.phone_validation_countrycode) phone?: string; /** diff --git a/src/models/entities/GroupContact.ts b/src/models/entities/GroupContact.ts index c7c8f18..08c5db3 100644 --- a/src/models/entities/GroupContact.ts +++ b/src/models/entities/GroupContact.ts @@ -8,6 +8,7 @@ import { IsString } from "class-validator"; import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm"; +import { config } from '../../config'; import { Address } from "./Address"; import { RunnerGroup } from "./RunnerGroup"; @@ -62,7 +63,7 @@ export class GroupContact { */ @Column({ nullable: true }) @IsOptional() - @IsPhoneNumber("DE") + @IsPhoneNumber(config.phone_validation_countrycode) phone?: string; /** diff --git a/src/models/entities/Participant.ts b/src/models/entities/Participant.ts index 2e40f5d..791b30d 100644 --- a/src/models/entities/Participant.ts +++ b/src/models/entities/Participant.ts @@ -8,6 +8,7 @@ import { IsString } from "class-validator"; import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, TableInheritance } from "typeorm"; +import { config } from '../../config'; import { Address } from "./Address"; import { Donation } from "./Donation"; @@ -62,7 +63,7 @@ export abstract class Participant { */ @Column({ nullable: true }) @IsOptional() - @IsPhoneNumber("DE") + @IsPhoneNumber(config.phone_validation_countrycode) phone?: string; /** From 4cfe9df429366c760a9a2346fe1256a8e0deb285 Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Wed, 9 Dec 2020 19:09:20 +0100 Subject: [PATCH 2/5] final phone validation move to ZZ default close #16 --- src/models/actions/CreateParticipant.ts | 3 ++- src/models/actions/CreateUser.ts | 3 ++- src/models/entities/User.ts | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/models/actions/CreateParticipant.ts b/src/models/actions/CreateParticipant.ts index 00c8783..9cd51ce 100644 --- a/src/models/actions/CreateParticipant.ts +++ b/src/models/actions/CreateParticipant.ts @@ -1,5 +1,6 @@ import { IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString } from 'class-validator'; import { getConnectionManager } from 'typeorm'; +import { config } from '../../config'; import { AddressNotFoundError, AddressWrongTypeError } from '../../errors/AddressErrors'; import { Address } from '../entities/Address'; @@ -32,7 +33,7 @@ export abstract class CreateParticipant { */ @IsString() @IsOptional() - @IsPhoneNumber("ZZ") + @IsPhoneNumber(config.phone_validation_countrycode) phone?: string; /** diff --git a/src/models/actions/CreateUser.ts b/src/models/actions/CreateUser.ts index ff6771a..d3c6ef6 100644 --- a/src/models/actions/CreateUser.ts +++ b/src/models/actions/CreateUser.ts @@ -2,6 +2,7 @@ import * as argon2 from "argon2"; import { IsEmail, IsOptional, IsPhoneNumber, IsString } from 'class-validator'; import { getConnectionManager } from 'typeorm'; import * as uuid from 'uuid'; +import { config } from '../../config'; import { UsernameOrEmailNeededError } from '../../errors/UserErrors'; import { UserGroupNotFoundError } from '../../errors/UserGroupErrors'; import { User } from '../entities/User'; @@ -49,7 +50,7 @@ export class CreateUser { * The new user's phone number. * Optional */ - @IsPhoneNumber("ZZ") + @IsPhoneNumber(config.phone_validation_countrycode) @IsOptional() phone?: string; diff --git a/src/models/entities/User.ts b/src/models/entities/User.ts index 8e29e27..ebc62b1 100644 --- a/src/models/entities/User.ts +++ b/src/models/entities/User.ts @@ -1,5 +1,6 @@ import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString, IsUUID } from "class-validator"; import { Column, Entity, JoinTable, ManyToMany, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm"; +import { config } from '../../config'; import { Permission } from './Permission'; import { UserAction } from './UserAction'; import { UserGroup } from './UserGroup'; @@ -35,7 +36,7 @@ export class User { */ @Column({ nullable: true }) @IsOptional() - @IsPhoneNumber("ZZ") + @IsPhoneNumber(config.phone_validation_countrycode) phone?: string; /** From a068c4d318dadc1860b796b231dafd3e2cf53714 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 9 Dec 2020 19:34:49 +0100 Subject: [PATCH 3/5] Deletes now return 204 instead of 404 (better rest compatability) ref #13 --- src/controllers/RunnerController.ts | 6 ++++-- src/controllers/RunnerOrganisationController.ts | 6 ++++-- src/controllers/RunnerTeamController.ts | 6 ++++-- src/controllers/TrackController.ts | 6 ++++-- src/controllers/UserController.ts | 6 ++++-- src/controllers/UserGroupController.ts | 6 ++++-- src/models/responses/ResponseEmpty.ts | 6 ++++++ 7 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 src/models/responses/ResponseEmpty.ts diff --git a/src/controllers/RunnerController.ts b/src/controllers/RunnerController.ts index 0a6ea34..1d61eba 100644 --- a/src/controllers/RunnerController.ts +++ b/src/controllers/RunnerController.ts @@ -6,6 +6,7 @@ import { RunnerGroupNeededError, RunnerIdsNotMatchingError, RunnerNotFoundError import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors'; import { CreateRunner } from '../models/actions/CreateRunner'; import { Runner } from '../models/entities/Runner'; +import { ResponseEmpty } from '../models/responses/ResponseEmpty'; import { ResponseRunner } from '../models/responses/ResponseRunner'; @JsonController('/runners') @@ -83,10 +84,11 @@ export class RunnerController { @Delete('/:id') @ResponseSchema(ResponseRunner) - @ResponseSchema(RunnerNotFoundError, { statusCode: 404 }) + @ResponseSchema(ResponseEmpty, { statusCode: 204 }) + @OnUndefined(204) @OpenAPI({ description: 'Delete a specified runner (if it exists).' }) async remove(@EntityFromParam('id') runner: Runner, @QueryParam("force") force: boolean) { - if (!runner) { throw new RunnerNotFoundError(); } + if (!runner) { return null; } const responseRunner = await this.runnerRepository.findOne(runner, { relations: ['scans', 'group'] }); if (!runner) { diff --git a/src/controllers/RunnerOrganisationController.ts b/src/controllers/RunnerOrganisationController.ts index a0914e3..f9733d5 100644 --- a/src/controllers/RunnerOrganisationController.ts +++ b/src/controllers/RunnerOrganisationController.ts @@ -5,6 +5,7 @@ import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-ext import { RunnerOrganisationHasRunnersError, RunnerOrganisationHasTeamsError, RunnerOrganisationIdsNotMatchingError, RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors'; import { CreateRunnerOrganisation } from '../models/actions/CreateRunnerOrganisation'; import { RunnerOrganisation } from '../models/entities/RunnerOrganisation'; +import { ResponseEmpty } from '../models/responses/ResponseEmpty'; import { ResponseRunnerOrganisation } from '../models/responses/ResponseRunnerOrganisation'; import { RunnerController } from './RunnerController'; import { RunnerTeamController } from './RunnerTeamController'; @@ -86,12 +87,13 @@ export class RunnerOrganisationController { @Delete('/:id') @ResponseSchema(ResponseRunnerOrganisation) - @ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 }) + @ResponseSchema(ResponseEmpty, { statusCode: 204 }) @ResponseSchema(RunnerOrganisationHasTeamsError, { statusCode: 406 }) @ResponseSchema(RunnerOrganisationHasRunnersError, { statusCode: 406 }) + @OnUndefined(204) @OpenAPI({ description: 'Delete a specified runnerOrganisation (if it exists).' }) async remove(@EntityFromParam('id') organisation: RunnerOrganisation, @QueryParam("force") force: boolean) { - if (!organisation) { throw new RunnerOrganisationNotFoundError() } + if (!organisation) { return null; } let runnerOrganisation = await this.runnerOrganisationRepository.findOne(organisation, { relations: ['address', 'contact', 'runners', 'teams'] }); if (!force) { diff --git a/src/controllers/RunnerTeamController.ts b/src/controllers/RunnerTeamController.ts index be44aac..4f69c36 100644 --- a/src/controllers/RunnerTeamController.ts +++ b/src/controllers/RunnerTeamController.ts @@ -5,6 +5,7 @@ import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-ext import { RunnerTeamHasRunnersError, RunnerTeamIdsNotMatchingError, RunnerTeamNotFoundError } from '../errors/RunnerTeamErrors'; import { CreateRunnerTeam } from '../models/actions/CreateRunnerTeam'; import { RunnerTeam } from '../models/entities/RunnerTeam'; +import { ResponseEmpty } from '../models/responses/ResponseEmpty'; import { ResponseRunnerTeam } from '../models/responses/ResponseRunnerTeam'; import { RunnerController } from './RunnerController'; @@ -86,11 +87,12 @@ export class RunnerTeamController { @Delete('/:id') @ResponseSchema(ResponseRunnerTeam) - @ResponseSchema(RunnerTeamNotFoundError, { statusCode: 404 }) + @ResponseSchema(ResponseEmpty, { statusCode: 204 }) @ResponseSchema(RunnerTeamHasRunnersError, { statusCode: 406 }) + @OnUndefined(204) @OpenAPI({ description: 'Delete a specified runnerTeam (if it exists).' }) async remove(@EntityFromParam('id') team: RunnerTeam, @QueryParam("force") force: boolean) { - if (!team) { throw new RunnerTeamNotFoundError(); } + if (!team) { return null; } let runnerTeam = await this.runnerTeamRepository.findOne(team, { relations: ['parentGroup', 'contact', 'runners'] }); if (!force) { diff --git a/src/controllers/TrackController.ts b/src/controllers/TrackController.ts index bf5fb71..d5fa9b6 100644 --- a/src/controllers/TrackController.ts +++ b/src/controllers/TrackController.ts @@ -5,6 +5,7 @@ import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-ext import { TrackIdsNotMatchingError, TrackNotFoundError } from "../errors/TrackErrors"; import { CreateTrack } from '../models/actions/CreateTrack'; import { Track } from '../models/entities/Track'; +import { ResponseEmpty } from '../models/responses/ResponseEmpty'; import { ResponseTrack } from '../models/responses/ResponseTrack'; @JsonController('/tracks') @@ -74,10 +75,11 @@ export class TrackController { @Delete('/:id') @ResponseSchema(ResponseTrack) - @ResponseSchema(TrackNotFoundError, { statusCode: 404 }) + @ResponseSchema(ResponseEmpty, { statusCode: 204 }) + @OnUndefined(204) @OpenAPI({ description: "Delete a specified track (if it exists)." }) async remove(@EntityFromParam('id') track: Track) { - if (!track) { throw new TrackNotFoundError(); } + if (!track) { return null; } await this.trackRepository.delete(track); return new ResponseTrack(track); diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index b5550a2..a5b3cdd 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -6,6 +6,7 @@ import { UserIdsNotMatchingError, UserNotFoundError } from '../errors/UserErrors import { UserGroupNotFoundError } from '../errors/UserGroupErrors'; import { CreateUser } from '../models/actions/CreateUser'; import { User } from '../models/entities/User'; +import { ResponseEmpty } from '../models/responses/ResponseEmpty'; @JsonController('/users') @@ -72,11 +73,12 @@ export class UserController { @Delete('/:id') @ResponseSchema(User) - @ResponseSchema(UserNotFoundError, { statusCode: 404 }) + @ResponseSchema(ResponseEmpty, { statusCode: 204 }) + @OnUndefined(204) @OpenAPI({ description: 'Delete a specified runner (if it exists).' }) async remove(@EntityFromParam('id') user: User) { if (!user) { - throw new UserNotFoundError(); + return null; } await this.userRepository.delete(user); diff --git a/src/controllers/UserGroupController.ts b/src/controllers/UserGroupController.ts index 89ef3b9..1d4bc38 100644 --- a/src/controllers/UserGroupController.ts +++ b/src/controllers/UserGroupController.ts @@ -5,6 +5,7 @@ import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-ext import { UserGroupIdsNotMatchingError, UserGroupNotFoundError } from '../errors/UserGroupErrors'; import { CreateUserGroup } from '../models/actions/CreateUserGroup'; import { UserGroup } from '../models/entities/UserGroup'; +import { ResponseEmpty } from '../models/responses/ResponseEmpty'; @JsonController('/usergroups') @@ -71,11 +72,12 @@ export class UserGroupController { @Delete('/:id') @ResponseSchema(UserGroup) - @ResponseSchema(UserGroupNotFoundError, { statusCode: 404 }) + @ResponseSchema(ResponseEmpty, { statusCode: 204 }) + @OnUndefined(204) @OpenAPI({ description: 'Delete a specified usergroup (if it exists).' }) async remove(@EntityFromParam('id') group: UserGroup) { if (!group) { - throw new UserGroupNotFoundError(); + return null; } await this.userGroupsRepository.delete(group); diff --git a/src/models/responses/ResponseEmpty.ts b/src/models/responses/ResponseEmpty.ts new file mode 100644 index 0000000..e1e3b41 --- /dev/null +++ b/src/models/responses/ResponseEmpty.ts @@ -0,0 +1,6 @@ + +/** + * Defines a empty response object +*/ +export class ResponseEmpty { +} From 622bdf7a3fb31e69ee28b43a02b3958c2568c31e Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Wed, 9 Dec 2020 19:40:08 +0100 Subject: [PATCH 4/5] move to dotenv + custom env validations ref #18 --- ormconfig.ts | 2 +- package.json | 4 ++-- src/app.ts | 9 +++++++-- src/config.ts | 22 ++++++++++++++++++---- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/ormconfig.ts b/ormconfig.ts index 852ff37..bf9be07 100644 --- a/ormconfig.ts +++ b/ormconfig.ts @@ -1,4 +1,4 @@ -import { config } from 'dotenv-safe'; +import { config } from 'dotenv'; config(); export default { diff --git a/package.json b/package.json index afc485d..baae298 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "class-validator-jsonschema": "^2.0.3", "consola": "^2.15.0", "cors": "^2.8.5", + "dotenv": "^8.2.0", "express": "^4.17.1", "helmet": "^4.2.0", "jsonwebtoken": "^8.5.1", @@ -45,14 +46,13 @@ }, "devDependencies": { "@types/cors": "^2.8.8", - "@types/dotenv-safe": "^8.1.1", + "@types/dotenv": "^8.2.0", "@types/express": "^4.17.9", "@types/jsonwebtoken": "^8.5.0", "@types/multer": "^1.4.4", "@types/node": "^14.14.9", "@types/swagger-ui-express": "^4.1.2", "@types/uuid": "^8.3.0", - "dotenv-safe": "^8.2.0", "nodemon": "^2.0.6", "sqlite3": "^5.0.0", "ts-node": "^9.0.0", diff --git a/src/app.ts b/src/app.ts index fd3dc8e..664ec6f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -2,7 +2,7 @@ import consola from "consola"; import "reflect-metadata"; import { createExpressServer } from "routing-controllers"; import authchecker from "./authchecker"; -import { config } from './config'; +import { config, e as errors } from './config'; import loaders from "./loaders/index"; import { ErrorHandler } from './middlewares/ErrorHandler'; @@ -23,4 +23,9 @@ async function main() { ); }); } -main(); +if (errors === 0) { + main(); +} else { + console.log("error"); + // something's wrong +} diff --git a/src/config.ts b/src/config.ts index 5dd7d19..567e35b 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,8 +1,22 @@ -import * as dotenvSafe from "dotenv-safe"; -dotenvSafe.config(); +import { config as configDotenv } from 'dotenv'; +configDotenv(); export const config = { - internal_port: process.env.APP_PORT || 4010, + internal_port: parseInt(process.env.APP_PORT) || 4010, development: process.env.NODE_ENV === "production", jwt_secret: process.env.JWT_SECRET || "secretjwtsecret", phone_validation_countrycode: process.env.PHONE_COUNTRYCODE || "ZZ" -} \ No newline at end of file +} +let errors = 0 +if (typeof config.internal_port !== "number") { + errors++ +} +if (typeof config.phone_validation_countrycode !== "string") { + errors++ +} +if (config.phone_validation_countrycode.length !== 2) { + errors++ +} +if (typeof config.development !== "boolean") { + errors++ +} +export let e = errors \ No newline at end of file From df5b8ac141ebd009018537ca6107f212dc6403c6 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 9 Dec 2020 19:41:15 +0100 Subject: [PATCH 5/5] Went back to using id's for deletion (for cleaner query params) ref #13 #17 --- src/controllers/RunnerController.ts | 5 +++-- src/controllers/RunnerOrganisationController.ts | 9 +++++---- src/controllers/RunnerTeamController.ts | 7 ++++--- src/controllers/TrackController.ts | 5 +++-- src/controllers/UserController.ts | 5 +++-- src/controllers/UserGroupController.ts | 5 +++-- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/controllers/RunnerController.ts b/src/controllers/RunnerController.ts index 1d61eba..53b869d 100644 --- a/src/controllers/RunnerController.ts +++ b/src/controllers/RunnerController.ts @@ -1,7 +1,7 @@ import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers'; import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { getConnectionManager, Repository } from 'typeorm'; -import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions'; +import { EntityFromBody } from 'typeorm-routing-controllers-extensions'; import { RunnerGroupNeededError, RunnerIdsNotMatchingError, RunnerNotFoundError } from '../errors/RunnerErrors'; import { RunnerGroupNotFoundError } from '../errors/RunnerGroupErrors'; import { CreateRunner } from '../models/actions/CreateRunner'; @@ -87,7 +87,8 @@ export class RunnerController { @ResponseSchema(ResponseEmpty, { statusCode: 204 }) @OnUndefined(204) @OpenAPI({ description: 'Delete a specified runner (if it exists).' }) - async remove(@EntityFromParam('id') runner: Runner, @QueryParam("force") force: boolean) { + async remove(@Param("id") id: number, @QueryParam("force") force: boolean) { + let runner = await this.runnerRepository.findOne({ id: id }); if (!runner) { return null; } const responseRunner = await this.runnerRepository.findOne(runner, { relations: ['scans', 'group'] }); diff --git a/src/controllers/RunnerOrganisationController.ts b/src/controllers/RunnerOrganisationController.ts index f9733d5..8471e90 100644 --- a/src/controllers/RunnerOrganisationController.ts +++ b/src/controllers/RunnerOrganisationController.ts @@ -1,7 +1,7 @@ import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers'; import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { getConnectionManager, Repository } from 'typeorm'; -import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions'; +import { EntityFromBody } from 'typeorm-routing-controllers-extensions'; import { RunnerOrganisationHasRunnersError, RunnerOrganisationHasTeamsError, RunnerOrganisationIdsNotMatchingError, RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors'; import { CreateRunnerOrganisation } from '../models/actions/CreateRunnerOrganisation'; import { RunnerOrganisation } from '../models/entities/RunnerOrganisation'; @@ -92,7 +92,8 @@ export class RunnerOrganisationController { @ResponseSchema(RunnerOrganisationHasRunnersError, { statusCode: 406 }) @OnUndefined(204) @OpenAPI({ description: 'Delete a specified runnerOrganisation (if it exists).' }) - async remove(@EntityFromParam('id') organisation: RunnerOrganisation, @QueryParam("force") force: boolean) { + async remove(@Param("id") id: number, @QueryParam("force") force: boolean) { + let organisation = await this.runnerOrganisationRepository.findOne({ id: id }); if (!organisation) { return null; } let runnerOrganisation = await this.runnerOrganisationRepository.findOne(organisation, { relations: ['address', 'contact', 'runners', 'teams'] }); @@ -103,7 +104,7 @@ export class RunnerOrganisationController { } const teamController = new RunnerTeamController() for (let team of runnerOrganisation.teams) { - await teamController.remove(team, true); + await teamController.remove(team.id, true); } if (!force) { @@ -113,7 +114,7 @@ export class RunnerOrganisationController { } const runnerController = new RunnerController() for (let runner of runnerOrganisation.runners) { - await runnerController.remove(runner, true); + await runnerController.remove(runner.id, true); } const responseOrganisation = new ResponseRunnerOrganisation(runnerOrganisation); diff --git a/src/controllers/RunnerTeamController.ts b/src/controllers/RunnerTeamController.ts index 4f69c36..2eeae3e 100644 --- a/src/controllers/RunnerTeamController.ts +++ b/src/controllers/RunnerTeamController.ts @@ -1,7 +1,7 @@ import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers'; import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { getConnectionManager, Repository } from 'typeorm'; -import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions'; +import { EntityFromBody } from 'typeorm-routing-controllers-extensions'; import { RunnerTeamHasRunnersError, RunnerTeamIdsNotMatchingError, RunnerTeamNotFoundError } from '../errors/RunnerTeamErrors'; import { CreateRunnerTeam } from '../models/actions/CreateRunnerTeam'; import { RunnerTeam } from '../models/entities/RunnerTeam'; @@ -91,7 +91,8 @@ export class RunnerTeamController { @ResponseSchema(RunnerTeamHasRunnersError, { statusCode: 406 }) @OnUndefined(204) @OpenAPI({ description: 'Delete a specified runnerTeam (if it exists).' }) - async remove(@EntityFromParam('id') team: RunnerTeam, @QueryParam("force") force: boolean) { + async remove(@Param("id") id: number, @QueryParam("force") force: boolean) { + let team = await this.runnerTeamRepository.findOne({ id: id }); if (!team) { return null; } let runnerTeam = await this.runnerTeamRepository.findOne(team, { relations: ['parentGroup', 'contact', 'runners'] }); @@ -102,7 +103,7 @@ export class RunnerTeamController { } const runnerController = new RunnerController() for (let runner of runnerTeam.runners) { - await runnerController.remove(runner, true); + await runnerController.remove(runner.id, true); } const responseTeam = new ResponseRunnerTeam(runnerTeam); diff --git a/src/controllers/TrackController.ts b/src/controllers/TrackController.ts index d5fa9b6..e17e098 100644 --- a/src/controllers/TrackController.ts +++ b/src/controllers/TrackController.ts @@ -1,7 +1,7 @@ import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put } from 'routing-controllers'; import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { getConnectionManager, Repository } from 'typeorm'; -import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions'; +import { EntityFromBody } from 'typeorm-routing-controllers-extensions'; import { TrackIdsNotMatchingError, TrackNotFoundError } from "../errors/TrackErrors"; import { CreateTrack } from '../models/actions/CreateTrack'; import { Track } from '../models/entities/Track'; @@ -78,7 +78,8 @@ export class TrackController { @ResponseSchema(ResponseEmpty, { statusCode: 204 }) @OnUndefined(204) @OpenAPI({ description: "Delete a specified track (if it exists)." }) - async remove(@EntityFromParam('id') track: Track) { + async remove(@Param("id") id: number) { + let track = await this.trackRepository.findOne({ id: id }); if (!track) { return null; } await this.trackRepository.delete(track); diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index a5b3cdd..f71fd60 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -1,7 +1,7 @@ import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put } from 'routing-controllers'; import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { getConnectionManager, Repository } from 'typeorm'; -import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions'; +import { EntityFromBody } from 'typeorm-routing-controllers-extensions'; import { UserIdsNotMatchingError, UserNotFoundError } from '../errors/UserErrors'; import { UserGroupNotFoundError } from '../errors/UserGroupErrors'; import { CreateUser } from '../models/actions/CreateUser'; @@ -76,7 +76,8 @@ export class UserController { @ResponseSchema(ResponseEmpty, { statusCode: 204 }) @OnUndefined(204) @OpenAPI({ description: 'Delete a specified runner (if it exists).' }) - async remove(@EntityFromParam('id') user: User) { + async remove(@Param("id") id: number) { + let user = await this.userRepository.findOne({ id: id }); if (!user) { return null; } diff --git a/src/controllers/UserGroupController.ts b/src/controllers/UserGroupController.ts index 1d4bc38..a317366 100644 --- a/src/controllers/UserGroupController.ts +++ b/src/controllers/UserGroupController.ts @@ -1,7 +1,7 @@ import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put } from 'routing-controllers'; import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { getConnectionManager, Repository } from 'typeorm'; -import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions'; +import { EntityFromBody } from 'typeorm-routing-controllers-extensions'; import { UserGroupIdsNotMatchingError, UserGroupNotFoundError } from '../errors/UserGroupErrors'; import { CreateUserGroup } from '../models/actions/CreateUserGroup'; import { UserGroup } from '../models/entities/UserGroup'; @@ -75,7 +75,8 @@ export class UserGroupController { @ResponseSchema(ResponseEmpty, { statusCode: 204 }) @OnUndefined(204) @OpenAPI({ description: 'Delete a specified usergroup (if it exists).' }) - async remove(@EntityFromParam('id') group: UserGroup) { + async remove(@Param("id") id: number) { + let group = await this.userGroupsRepository.findOne({ id: id }); if (!group) { return null; }