From e6b9d4f2737a6eeb30e4c14a10675b13f89d62fa Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Sun, 10 Jan 2021 16:31:55 +0100 Subject: [PATCH] Renamed the to>Entity Name>() functiuons to toEntity() ref #76 --- src/controllers/DonorController.ts | 2 +- src/controllers/PermissionController.ts | 2 +- src/controllers/RunnerController.ts | 2 +- src/controllers/RunnerOrganisationController.ts | 2 +- src/controllers/ScanController.ts | 4 ++-- src/controllers/StatsClientController.ts | 2 +- src/controllers/TrackController.ts | 2 +- src/controllers/UserController.ts | 2 +- src/controllers/UserGroupController.ts | 2 +- src/models/actions/create/CreateAddress.ts | 2 +- src/models/actions/create/CreateDonor.ts | 2 +- src/models/actions/create/CreateGroupContact.ts | 2 +- src/models/actions/create/CreatePermission.ts | 2 +- src/models/actions/create/CreateRunner.ts | 2 +- src/models/actions/create/CreateRunnerOrganisation.ts | 2 +- src/models/actions/create/CreateScan.ts | 2 +- src/models/actions/create/CreateStatsClient.ts | 2 +- src/models/actions/create/CreateTrack.ts | 2 +- src/models/actions/create/CreateTrackScan.ts | 2 +- src/models/actions/create/CreateUser.ts | 2 +- src/models/actions/create/CreateUserGroup.ts | 2 +- src/seeds/SeedUsers.ts | 6 +++--- 22 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/controllers/DonorController.ts b/src/controllers/DonorController.ts index 9a13784..5b17c1d 100644 --- a/src/controllers/DonorController.ts +++ b/src/controllers/DonorController.ts @@ -52,7 +52,7 @@ export class DonorController { async post(@Body({ validate: true }) createRunner: CreateDonor) { let donor; try { - donor = await createRunner.toDonor(); + donor = await createRunner.toEntity(); } catch (error) { throw error; } diff --git a/src/controllers/PermissionController.ts b/src/controllers/PermissionController.ts index 9080cac..37085f1 100644 --- a/src/controllers/PermissionController.ts +++ b/src/controllers/PermissionController.ts @@ -58,7 +58,7 @@ export class PermissionController { async post(@Body({ validate: true }) createPermission: CreatePermission) { let permission; try { - permission = await createPermission.toPermission(); + permission = await createPermission.toEntity(); } catch (error) { throw error; } diff --git a/src/controllers/RunnerController.ts b/src/controllers/RunnerController.ts index 494876c..184cc38 100644 --- a/src/controllers/RunnerController.ts +++ b/src/controllers/RunnerController.ts @@ -57,7 +57,7 @@ export class RunnerController { async post(@Body({ validate: true }) createRunner: CreateRunner) { let runner; try { - runner = await createRunner.toRunner(); + runner = await createRunner.toEntity(); } catch (error) { throw error; } diff --git a/src/controllers/RunnerOrganisationController.ts b/src/controllers/RunnerOrganisationController.ts index ac06cbb..4717d3c 100644 --- a/src/controllers/RunnerOrganisationController.ts +++ b/src/controllers/RunnerOrganisationController.ts @@ -55,7 +55,7 @@ export class RunnerOrganisationController { async post(@Body({ validate: true }) createRunnerOrganisation: CreateRunnerOrganisation) { let runnerOrganisation; try { - runnerOrganisation = await createRunnerOrganisation.toRunnerOrganisation(); + runnerOrganisation = await createRunnerOrganisation.toEntity(); } catch (error) { throw error; } diff --git a/src/controllers/ScanController.ts b/src/controllers/ScanController.ts index e5b46fc..e098a21 100644 --- a/src/controllers/ScanController.ts +++ b/src/controllers/ScanController.ts @@ -62,7 +62,7 @@ export class ScanController { @ResponseSchema(RunnerNotFoundError, { statusCode: 404 }) @OpenAPI({ description: 'Create a new scan (not track scan - use /scans/trackscans instead).
Please rmemember to provide the scan\'s runner\'s id and distance.', security: [{ "ScanApiToken": [] }, { "AuthToken": [] }, { "RefreshTokenCookie": [] }] }) async post(@Body({ validate: true }) createScan: CreateScan) { - let scan = await createScan.toScan(); + let scan = await createScan.toEntity(); scan = await this.scanRepository.save(scan); return (await this.scanRepository.findOne({ id: scan.id }, { relations: ['runner', 'track', 'runner.scans', 'runner.scans.track', 'card', 'station'] })).toResponse(); } @@ -73,7 +73,7 @@ export class ScanController { @ResponseSchema(RunnerNotFoundError, { statusCode: 404 }) @OpenAPI({ description: 'Create a new track scan (for "normal" scans use /scans instead).
Please remember that to provide the scan\'s card\'s station\'s id.', security: [{ "ScanApiToken": [] }, { "AuthToken": [] }, { "RefreshTokenCookie": [] }] }) async postTrackScans(@Body({ validate: true }) createScan: CreateTrackScan) { - let scan = await createScan.toScan(); + let scan = await createScan.toEntity(); scan = await this.trackScanRepository.save(scan); return (await this.scanRepository.findOne({ id: scan.id }, { relations: ['runner', 'track', 'runner.scans', 'runner.scans.track', 'card', 'station'] })).toResponse(); } diff --git a/src/controllers/StatsClientController.ts b/src/controllers/StatsClientController.ts index 9d9080d..d7724c3 100644 --- a/src/controllers/StatsClientController.ts +++ b/src/controllers/StatsClientController.ts @@ -53,7 +53,7 @@ export class StatsClientController { @Body({ validate: true }) client: CreateStatsClient ) { - let newClient = await this.clientRepository.save(await client.toStatsClient()); + let newClient = await this.clientRepository.save(await client.toEntity()); let responseClient = new ResponseStatsClient(newClient); responseClient.key = newClient.cleartextkey; return responseClient; diff --git a/src/controllers/TrackController.ts b/src/controllers/TrackController.ts index 85416db..a47972f 100644 --- a/src/controllers/TrackController.ts +++ b/src/controllers/TrackController.ts @@ -55,7 +55,7 @@ export class TrackController { @Body({ validate: true }) track: CreateTrack ) { - return new ResponseTrack(await this.trackRepository.save(track.toTrack())); + return new ResponseTrack(await this.trackRepository.save(track.toEntity())); } @Put('/:id') diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index 0fbed48..195b66a 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -56,7 +56,7 @@ export class UserController { async post(@Body({ validate: true }) createUser: CreateUser) { let user; try { - user = await createUser.toUser(); + user = await createUser.toEntity(); } catch (error) { throw error; } diff --git a/src/controllers/UserGroupController.ts b/src/controllers/UserGroupController.ts index f3ae435..85426f5 100644 --- a/src/controllers/UserGroupController.ts +++ b/src/controllers/UserGroupController.ts @@ -48,7 +48,7 @@ export class UserGroupController { async post(@Body({ validate: true }) createUserGroup: CreateUserGroup) { let userGroup; try { - userGroup = await createUserGroup.toUserGroup(); + userGroup = await createUserGroup.toEntity(); } catch (error) { throw error; } diff --git a/src/models/actions/create/CreateAddress.ts b/src/models/actions/create/CreateAddress.ts index 365035e..0111736 100644 --- a/src/models/actions/create/CreateAddress.ts +++ b/src/models/actions/create/CreateAddress.ts @@ -56,7 +56,7 @@ export class CreateAddress { /** * Creates a new Address entity from this. */ - public toAddress(): Address { + public toEntity(): Address { let newAddress: Address = new Address(); newAddress.address1 = this.address1; diff --git a/src/models/actions/create/CreateDonor.ts b/src/models/actions/create/CreateDonor.ts index 2deb10b..791461a 100644 --- a/src/models/actions/create/CreateDonor.ts +++ b/src/models/actions/create/CreateDonor.ts @@ -18,7 +18,7 @@ export class CreateDonor extends CreateParticipant { /** * Creates a new Donor entity from this. */ - public async toDonor(): Promise { + public async toEntity(): Promise { let newDonor: Donor = new Donor(); newDonor.firstname = this.firstname; diff --git a/src/models/actions/create/CreateGroupContact.ts b/src/models/actions/create/CreateGroupContact.ts index fa83bed..c6e10a8 100644 --- a/src/models/actions/create/CreateGroupContact.ts +++ b/src/models/actions/create/CreateGroupContact.ts @@ -72,7 +72,7 @@ export class CreateGroupContact { /** * Creates a new Address entity from this. */ - public async toGroupContact(): Promise { + public async toEntity(): Promise { let contact: GroupContact = new GroupContact(); contact.firstname = this.firstname; contact.middlename = this.middlename; diff --git a/src/models/actions/create/CreatePermission.ts b/src/models/actions/create/CreatePermission.ts index 41fddfc..e59a186 100644 --- a/src/models/actions/create/CreatePermission.ts +++ b/src/models/actions/create/CreatePermission.ts @@ -39,7 +39,7 @@ export class CreatePermission { /** * Creates a new Permission entity from this. */ - public async toPermission(): Promise { + public async toEntity(): Promise { let newPermission: Permission = new Permission(); newPermission.principal = await this.getPrincipal(); diff --git a/src/models/actions/create/CreateRunner.ts b/src/models/actions/create/CreateRunner.ts index acd36d4..2286fdf 100644 --- a/src/models/actions/create/CreateRunner.ts +++ b/src/models/actions/create/CreateRunner.ts @@ -21,7 +21,7 @@ export class CreateRunner extends CreateParticipant { /** * Creates a new Runner entity from this. */ - public async toRunner(): Promise { + public async toEntity(): Promise { let newRunner: Runner = new Runner(); newRunner.firstname = this.firstname; diff --git a/src/models/actions/create/CreateRunnerOrganisation.ts b/src/models/actions/create/CreateRunnerOrganisation.ts index 426793d..04edf93 100644 --- a/src/models/actions/create/CreateRunnerOrganisation.ts +++ b/src/models/actions/create/CreateRunnerOrganisation.ts @@ -36,7 +36,7 @@ export class CreateRunnerOrganisation extends CreateRunnerGroup { /** * Creates a new RunnerOrganisation entity from this. */ - public async toRunnerOrganisation(): Promise { + public async toEntity(): Promise { let newRunnerOrganisation: RunnerOrganisation = new RunnerOrganisation(); newRunnerOrganisation.name = this.name; diff --git a/src/models/actions/create/CreateScan.ts b/src/models/actions/create/CreateScan.ts index 9835924..496b8a0 100644 --- a/src/models/actions/create/CreateScan.ts +++ b/src/models/actions/create/CreateScan.ts @@ -36,7 +36,7 @@ export abstract class CreateScan { /** * Creates a new Scan entity from this. */ - public async toScan(): Promise { + public async toEntity(): Promise { let newScan = new Scan(); newScan.distance = this.distance; diff --git a/src/models/actions/create/CreateStatsClient.ts b/src/models/actions/create/CreateStatsClient.ts index d648f3c..0f666fc 100644 --- a/src/models/actions/create/CreateStatsClient.ts +++ b/src/models/actions/create/CreateStatsClient.ts @@ -18,7 +18,7 @@ export class CreateStatsClient { /** * Converts this to a StatsClient entity. */ - public async toStatsClient(): Promise { + public async toEntity(): Promise { let newClient: StatsClient = new StatsClient(); newClient.description = this.description; diff --git a/src/models/actions/create/CreateTrack.ts b/src/models/actions/create/CreateTrack.ts index 7250889..8c0db34 100644 --- a/src/models/actions/create/CreateTrack.ts +++ b/src/models/actions/create/CreateTrack.ts @@ -31,7 +31,7 @@ export class CreateTrack { /** * Creates a new Track entity from this. */ - public toTrack(): Track { + public toEntity(): Track { let newTrack: Track = new Track(); newTrack.name = this.name; diff --git a/src/models/actions/create/CreateTrackScan.ts b/src/models/actions/create/CreateTrackScan.ts index 49a9611..db63cf2 100644 --- a/src/models/actions/create/CreateTrackScan.ts +++ b/src/models/actions/create/CreateTrackScan.ts @@ -30,7 +30,7 @@ export class CreateTrackScan { /** * Creates a new Track entity from this. */ - public async toScan(): Promise { + public async toEntity(): Promise { let newScan: TrackScan = new TrackScan(); newScan.station = await this.getStation(); diff --git a/src/models/actions/create/CreateUser.ts b/src/models/actions/create/CreateUser.ts index a153750..a5f20c2 100644 --- a/src/models/actions/create/CreateUser.ts +++ b/src/models/actions/create/CreateUser.ts @@ -89,7 +89,7 @@ export class CreateUser { /** * Converts this to a User entity. */ - public async toUser(): Promise { + public async toEntity(): Promise { let newUser: User = new User(); if (this.email === undefined && this.username === undefined) { diff --git a/src/models/actions/create/CreateUserGroup.ts b/src/models/actions/create/CreateUserGroup.ts index ec0dad7..aa5a862 100644 --- a/src/models/actions/create/CreateUserGroup.ts +++ b/src/models/actions/create/CreateUserGroup.ts @@ -22,7 +22,7 @@ export class CreateUserGroup { /** * Creates a new UserGroup entity from this. */ - public async toUserGroup(): Promise { + public async toEntity(): Promise { let newUserGroup: UserGroup = new UserGroup(); newUserGroup.name = this.name; diff --git a/src/seeds/SeedUsers.ts b/src/seeds/SeedUsers.ts index a21db99..e70ef84 100644 --- a/src/seeds/SeedUsers.ts +++ b/src/seeds/SeedUsers.ts @@ -24,7 +24,7 @@ export default class SeedUsers implements Seeder { let adminGroup = new CreateUserGroup(); adminGroup.name = "ADMINS"; adminGroup.description = "Have all possible permissions"; - return await connection.getRepository(UserGroup).save(await adminGroup.toUserGroup()); + return await connection.getRepository(UserGroup).save(await adminGroup.toEntity()); } public async createUser(connection: Connection, group: number) { @@ -34,7 +34,7 @@ export default class SeedUsers implements Seeder { initialUser.username = "demo"; initialUser.password = "demo"; initialUser.groups = group; - return await connection.getRepository(User).save(await initialUser.toUser()); + return await connection.getRepository(User).save(await initialUser.toEntity()); } public async createPermissions(connection: Connection, principal: number) { @@ -45,7 +45,7 @@ export default class SeedUsers implements Seeder { permission.target = target; permission.action = action; permission.principal = principal; - await repo.save(await permission.toPermission()); + await repo.save(await permission.toEntity()); } } }