From c6c643ecf125f5fdf58b105f97efad32e8545dd4 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Sun, 24 Jan 2021 18:40:46 +0100 Subject: [PATCH] =?UTF-8?q?Renamed=20files=20and=20classed=20from=20*Organ?= =?UTF-8?q?isation*=20to=20*Organization*=F0=9F=93=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ref #117 --- .../RunnerOrganisationController.ts | 127 ------------------ .../RunnerOrganizationController.ts | 127 ++++++++++++++++++ .../RunnerSelfServiceController.ts | 14 +- src/controllers/StatsController.ts | 10 +- ...nErrors.ts => RunnerOrganizationErrors.ts} | 24 ++-- src/models/actions/ImportRunner.ts | 8 +- src/models/actions/create/CreateRunner.ts | 4 +- .../create/CreateRunnerOrganisation.ts | 43 ------ .../create/CreateRunnerOrganization.ts | 43 ++++++ src/models/actions/create/CreateRunnerTeam.ts | 10 +- .../create/CreateSelfServiceCitizenRunner.ts | 6 +- ...isation.ts => UpdateRunnerOrganization.ts} | 10 +- src/models/actions/update/UpdateRunnerTeam.ts | 10 +- ...rOrganisation.ts => RunnerOrganization.ts} | 10 +- src/models/entities/RunnerTeam.ts | 8 +- ...ation.ts => ResponseRunnerOrganization.ts} | 16 +-- src/models/responses/ResponseRunnerTeam.ts | 4 +- src/models/responses/ResponseStats.ts | 4 +- ...sation.ts => ResponseStatsOrganization.ts} | 4 +- src/seeds/SeedPublicOrg.ts | 8 +- src/seeds/SeedTestRunners.ts | 14 +- 21 files changed, 252 insertions(+), 252 deletions(-) delete mode 100644 src/controllers/RunnerOrganisationController.ts create mode 100644 src/controllers/RunnerOrganizationController.ts rename src/errors/{RunnerOrganisationErrors.ts => RunnerOrganizationErrors.ts} (66%) delete mode 100644 src/models/actions/create/CreateRunnerOrganisation.ts create mode 100644 src/models/actions/create/CreateRunnerOrganization.ts rename src/models/actions/update/{UpdateRunnerOrganisation.ts => UpdateRunnerOrganization.ts} (78%) rename src/models/entities/{RunnerOrganisation.ts => RunnerOrganization.ts} (86%) rename src/models/responses/{ResponseRunnerOrganisation.ts => ResponseRunnerOrganization.ts} (69%) rename src/models/responses/{ResponseStatsOrganisation.ts => ResponseStatsOrganization.ts} (90%) diff --git a/src/controllers/RunnerOrganisationController.ts b/src/controllers/RunnerOrganisationController.ts deleted file mode 100644 index 71465f2..0000000 --- a/src/controllers/RunnerOrganisationController.ts +++ /dev/null @@ -1,127 +0,0 @@ -import { Authorized, 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 { RunnerOrganisationHasRunnersError, RunnerOrganisationHasTeamsError, RunnerOrganisationIdsNotMatchingError, RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors'; -import { CreateRunnerOrganisation } from '../models/actions/create/CreateRunnerOrganisation'; -import { UpdateRunnerOrganisation } from '../models/actions/update/UpdateRunnerOrganisation'; -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'; - - -@JsonController('/organizations') -@OpenAPI({ security: [{ "AuthToken": [] }, { "RefreshTokenCookie": [] }] }) -export class RunnerOrganisationController { - private runnerOrganisationRepository: Repository; - - /** - * Gets the repository of this controller's model/entity. - */ - constructor() { - this.runnerOrganisationRepository = getConnectionManager().get().getRepository(RunnerOrganisation); - } - - @Get() - @Authorized("ORGANISATION:GET") - @ResponseSchema(ResponseRunnerOrganisation, { isArray: true }) - @OpenAPI({ description: 'Lists all organizations.
This includes their address, contact and teams (if existing/associated).' }) - async getAll() { - let responseTeams: ResponseRunnerOrganisation[] = new Array(); - const runners = await this.runnerOrganisationRepository.find({ relations: ['contact', 'teams'] }); - runners.forEach(runner => { - responseTeams.push(new ResponseRunnerOrganisation(runner)); - }); - return responseTeams; - } - - @Get('/:id') - @Authorized("ORGANISATION:GET") - @ResponseSchema(ResponseRunnerOrganisation) - @ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 }) - @OnUndefined(RunnerOrganisationNotFoundError) - @OpenAPI({ description: 'Lists all information about the organization whose id got provided.' }) - async getOne(@Param('id') id: number) { - let runnerOrg = await this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['contact', 'teams'] }); - if (!runnerOrg) { throw new RunnerOrganisationNotFoundError(); } - return new ResponseRunnerOrganisation(runnerOrg); - } - - @Post() - @Authorized("ORGANISATION:CREATE") - @ResponseSchema(ResponseRunnerOrganisation) - @OpenAPI({ description: 'Create a new organsisation.' }) - async post(@Body({ validate: true }) createRunnerOrganisation: CreateRunnerOrganisation) { - let runnerOrganisation; - try { - runnerOrganisation = await createRunnerOrganisation.toEntity(); - } catch (error) { - throw error; - } - - runnerOrganisation = await this.runnerOrganisationRepository.save(runnerOrganisation); - - return new ResponseRunnerOrganisation(await this.runnerOrganisationRepository.findOne(runnerOrganisation, { relations: ['contact', 'teams'] })); - } - - @Put('/:id') - @Authorized("ORGANISATION:UPDATE") - @ResponseSchema(ResponseRunnerOrganisation) - @ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 }) - @ResponseSchema(RunnerOrganisationIdsNotMatchingError, { statusCode: 406 }) - @OpenAPI({ description: "Update the organization whose id you provided.
Please remember that ids can't be changed." }) - async put(@Param('id') id: number, @Body({ validate: true }) updateOrganisation: UpdateRunnerOrganisation) { - let oldRunnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id }); - - if (!oldRunnerOrganisation) { - throw new RunnerOrganisationNotFoundError(); - } - - if (oldRunnerOrganisation.id != updateOrganisation.id) { - throw new RunnerOrganisationIdsNotMatchingError(); - } - - await this.runnerOrganisationRepository.save(await updateOrganisation.update(oldRunnerOrganisation)); - - return new ResponseRunnerOrganisation(await this.runnerOrganisationRepository.findOne(id, { relations: ['contact', 'teams'] })); - } - - @Delete('/:id') - @Authorized("ORGANISATION:DELETE") - @ResponseSchema(ResponseRunnerOrganisation) - @ResponseSchema(ResponseEmpty, { statusCode: 204 }) - @ResponseSchema(RunnerOrganisationHasTeamsError, { statusCode: 406 }) - @ResponseSchema(RunnerOrganisationHasRunnersError, { statusCode: 406 }) - @OnUndefined(204) - @OpenAPI({ description: 'Delete the organsisation whose id you provided.
If the organization still has runners and/or teams associated this will fail.
To delete the organization with all associated runners and teams set the force QueryParam to true (cascading deletion might take a while).
This won\'t delete the associated contact.
If no organization with this id exists it will just return 204(no content).' }) - async remove(@Param("id") id: number, @QueryParam("force") force: boolean) { - let organization = await this.runnerOrganisationRepository.findOne({ id: id }); - if (!organization) { return null; } - let runnerOrganisation = await this.runnerOrganisationRepository.findOne(organization, { relations: ['contact', 'runners', 'teams'] }); - - if (!force) { - if (runnerOrganisation.teams.length != 0) { - throw new RunnerOrganisationHasTeamsError(); - } - } - const teamController = new RunnerTeamController() - for (let team of runnerOrganisation.teams) { - await teamController.remove(team.id, true); - } - - if (!force) { - if (runnerOrganisation.runners.length != 0) { - throw new RunnerOrganisationHasRunnersError(); - } - } - const runnerController = new RunnerController() - for (let runner of runnerOrganisation.runners) { - await runnerController.remove(runner.id, true); - } - - const responseOrganisation = new ResponseRunnerOrganisation(runnerOrganisation); - await this.runnerOrganisationRepository.delete(organization); - return responseOrganisation; - } -} diff --git a/src/controllers/RunnerOrganizationController.ts b/src/controllers/RunnerOrganizationController.ts new file mode 100644 index 0000000..b4dcc70 --- /dev/null +++ b/src/controllers/RunnerOrganizationController.ts @@ -0,0 +1,127 @@ +import { Authorized, 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 { RunnerOrganizationHasRunnersError, RunnerOrganizationHasTeamsError, RunnerOrganizationIdsNotMatchingError, RunnerOrganizationNotFoundError } from '../errors/RunnerOrganizationErrors'; +import { CreateRunnerOrganization } from '../models/actions/create/CreateRunnerOrganization'; +import { UpdateRunnerOrganization } from '../models/actions/update/UpdateRunnerOrganization'; +import { RunnerOrganization } from '../models/entities/RunnerOrganization'; +import { ResponseEmpty } from '../models/responses/ResponseEmpty'; +import { ResponseRunnerOrganization } from '../models/responses/ResponseRunnerOrganization'; +import { RunnerController } from './RunnerController'; +import { RunnerTeamController } from './RunnerTeamController'; + + +@JsonController('/organizations') +@OpenAPI({ security: [{ "AuthToken": [] }, { "RefreshTokenCookie": [] }] }) +export class RunnerOrganizationController { + private runnerOrganizationRepository: Repository; + + /** + * Gets the repository of this controller's model/entity. + */ + constructor() { + this.runnerOrganizationRepository = getConnectionManager().get().getRepository(RunnerOrganization); + } + + @Get() + @Authorized("ORGANISATION:GET") + @ResponseSchema(ResponseRunnerOrganization, { isArray: true }) + @OpenAPI({ description: 'Lists all organizations.
This includes their address, contact and teams (if existing/associated).' }) + async getAll() { + let responseTeams: ResponseRunnerOrganization[] = new Array(); + const runners = await this.runnerOrganizationRepository.find({ relations: ['contact', 'teams'] }); + runners.forEach(runner => { + responseTeams.push(new ResponseRunnerOrganization(runner)); + }); + return responseTeams; + } + + @Get('/:id') + @Authorized("ORGANISATION:GET") + @ResponseSchema(ResponseRunnerOrganization) + @ResponseSchema(RunnerOrganizationNotFoundError, { statusCode: 404 }) + @OnUndefined(RunnerOrganizationNotFoundError) + @OpenAPI({ description: 'Lists all information about the organization whose id got provided.' }) + async getOne(@Param('id') id: number) { + let runnerOrg = await this.runnerOrganizationRepository.findOne({ id: id }, { relations: ['contact', 'teams'] }); + if (!runnerOrg) { throw new RunnerOrganizationNotFoundError(); } + return new ResponseRunnerOrganization(runnerOrg); + } + + @Post() + @Authorized("ORGANISATION:CREATE") + @ResponseSchema(ResponseRunnerOrganization) + @OpenAPI({ description: 'Create a new organsisation.' }) + async post(@Body({ validate: true }) createRunnerOrganization: CreateRunnerOrganization) { + let runnerOrganization; + try { + runnerOrganization = await createRunnerOrganization.toEntity(); + } catch (error) { + throw error; + } + + runnerOrganization = await this.runnerOrganizationRepository.save(runnerOrganization); + + return new ResponseRunnerOrganization(await this.runnerOrganizationRepository.findOne(runnerOrganization, { relations: ['contact', 'teams'] })); + } + + @Put('/:id') + @Authorized("ORGANISATION:UPDATE") + @ResponseSchema(ResponseRunnerOrganization) + @ResponseSchema(RunnerOrganizationNotFoundError, { statusCode: 404 }) + @ResponseSchema(RunnerOrganizationIdsNotMatchingError, { statusCode: 406 }) + @OpenAPI({ description: "Update the organization whose id you provided.
Please remember that ids can't be changed." }) + async put(@Param('id') id: number, @Body({ validate: true }) updateOrganization: UpdateRunnerOrganization) { + let oldRunnerOrganization = await this.runnerOrganizationRepository.findOne({ id: id }); + + if (!oldRunnerOrganization) { + throw new RunnerOrganizationNotFoundError(); + } + + if (oldRunnerOrganization.id != updateOrganization.id) { + throw new RunnerOrganizationIdsNotMatchingError(); + } + + await this.runnerOrganizationRepository.save(await updateOrganization.update(oldRunnerOrganization)); + + return new ResponseRunnerOrganization(await this.runnerOrganizationRepository.findOne(id, { relations: ['contact', 'teams'] })); + } + + @Delete('/:id') + @Authorized("ORGANISATION:DELETE") + @ResponseSchema(ResponseRunnerOrganization) + @ResponseSchema(ResponseEmpty, { statusCode: 204 }) + @ResponseSchema(RunnerOrganizationHasTeamsError, { statusCode: 406 }) + @ResponseSchema(RunnerOrganizationHasRunnersError, { statusCode: 406 }) + @OnUndefined(204) + @OpenAPI({ description: 'Delete the organsisation whose id you provided.
If the organization still has runners and/or teams associated this will fail.
To delete the organization with all associated runners and teams set the force QueryParam to true (cascading deletion might take a while).
This won\'t delete the associated contact.
If no organization with this id exists it will just return 204(no content).' }) + async remove(@Param("id") id: number, @QueryParam("force") force: boolean) { + let organization = await this.runnerOrganizationRepository.findOne({ id: id }); + if (!organization) { return null; } + let runnerOrganization = await this.runnerOrganizationRepository.findOne(organization, { relations: ['contact', 'runners', 'teams'] }); + + if (!force) { + if (runnerOrganization.teams.length != 0) { + throw new RunnerOrganizationHasTeamsError(); + } + } + const teamController = new RunnerTeamController() + for (let team of runnerOrganization.teams) { + await teamController.remove(team.id, true); + } + + if (!force) { + if (runnerOrganization.runners.length != 0) { + throw new RunnerOrganizationHasRunnersError(); + } + } + const runnerController = new RunnerController() + for (let runner of runnerOrganization.runners) { + await runnerController.remove(runner.id, true); + } + + const responseOrganization = new ResponseRunnerOrganization(runnerOrganization); + await this.runnerOrganizationRepository.delete(organization); + return responseOrganization; + } +} diff --git a/src/controllers/RunnerSelfServiceController.ts b/src/controllers/RunnerSelfServiceController.ts index eb5070d..eb35f48 100644 --- a/src/controllers/RunnerSelfServiceController.ts +++ b/src/controllers/RunnerSelfServiceController.ts @@ -5,27 +5,27 @@ import { getConnectionManager, Repository } from 'typeorm'; import { config } from '../config'; import { InvalidCredentialsError, JwtNotProvidedError } from '../errors/AuthError'; import { RunnerEmailNeededError, RunnerNotFoundError } from '../errors/RunnerErrors'; -import { RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors'; +import { RunnerOrganizationNotFoundError } from '../errors/RunnerOrganizationErrors'; import { JwtCreator } from '../jwtcreator'; import { CreateSelfServiceCitizenRunner } from '../models/actions/create/CreateSelfServiceCitizenRunner'; import { CreateSelfServiceRunner } from '../models/actions/create/CreateSelfServiceRunner'; import { Runner } from '../models/entities/Runner'; import { RunnerGroup } from '../models/entities/RunnerGroup'; -import { RunnerOrganisation } from '../models/entities/RunnerOrganisation'; +import { RunnerOrganization } from '../models/entities/RunnerOrganization'; import { ResponseSelfServiceRunner } from '../models/responses/ResponseSelfServiceRunner'; @JsonController('/runners') export class RunnerSelfServiceController { private runnerRepository: Repository; - private orgRepository: Repository; + private orgRepository: Repository; /** * Gets the repository of this controller's model/entity. */ constructor() { this.runnerRepository = getConnectionManager().get().getRepository(Runner); - this.orgRepository = getConnectionManager().get().getRepository(RunnerOrganisation); + this.orgRepository = getConnectionManager().get().getRepository(RunnerOrganization); } @Get('/me/:jwt') @@ -52,9 +52,9 @@ export class RunnerSelfServiceController { @Post('/register/:token') @ResponseSchema(ResponseSelfServiceRunner) - @ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 }) + @ResponseSchema(RunnerOrganizationNotFoundError, { statusCode: 404 }) @OpenAPI({ description: 'Create a new selfservice runner in a provided org.
The orgs get provided and authorized via api tokens that can be optained via the /organizations endpoint.' }) - async registerOrganisationRunner(@Param('token') token: string, @Body({ validate: true }) createRunner: CreateSelfServiceRunner) { + async registerOrganizationRunner(@Param('token') token: string, @Body({ validate: true }) createRunner: CreateSelfServiceRunner) { const org = await this.getOrgansisation(token); let runner = await createRunner.toEntity(org); @@ -91,7 +91,7 @@ export class RunnerSelfServiceController { token = Buffer.from(token, 'base64').toString('utf8'); const organization = await this.orgRepository.findOne({ key: token }); - if (!organization) { throw new RunnerOrganisationNotFoundError; } + if (!organization) { throw new RunnerOrganizationNotFoundError; } return organization; } diff --git a/src/controllers/StatsController.ts b/src/controllers/StatsController.ts index d0cf8b6..ccc9527 100644 --- a/src/controllers/StatsController.ts +++ b/src/controllers/StatsController.ts @@ -4,12 +4,12 @@ import { getConnection } from 'typeorm'; import StatsAuth from '../middlewares/StatsAuth'; import { Donation } from '../models/entities/Donation'; import { Runner } from '../models/entities/Runner'; -import { RunnerOrganisation } from '../models/entities/RunnerOrganisation'; +import { RunnerOrganization } from '../models/entities/RunnerOrganization'; import { RunnerTeam } from '../models/entities/RunnerTeam'; import { Scan } from '../models/entities/Scan'; import { User } from '../models/entities/User'; import { ResponseStats } from '../models/responses/ResponseStats'; -import { ResponseStatsOrgnisation } from '../models/responses/ResponseStatsOrganisation'; +import { ResponseStatsOrgnisation } from '../models/responses/ResponseStatsOrganization'; import { ResponseStatsRunner } from '../models/responses/ResponseStatsRunner'; import { ResponseStatsTeam } from '../models/responses/ResponseStatsTeam'; @@ -23,7 +23,7 @@ export class StatsController { let connection = getConnection(); let runners = await connection.getRepository(Runner).find({ relations: ['scans', 'scans.track'] }); let teams = await connection.getRepository(RunnerTeam).find(); - let orgs = await connection.getRepository(RunnerOrganisation).find(); + let orgs = await connection.getRepository(RunnerOrganization).find(); let users = await connection.getRepository(User).find(); let scans = await connection.getRepository(Scan).find(); let donations = await connection.getRepository(Donation).find({ relations: ['runner', 'runner.scans', 'runner.scans.track'] }); @@ -99,7 +99,7 @@ export class StatsController { @ResponseSchema(ResponseStatsOrgnisation, { isArray: true }) @OpenAPI({ description: "Returns the top ten organizations by distance.", security: [{ "StatsApiToken": [] }, { "AuthToken": [] }, { "RefreshTokenCookie": [] }] }) async getTopOrgsByDistance() { - let orgs = await getConnection().getRepository(RunnerOrganisation).find({ relations: ['runners', 'runners.scans', 'runners.distanceDonations', 'runners.scans.track', 'teams', 'teams.runners', 'teams.runners.scans', 'teams.runners.distanceDonations', 'teams.runners.scans.track'] }); + let orgs = await getConnection().getRepository(RunnerOrganization).find({ relations: ['runners', 'runners.scans', 'runners.distanceDonations', 'runners.scans.track', 'teams', 'teams.runners', 'teams.runners.scans', 'teams.runners.distanceDonations', 'teams.runners.scans.track'] }); let topOrgs = orgs.sort((org1, org2) => org1.distance - org2.distance).slice(0, 9); let responseOrgs: ResponseStatsOrgnisation[] = new Array(); topOrgs.forEach(org => { @@ -113,7 +113,7 @@ export class StatsController { @ResponseSchema(ResponseStatsOrgnisation, { isArray: true }) @OpenAPI({ description: "Returns the top ten organizations by donations.", security: [{ "StatsApiToken": [] }, { "AuthToken": [] }, { "RefreshTokenCookie": [] }] }) async getTopOrgsByDonations() { - let orgs = await getConnection().getRepository(RunnerOrganisation).find({ relations: ['runners', 'runners.scans', 'runners.distanceDonations', 'runners.scans.track', 'teams', 'teams.runners', 'teams.runners.scans', 'teams.runners.distanceDonations', 'teams.runners.scans.track'] }); + let orgs = await getConnection().getRepository(RunnerOrganization).find({ relations: ['runners', 'runners.scans', 'runners.distanceDonations', 'runners.scans.track', 'teams', 'teams.runners', 'teams.runners.scans', 'teams.runners.distanceDonations', 'teams.runners.scans.track'] }); let topOrgs = orgs.sort((org1, org2) => org1.distanceDonationAmount - org2.distanceDonationAmount).slice(0, 9); let responseOrgs: ResponseStatsOrgnisation[] = new Array(); topOrgs.forEach(org => { diff --git a/src/errors/RunnerOrganisationErrors.ts b/src/errors/RunnerOrganizationErrors.ts similarity index 66% rename from src/errors/RunnerOrganisationErrors.ts rename to src/errors/RunnerOrganizationErrors.ts index b815900..0f40dfb 100644 --- a/src/errors/RunnerOrganisationErrors.ts +++ b/src/errors/RunnerOrganizationErrors.ts @@ -4,21 +4,21 @@ import { NotAcceptableError, NotFoundError } from 'routing-controllers'; /** * Error to throw when a runner organization couldn't be found. */ -export class RunnerOrganisationNotFoundError extends NotFoundError { +export class RunnerOrganizationNotFoundError extends NotFoundError { @IsString() - name = "RunnerOrganisationNotFoundError" + name = "RunnerOrganizationNotFoundError" @IsString() - message = "RunnerOrganisation not found!" + message = "RunnerOrganization not found!" } /** * Error to throw when two runner organization's ids don't match. * Usually occurs when a user tries to change a runner organization's id. */ -export class RunnerOrganisationIdsNotMatchingError extends NotAcceptableError { +export class RunnerOrganizationIdsNotMatchingError extends NotAcceptableError { @IsString() - name = "RunnerOrganisationIdsNotMatchingError" + name = "RunnerOrganizationIdsNotMatchingError" @IsString() message = "The ids don't match! \n And if you wanted to change a runner organization's id: This isn't allowed!" @@ -27,9 +27,9 @@ export class RunnerOrganisationIdsNotMatchingError extends NotAcceptableError { /** * Error to throw when a organization still has runners associated. */ -export class RunnerOrganisationHasRunnersError extends NotAcceptableError { +export class RunnerOrganizationHasRunnersError extends NotAcceptableError { @IsString() - name = "RunnerOrganisationHasRunnersError" + name = "RunnerOrganizationHasRunnersError" @IsString() message = "This organization still has runners associated with it. \n If you want to delete this organization with all it's runners and teams add `?force` to your query." @@ -38,20 +38,20 @@ export class RunnerOrganisationHasRunnersError extends NotAcceptableError { /** * Error to throw when a organization still has teams associated. */ -export class RunnerOrganisationHasTeamsError extends NotAcceptableError { +export class RunnerOrganizationHasTeamsError extends NotAcceptableError { @IsString() - name = "RunnerOrganisationHasTeamsError" + name = "RunnerOrganizationHasTeamsError" @IsString() message = "This organization still has teams associated with it. \n If you want to delete this organization with all it's runners and teams add `?force` to your query." } /** - * Error to throw, when a provided runnerOrganisation doesn't belong to the accepted types. + * Error to throw, when a provided runnerOrganization doesn't belong to the accepted types. */ -export class RunnerOrganisationWrongTypeError extends NotAcceptableError { +export class RunnerOrganizationWrongTypeError extends NotAcceptableError { @IsString() - name = "RunnerOrganisationWrongTypeError" + name = "RunnerOrganizationWrongTypeError" @IsString() message = "The runner organization must be an existing organization's id. \n You provided a object of another type." diff --git a/src/models/actions/ImportRunner.ts b/src/models/actions/ImportRunner.ts index b399d90..4370343 100644 --- a/src/models/actions/ImportRunner.ts +++ b/src/models/actions/ImportRunner.ts @@ -1,9 +1,9 @@ import { IsNotEmpty, IsOptional, IsString } from 'class-validator'; import { getConnectionManager } from 'typeorm'; import { RunnerGroupNeededError } from '../../errors/RunnerErrors'; -import { RunnerOrganisationNotFoundError } from '../../errors/RunnerOrganisationErrors'; +import { RunnerOrganizationNotFoundError } from '../../errors/RunnerOrganizationErrors'; import { RunnerGroup } from '../entities/RunnerGroup'; -import { RunnerOrganisation } from '../entities/RunnerOrganisation'; +import { RunnerOrganization } from '../entities/RunnerOrganization'; import { RunnerTeam } from '../entities/RunnerTeam'; import { CreateRunner } from './create/CreateRunner'; @@ -78,9 +78,9 @@ export class ImportRunner { let team = await getConnectionManager().get().getRepository(RunnerTeam).findOne({ id: groupID }); if (team) { return team; } - let org = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: groupID }); + let org = await getConnectionManager().get().getRepository(RunnerOrganization).findOne({ id: groupID }); if (!org) { - throw new RunnerOrganisationNotFoundError(); + throw new RunnerOrganizationNotFoundError(); } if (this.team === undefined) { return org; } diff --git a/src/models/actions/create/CreateRunner.ts b/src/models/actions/create/CreateRunner.ts index 9916ba8..63871e3 100644 --- a/src/models/actions/create/CreateRunner.ts +++ b/src/models/actions/create/CreateRunner.ts @@ -1,7 +1,7 @@ import { IsInt } from 'class-validator'; import { getConnectionManager } from 'typeorm'; import { RunnerGroupNotFoundError } from '../../../errors/RunnerGroupErrors'; -import { RunnerOrganisationWrongTypeError } from '../../../errors/RunnerOrganisationErrors'; +import { RunnerOrganizationWrongTypeError } from '../../../errors/RunnerOrganizationErrors'; import { RunnerTeamNeedsParentError } from '../../../errors/RunnerTeamErrors'; import { Address } from '../../entities/Address'; import { Runner } from '../../entities/Runner'; @@ -50,6 +50,6 @@ export class CreateRunner extends CreateParticipant { return group; } - throw new RunnerOrganisationWrongTypeError; + throw new RunnerOrganizationWrongTypeError; } } \ No newline at end of file diff --git a/src/models/actions/create/CreateRunnerOrganisation.ts b/src/models/actions/create/CreateRunnerOrganisation.ts deleted file mode 100644 index e1a2e15..0000000 --- a/src/models/actions/create/CreateRunnerOrganisation.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { IsBoolean, IsObject, IsOptional } from 'class-validator'; -import * as uuid from 'uuid'; -import { Address } from '../../entities/Address'; -import { RunnerOrganisation } from '../../entities/RunnerOrganisation'; -import { CreateRunnerGroup } from './CreateRunnerGroup'; - - -/** - * This classed is used to create a new RunnerOrganisation entity from a json body (post request). - */ -export class CreateRunnerOrganisation extends CreateRunnerGroup { - /** - * The new organization's address. - */ - @IsOptional() - @IsObject() - address?: Address; - - /** - * Is registration enabled for the new organization? - */ - @IsOptional() - @IsBoolean() - registrationEnabled?: boolean = false; - - /** - * Creates a new RunnerOrganisation entity from this. - */ - public async toEntity(): Promise { - let newRunnerOrganisation: RunnerOrganisation = new RunnerOrganisation(); - - newRunnerOrganisation.name = this.name; - newRunnerOrganisation.contact = await this.getContact(); - newRunnerOrganisation.address = this.address; - Address.validate(newRunnerOrganisation.address); - - if (this.registrationEnabled) { - newRunnerOrganisation.key = uuid.v4().toUpperCase(); - } - - return newRunnerOrganisation; - } -} \ No newline at end of file diff --git a/src/models/actions/create/CreateRunnerOrganization.ts b/src/models/actions/create/CreateRunnerOrganization.ts new file mode 100644 index 0000000..8aba1f4 --- /dev/null +++ b/src/models/actions/create/CreateRunnerOrganization.ts @@ -0,0 +1,43 @@ +import { IsBoolean, IsObject, IsOptional } from 'class-validator'; +import * as uuid from 'uuid'; +import { Address } from '../../entities/Address'; +import { RunnerOrganization } from '../../entities/RunnerOrganization'; +import { CreateRunnerGroup } from './CreateRunnerGroup'; + + +/** + * This classed is used to create a new RunnerOrganization entity from a json body (post request). + */ +export class CreateRunnerOrganization extends CreateRunnerGroup { + /** + * The new organization's address. + */ + @IsOptional() + @IsObject() + address?: Address; + + /** + * Is registration enabled for the new organization? + */ + @IsOptional() + @IsBoolean() + registrationEnabled?: boolean = false; + + /** + * Creates a new RunnerOrganization entity from this. + */ + public async toEntity(): Promise { + let newRunnerOrganization: RunnerOrganization = new RunnerOrganization(); + + newRunnerOrganization.name = this.name; + newRunnerOrganization.contact = await this.getContact(); + newRunnerOrganization.address = this.address; + Address.validate(newRunnerOrganization.address); + + if (this.registrationEnabled) { + newRunnerOrganization.key = uuid.v4().toUpperCase(); + } + + return newRunnerOrganization; + } +} \ No newline at end of file diff --git a/src/models/actions/create/CreateRunnerTeam.ts b/src/models/actions/create/CreateRunnerTeam.ts index 451d9d6..0cc7078 100644 --- a/src/models/actions/create/CreateRunnerTeam.ts +++ b/src/models/actions/create/CreateRunnerTeam.ts @@ -1,8 +1,8 @@ import { IsInt, IsNotEmpty } from 'class-validator'; import { getConnectionManager } from 'typeorm'; -import { RunnerOrganisationNotFoundError } from '../../../errors/RunnerOrganisationErrors'; +import { RunnerOrganizationNotFoundError } from '../../../errors/RunnerOrganizationErrors'; import { RunnerTeamNeedsParentError } from '../../../errors/RunnerTeamErrors'; -import { RunnerOrganisation } from '../../entities/RunnerOrganisation'; +import { RunnerOrganization } from '../../entities/RunnerOrganization'; import { RunnerTeam } from '../../entities/RunnerTeam'; import { CreateRunnerGroup } from './CreateRunnerGroup'; @@ -21,12 +21,12 @@ export class CreateRunnerTeam extends CreateRunnerGroup { /** * Gets the new team's parent org based on it's id. */ - public async getParent(): Promise { + public async getParent(): Promise { if (this.parentGroup === undefined || this.parentGroup === null) { throw new RunnerTeamNeedsParentError(); } - let parentGroup = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: this.parentGroup }); - if (!parentGroup) { throw new RunnerOrganisationNotFoundError();; } + let parentGroup = await getConnectionManager().get().getRepository(RunnerOrganization).findOne({ id: this.parentGroup }); + if (!parentGroup) { throw new RunnerOrganizationNotFoundError();; } return parentGroup; } diff --git a/src/models/actions/create/CreateSelfServiceCitizenRunner.ts b/src/models/actions/create/CreateSelfServiceCitizenRunner.ts index 1b9514b..d3a9d12 100644 --- a/src/models/actions/create/CreateSelfServiceCitizenRunner.ts +++ b/src/models/actions/create/CreateSelfServiceCitizenRunner.ts @@ -3,7 +3,7 @@ import { getConnection } from 'typeorm'; import { RunnerEmailNeededError } from '../../../errors/RunnerErrors'; import { Address } from '../../entities/Address'; import { Runner } from '../../entities/Runner'; -import { RunnerOrganisation } from '../../entities/RunnerOrganisation'; +import { RunnerOrganization } from '../../entities/RunnerOrganization'; import { CreateParticipant } from './CreateParticipant'; /** @@ -46,7 +46,7 @@ export class CreateSelfServiceCitizenRunner extends CreateParticipant { /** * Gets the new runner's group by it's id. */ - public async getGroup(): Promise { - return await getConnection().getRepository(RunnerOrganisation).findOne({ id: 1 }); + public async getGroup(): Promise { + return await getConnection().getRepository(RunnerOrganization).findOne({ id: 1 }); } } \ No newline at end of file diff --git a/src/models/actions/update/UpdateRunnerOrganisation.ts b/src/models/actions/update/UpdateRunnerOrganization.ts similarity index 78% rename from src/models/actions/update/UpdateRunnerOrganisation.ts rename to src/models/actions/update/UpdateRunnerOrganization.ts index 72acdba..52afbbb 100644 --- a/src/models/actions/update/UpdateRunnerOrganisation.ts +++ b/src/models/actions/update/UpdateRunnerOrganization.ts @@ -1,13 +1,13 @@ import { IsBoolean, IsInt, IsObject, IsOptional } from 'class-validator'; import * as uuid from 'uuid'; import { Address } from '../../entities/Address'; -import { RunnerOrganisation } from '../../entities/RunnerOrganisation'; +import { RunnerOrganization } from '../../entities/RunnerOrganization'; import { CreateRunnerGroup } from '../create/CreateRunnerGroup'; /** - * This class is used to update a RunnerOrganisation entity (via put request). + * This class is used to update a RunnerOrganization entity (via put request). */ -export class UpdateRunnerOrganisation extends CreateRunnerGroup { +export class UpdateRunnerOrganization extends CreateRunnerGroup { /** * The updated orgs's id. @@ -31,9 +31,9 @@ export class UpdateRunnerOrganisation extends CreateRunnerGroup { registrationEnabled?: boolean = false; /** - * Updates a provided RunnerOrganisation entity based on this. + * Updates a provided RunnerOrganization entity based on this. */ - public async update(organization: RunnerOrganisation): Promise { + public async update(organization: RunnerOrganization): Promise { organization.name = this.name; organization.contact = await this.getContact(); diff --git a/src/models/actions/update/UpdateRunnerTeam.ts b/src/models/actions/update/UpdateRunnerTeam.ts index b5cc7a5..aaec708 100644 --- a/src/models/actions/update/UpdateRunnerTeam.ts +++ b/src/models/actions/update/UpdateRunnerTeam.ts @@ -1,8 +1,8 @@ import { IsInt, IsPositive } from 'class-validator'; import { getConnectionManager } from 'typeorm'; -import { RunnerOrganisationNotFoundError } from '../../../errors/RunnerOrganisationErrors'; +import { RunnerOrganizationNotFoundError } from '../../../errors/RunnerOrganizationErrors'; import { RunnerTeamNeedsParentError } from '../../../errors/RunnerTeamErrors'; -import { RunnerOrganisation } from '../../entities/RunnerOrganisation'; +import { RunnerOrganization } from '../../entities/RunnerOrganization'; import { RunnerTeam } from '../../entities/RunnerTeam'; import { CreateRunnerGroup } from '../create/CreateRunnerGroup'; @@ -28,12 +28,12 @@ export class UpdateRunnerTeam extends CreateRunnerGroup { /** * Loads the updated teams's parentGroup based on it's id. */ - public async getParent(): Promise { + public async getParent(): Promise { if (this.parentGroup === undefined || this.parentGroup === null) { throw new RunnerTeamNeedsParentError(); } - let parentGroup = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: this.parentGroup }); - if (!parentGroup) { throw new RunnerOrganisationNotFoundError();; } + let parentGroup = await getConnectionManager().get().getRepository(RunnerOrganization).findOne({ id: this.parentGroup }); + if (!parentGroup) { throw new RunnerOrganizationNotFoundError();; } return parentGroup; } diff --git a/src/models/entities/RunnerOrganisation.ts b/src/models/entities/RunnerOrganization.ts similarity index 86% rename from src/models/entities/RunnerOrganisation.ts rename to src/models/entities/RunnerOrganization.ts index 719fb45..1988dca 100644 --- a/src/models/entities/RunnerOrganisation.ts +++ b/src/models/entities/RunnerOrganization.ts @@ -1,17 +1,17 @@ import { IsInt, IsOptional, IsString } from "class-validator"; import { ChildEntity, Column, OneToMany } from "typeorm"; -import { ResponseRunnerOrganisation } from '../responses/ResponseRunnerOrganisation'; +import { ResponseRunnerOrganization } from '../responses/ResponseRunnerOrganization'; import { Address } from './Address'; import { Runner } from './Runner'; import { RunnerGroup } from "./RunnerGroup"; import { RunnerTeam } from "./RunnerTeam"; /** - * Defines the RunnerOrganisation entity. + * Defines the RunnerOrganization entity. * This usually is a school, club or company. */ @ChildEntity() -export class RunnerOrganisation extends RunnerGroup { +export class RunnerOrganization extends RunnerGroup { /** * The organizations's address. @@ -68,7 +68,7 @@ export class RunnerOrganisation extends RunnerGroup { /** * Turns this entity into it's response class. */ - public toResponse(): ResponseRunnerOrganisation { - return new ResponseRunnerOrganisation(this); + public toResponse(): ResponseRunnerOrganization { + return new ResponseRunnerOrganization(this); } } \ No newline at end of file diff --git a/src/models/entities/RunnerTeam.ts b/src/models/entities/RunnerTeam.ts index ba4884d..b8e224e 100644 --- a/src/models/entities/RunnerTeam.ts +++ b/src/models/entities/RunnerTeam.ts @@ -2,7 +2,7 @@ import { IsNotEmpty } from "class-validator"; import { ChildEntity, ManyToOne } from "typeorm"; import { ResponseRunnerTeam } from '../responses/ResponseRunnerTeam'; import { RunnerGroup } from "./RunnerGroup"; -import { RunnerOrganisation } from "./RunnerOrganisation"; +import { RunnerOrganization } from "./RunnerOrganization"; /** * Defines the RunnerTeam entity. @@ -13,11 +13,11 @@ export class RunnerTeam extends RunnerGroup { /** * The team's parent group. - * Every team has to be part of a runnerOrganisation - this get's checked on creation and update. + * Every team has to be part of a runnerOrganization - this get's checked on creation and update. */ @IsNotEmpty() - @ManyToOne(() => RunnerOrganisation, org => org.teams, { nullable: true }) - parentGroup?: RunnerOrganisation; + @ManyToOne(() => RunnerOrganization, org => org.teams, { nullable: true }) + parentGroup?: RunnerOrganization; /** * Turns this entity into it's response class. diff --git a/src/models/responses/ResponseRunnerOrganisation.ts b/src/models/responses/ResponseRunnerOrganization.ts similarity index 69% rename from src/models/responses/ResponseRunnerOrganisation.ts rename to src/models/responses/ResponseRunnerOrganization.ts index af6fb4c..dcafb53 100644 --- a/src/models/responses/ResponseRunnerOrganisation.ts +++ b/src/models/responses/ResponseRunnerOrganization.ts @@ -10,24 +10,24 @@ import { IsString } from "class-validator"; import { Address } from '../entities/Address'; -import { RunnerOrganisation } from '../entities/RunnerOrganisation'; +import { RunnerOrganization } from '../entities/RunnerOrganization'; import { RunnerTeam } from '../entities/RunnerTeam'; import { ResponseRunnerGroup } from './ResponseRunnerGroup'; /** - * Defines the runnerOrganisation response. + * Defines the runnerOrganization response. */ -export class ResponseRunnerOrganisation extends ResponseRunnerGroup { +export class ResponseRunnerOrganization extends ResponseRunnerGroup { /** - * The runnerOrganisation's address. + * The runnerOrganization's address. */ @IsObject() @IsOptional() address?: Address; /** - * The runnerOrganisation associated teams. + * The runnerOrganization associated teams. */ @IsArray() teams: RunnerTeam[]; @@ -49,10 +49,10 @@ export class ResponseRunnerOrganisation extends ResponseRunnerGroup { registrationEnabled?: boolean = true; /** - * Creates a ResponseRunnerOrganisation object from a runnerOrganisation. - * @param org The runnerOrganisation the response shall be build for. + * Creates a ResponseRunnerOrganization object from a runnerOrganization. + * @param org The runnerOrganization the response shall be build for. */ - public constructor(org: RunnerOrganisation) { + public constructor(org: RunnerOrganization) { super(org); this.address = org.address; this.teams = org.teams; diff --git a/src/models/responses/ResponseRunnerTeam.ts b/src/models/responses/ResponseRunnerTeam.ts index 3d75cc3..50566cf 100644 --- a/src/models/responses/ResponseRunnerTeam.ts +++ b/src/models/responses/ResponseRunnerTeam.ts @@ -1,7 +1,7 @@ import { IsNotEmpty, IsObject } from "class-validator"; import { RunnerTeam } from '../entities/RunnerTeam'; import { ResponseRunnerGroup } from './ResponseRunnerGroup'; -import { ResponseRunnerOrganisation } from './ResponseRunnerOrganisation'; +import { ResponseRunnerOrganization } from './ResponseRunnerOrganization'; /** * Defines the runnerTeam response. @@ -13,7 +13,7 @@ export class ResponseRunnerTeam extends ResponseRunnerGroup { */ @IsObject() @IsNotEmpty() - parentGroup: ResponseRunnerOrganisation; + parentGroup: ResponseRunnerOrganization; /** * Creates a ResponseRunnerTeam object from a runnerTeam. diff --git a/src/models/responses/ResponseStats.ts b/src/models/responses/ResponseStats.ts index 84a0773..d184089 100644 --- a/src/models/responses/ResponseStats.ts +++ b/src/models/responses/ResponseStats.ts @@ -3,7 +3,7 @@ import { } from "class-validator"; import { Donation } from '../entities/Donation'; import { Runner } from '../entities/Runner'; -import { RunnerOrganisation } from '../entities/RunnerOrganisation'; +import { RunnerOrganization } from '../entities/RunnerOrganization'; import { RunnerTeam } from '../entities/RunnerTeam'; import { Scan } from '../entities/Scan'; import { User } from '../entities/User'; @@ -70,7 +70,7 @@ export class ResponseStats { * @param scans Array containing all scans - no relations have to be resolved. * @param donations Array containing all donations - the following relations have to be resolved: runner, runner.scans, runner.scans.track */ - public constructor(runners: Runner[], teams: RunnerTeam[], orgs: RunnerOrganisation[], users: User[], scans: Scan[], donations: Donation[]) { + public constructor(runners: Runner[], teams: RunnerTeam[], orgs: RunnerOrganization[], users: User[], scans: Scan[], donations: Donation[]) { this.total_runners = runners.length; this.total_teams = teams.length; this.total_orgs = orgs.length; diff --git a/src/models/responses/ResponseStatsOrganisation.ts b/src/models/responses/ResponseStatsOrganization.ts similarity index 90% rename from src/models/responses/ResponseStatsOrganisation.ts rename to src/models/responses/ResponseStatsOrganization.ts index e235718..592435a 100644 --- a/src/models/responses/ResponseStatsOrganisation.ts +++ b/src/models/responses/ResponseStatsOrganization.ts @@ -3,7 +3,7 @@ import { IsString } from "class-validator"; -import { RunnerOrganisation } from '../entities/RunnerOrganisation'; +import { RunnerOrganization } from '../entities/RunnerOrganization'; /** * Defines the org stats response. @@ -38,7 +38,7 @@ export class ResponseStatsOrgnisation { * Creates a new organization stats response from a organization * @param org The organization whoes response shall be generated - the following relations have to be resolved: runners, runners.scans, runners.distanceDonations, runners.scans.track, teams, teams.runners, teams.runners.scans, teams.runners.distanceDonations, teams.runners.scans.track */ - public constructor(org: RunnerOrganisation) { + public constructor(org: RunnerOrganization) { this.name = org.name; this.id = org.id; this.distance = org.distance; diff --git a/src/seeds/SeedPublicOrg.ts b/src/seeds/SeedPublicOrg.ts index 57685f8..b5c055c 100644 --- a/src/seeds/SeedPublicOrg.ts +++ b/src/seeds/SeedPublicOrg.ts @@ -1,15 +1,15 @@ import { Connection } from 'typeorm'; import { Factory, Seeder } from 'typeorm-seeding'; -import { CreateRunnerOrganisation } from '../models/actions/create/CreateRunnerOrganisation'; -import { RunnerOrganisation } from '../models/entities/RunnerOrganisation'; +import { CreateRunnerOrganization } from '../models/actions/create/CreateRunnerOrganization'; +import { RunnerOrganization } from '../models/entities/RunnerOrganization'; /** * Seeds the public runner org (named: "Citizen" by default). */ export default class SeedPublicOrg implements Seeder { public async run(factory: Factory, connection: Connection): Promise { - let publicOrg = new CreateRunnerOrganisation(); + let publicOrg = new CreateRunnerOrganization(); publicOrg.name = "Citizen"; - await connection.getRepository(RunnerOrganisation).save(await publicOrg.toEntity()); + await connection.getRepository(RunnerOrganization).save(await publicOrg.toEntity()); } } \ No newline at end of file diff --git a/src/seeds/SeedTestRunners.ts b/src/seeds/SeedTestRunners.ts index 14725c6..8bdfffe 100644 --- a/src/seeds/SeedTestRunners.ts +++ b/src/seeds/SeedTestRunners.ts @@ -2,13 +2,13 @@ import { Connection } from 'typeorm'; import { Factory, Seeder } from 'typeorm-seeding'; import { CreateGroupContact } from '../models/actions/create/CreateGroupContact'; import { CreateRunner } from '../models/actions/create/CreateRunner'; -import { CreateRunnerOrganisation } from '../models/actions/create/CreateRunnerOrganisation'; +import { CreateRunnerOrganization } from '../models/actions/create/CreateRunnerOrganization'; import { CreateRunnerTeam } from '../models/actions/create/CreateRunnerTeam'; import { Address } from '../models/entities/Address'; import { GroupContact } from '../models/entities/GroupContact'; import { Runner } from '../models/entities/Runner'; import { RunnerGroup } from '../models/entities/RunnerGroup'; -import { RunnerOrganisation } from '../models/entities/RunnerOrganisation'; +import { RunnerOrganization } from '../models/entities/RunnerOrganization'; import { RunnerTeam } from '../models/entities/RunnerTeam'; /** @@ -17,15 +17,15 @@ import { RunnerTeam } from '../models/entities/RunnerTeam'; */ export default class SeedTestRunners implements Seeder { public async run(factory: Factory, connection: Connection): Promise { - let testOrg: RunnerOrganisation = await this.createTestOrg(connection); + let testOrg: RunnerOrganization = await this.createTestOrg(connection); let testTeam: RunnerTeam = await this.createTestTeam(connection, testOrg); await this.createTestContact(connection, testOrg); await this.createTestRunners(connection, testOrg); await this.createTestRunners(connection, testTeam); } - public async createTestOrg(connection: Connection): Promise { - let testOrg = new CreateRunnerOrganisation(); + public async createTestOrg(connection: Connection): Promise { + let testOrg = new CreateRunnerOrganization(); testOrg.name = "Test Org"; testOrg.address = new Address(); @@ -34,10 +34,10 @@ export default class SeedTestRunners implements Seeder { testOrg.address.country = "Germany"; testOrg.address.postalcode = "90174"; - return await connection.getRepository(RunnerOrganisation).save(await testOrg.toEntity()); + return await connection.getRepository(RunnerOrganization).save(await testOrg.toEntity()); } - public async createTestTeam(connection: Connection, org: RunnerOrganisation): Promise { + public async createTestTeam(connection: Connection, org: RunnerOrganization): Promise { let testTeam = new CreateRunnerTeam(); testTeam.name = "Test Team"; testTeam.parentGroup = org.id;