diff --git a/src/controllers/DonationController.ts b/src/controllers/DonationController.ts
index 9c2696d..9401694 100644
--- a/src/controllers/DonationController.ts
+++ b/src/controllers/DonationController.ts
@@ -78,7 +78,7 @@ export class DonationController {
async postDistance(@Body({ validate: true }) createDonation: CreateDistanceDonation) {
let donation = await createDonation.toEntity();
donation = await this.distanceDonationRepository.save(donation);
- return (await this.donationRepository.findOne({ id: donation.id }, { relations: ['runner', 'donor', 'runner.scans', 'runner.scans.track'] })).toResponse();
+ return (await this.distanceDonationRepository.findOne({ id: donation.id }, { relations: ['runner', 'donor', 'runner.scans', 'runner.scans.track'] })).toResponse();
}
@Put('/fixed/:id')
@@ -124,7 +124,7 @@ export class DonationController {
}
await this.distanceDonationRepository.save(await donation.update(oldDonation));
- return (await this.donationRepository.findOne({ id: donation.id }, { relations: ['runner', 'donor', 'runner.scans', 'runner.scans.track'] })).toResponse();
+ return (await this.distanceDonationRepository.findOne({ id: donation.id }, { relations: ['runner', 'donor', 'runner.scans', 'runner.scans.track'] })).toResponse();
}
@Delete('/:id')
diff --git a/src/controllers/ScanController.ts b/src/controllers/ScanController.ts
index 0de844c..b223689 100644
--- a/src/controllers/ScanController.ts
+++ b/src/controllers/ScanController.ts
@@ -36,7 +36,7 @@ export class ScanController {
@OpenAPI({ description: 'Lists all scans (normal or track) from all runners.
This includes the scan\'s runner\'s distance ran.' })
async getAll() {
let responseScans: ResponseScan[] = new Array();
- const scans = await this.scanRepository.find({ relations: ['runner', 'track', 'runner.scans', 'runner.scans.track', 'card', 'station'] });
+ const scans = await this.scanRepository.find({ relations: ['runner', 'track', 'runner.scans', 'runner.group', 'runner.scans.track', 'card', 'station'] });
scans.forEach(scan => {
responseScans.push(scan.toResponse());
});
@@ -51,7 +51,7 @@ export class ScanController {
@OnUndefined(ScanNotFoundError)
@OpenAPI({ description: 'Lists all information about the scan whose id got provided. This includes the scan\'s runner\'s distance ran.' })
async getOne(@Param('id') id: number) {
- let scan = await this.scanRepository.findOne({ id: id }, { relations: ['runner', 'track', 'runner.scans', 'runner.scans.track', 'card', 'station'] })
+ let scan = await this.scanRepository.findOne({ id: id }, { relations: ['runner', 'track', 'runner.scans', 'runner.group', 'runner.scans.track', 'card', 'station'] })
if (!scan) { throw new ScanNotFoundError(); }
return scan.toResponse();
}
@@ -64,7 +64,7 @@ export class ScanController {
async post(@Body({ validate: true }) createScan: CreateScan) {
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();
+ return (await this.scanRepository.findOne({ id: scan.id }, { relations: ['runner', 'track', 'runner.scans', 'runner.group', 'runner.scans.track', 'card', 'station'] })).toResponse();
}
@Post("/trackscans")
@@ -75,7 +75,7 @@ export class ScanController {
async postTrackScans(@Body({ validate: true }) createScan: CreateTrackScan) {
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();
+ return (await this.scanRepository.findOne({ id: scan.id }, { relations: ['runner', 'track', 'runner.scans', 'runner.group', 'runner.scans.track', 'card', 'station'] })).toResponse();
}
@Put('/:id')
@@ -97,7 +97,7 @@ export class ScanController {
}
await this.scanRepository.save(await scan.update(oldScan));
- return (await this.scanRepository.findOne({ id: id }, { relations: ['runner', 'track', 'runner.scans', 'runner.scans.track', 'card', 'station'] })).toResponse();
+ return (await this.scanRepository.findOne({ id: id }, { relations: ['runner', 'track', 'runner.scans', 'runner.group', 'runner.scans.track', 'card', 'station'] })).toResponse();
}
@Put('/trackscans/:id')
@@ -120,7 +120,7 @@ export class ScanController {
}
await this.trackScanRepository.save(await scan.update(oldScan));
- return (await this.scanRepository.findOne({ id: id }, { relations: ['runner', 'track', 'runner.scans', 'runner.scans.track', 'card', 'station'] })).toResponse();
+ return (await this.scanRepository.findOne({ id: id }, { relations: ['runner', 'track', 'runner.scans', 'runner.group', 'runner.scans.track', 'card', 'station'] })).toResponse();
}
@Delete('/:id')
@@ -132,7 +132,7 @@ export class ScanController {
async remove(@Param("id") id: number, @QueryParam("force") force: boolean) {
let scan = await this.scanRepository.findOne({ id: id });
if (!scan) { return null; }
- const responseScan = await this.scanRepository.findOne({ id: scan.id }, { relations: ['runner', 'track', 'runner.scans', 'runner.scans.track', 'card', 'station'] });
+ const responseScan = await this.scanRepository.findOne({ id: scan.id }, { relations: ['runner', 'track', 'runner.scans', 'runner.group', 'runner.scans.track', 'card', 'station'] });
await this.scanRepository.delete(scan);
return responseScan.toResponse();
diff --git a/src/models/entities/UserGroup.ts b/src/models/entities/UserGroup.ts
index cd7b06c..fad8039 100644
--- a/src/models/entities/UserGroup.ts
+++ b/src/models/entities/UserGroup.ts
@@ -4,7 +4,6 @@ import {
IsString
} from "class-validator";
import { ChildEntity, Column } from "typeorm";
-import { ResponsePrincipal } from '../responses/ResponsePrincipal';
import { ResponseUserGroup } from '../responses/ResponseUserGroup';
import { Principal } from './Principal';
@@ -34,7 +33,7 @@ export class UserGroup extends Principal {
/**
* Turns this entity into it's response class.
*/
- public toResponse(): ResponsePrincipal {
+ public toResponse(): ResponseUserGroup {
return new ResponseUserGroup(this);
}
}
\ No newline at end of file
diff --git a/src/models/responses/ResponseDistanceDonation.ts b/src/models/responses/ResponseDistanceDonation.ts
index a76d122..65fea13 100644
--- a/src/models/responses/ResponseDistanceDonation.ts
+++ b/src/models/responses/ResponseDistanceDonation.ts
@@ -36,7 +36,7 @@ export class ResponseDistanceDonation extends ResponseDonation implements IRespo
*/
public constructor(donation: DistanceDonation) {
super(donation);
- this.runner = donation.runner.toResponse();
+ if (donation.runner) { this.runner = donation.runner.toResponse(); }
this.amountPerDistance = donation.amountPerDistance;
}
}
diff --git a/src/models/responses/ResponseGroupContact.ts b/src/models/responses/ResponseGroupContact.ts
index 4cd826d..e3fee94 100644
--- a/src/models/responses/ResponseGroupContact.ts
+++ b/src/models/responses/ResponseGroupContact.ts
@@ -77,8 +77,10 @@ export class ResponseGroupContact implements IResponse {
this.email = contact.email;
this.address = contact.address;
this.groups = new Array();
- for (let group of contact.groups) {
- this.groups.push(group.toResponse());
+ if (contact.groups) {
+ for (let group of contact.groups) {
+ this.groups.push(group.toResponse());
+ }
}
}
}
diff --git a/src/models/responses/ResponseRunner.ts b/src/models/responses/ResponseRunner.ts
index 5820baf..8ed39e1 100644
--- a/src/models/responses/ResponseRunner.ts
+++ b/src/models/responses/ResponseRunner.ts
@@ -3,10 +3,10 @@ import {
IsObject
} from "class-validator";
import { Runner } from '../entities/Runner';
-import { RunnerGroup } from '../entities/RunnerGroup';
import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';
import { ResponseParticipant } from './ResponseParticipant';
+import { ResponseRunnerGroup } from './ResponseRunnerGroup';
/**
* Defines the runner response.
@@ -28,7 +28,7 @@ export class ResponseRunner extends ResponseParticipant implements IResponse {
* The runner's group.
*/
@IsObject()
- group: RunnerGroup;
+ group: ResponseRunnerGroup;
/**
* Creates a ResponseRunner object from a runner.
@@ -38,6 +38,6 @@ export class ResponseRunner extends ResponseParticipant implements IResponse {
super(runner);
if (!runner.scans) { this.distance = 0 }
else { this.distance = runner.validScans.reduce((sum, current) => sum + current.distance, 0); }
- this.group = runner.group;
+ if (runner.group) { this.group = runner.group.toResponse(); }
}
}
diff --git a/src/models/responses/ResponseRunnerGroup.ts b/src/models/responses/ResponseRunnerGroup.ts
index e9f6e56..b841218 100644
--- a/src/models/responses/ResponseRunnerGroup.ts
+++ b/src/models/responses/ResponseRunnerGroup.ts
@@ -1,8 +1,8 @@
import { IsInt, IsNotEmpty, IsObject, IsOptional, IsString } from "class-validator";
-import { GroupContact } from '../entities/GroupContact';
import { RunnerGroup } from '../entities/RunnerGroup';
import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';
+import { ResponseGroupContact } from './ResponseGroupContact';
/**
* Defines the runnerGroup response.
@@ -34,7 +34,7 @@ export abstract class ResponseRunnerGroup implements IResponse {
*/
@IsObject()
@IsOptional()
- contact?: GroupContact;
+ contact?: ResponseGroupContact;
/**
* Creates a ResponseRunnerGroup object from a runnerGroup.
@@ -43,6 +43,6 @@ export abstract class ResponseRunnerGroup implements IResponse {
public constructor(group: RunnerGroup) {
this.id = group.id;
this.name = group.name;
- this.contact = group.contact;
+ if (group.contact) { this.contact = group.contact.toResponse(); };
}
}
diff --git a/src/models/responses/ResponseRunnerOrganization.ts b/src/models/responses/ResponseRunnerOrganization.ts
index 37e9af5..3a78dfc 100644
--- a/src/models/responses/ResponseRunnerOrganization.ts
+++ b/src/models/responses/ResponseRunnerOrganization.ts
@@ -11,10 +11,10 @@ import {
} from "class-validator";
import { Address } from '../entities/Address';
import { RunnerOrganization } from '../entities/RunnerOrganization';
-import { RunnerTeam } from '../entities/RunnerTeam';
import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';
import { ResponseRunnerGroup } from './ResponseRunnerGroup';
+import { ResponseRunnerTeam } from './ResponseRunnerTeam';
/**
* Defines the runnerOrganization response.
@@ -37,7 +37,7 @@ export class ResponseRunnerOrganization extends ResponseRunnerGroup implements I
* The runnerOrganization associated teams.
*/
@IsArray()
- teams: RunnerTeam[];
+ teams: ResponseRunnerTeam[];
/**
* The organization's registration key.
@@ -62,7 +62,13 @@ export class ResponseRunnerOrganization extends ResponseRunnerGroup implements I
public constructor(org: RunnerOrganization) {
super(org);
this.address = org.address;
- this.teams = org.teams;
+ this.teams = new Array();
+ if (org.teams) {
+ for (let team of org.teams) {
+ this.teams.push(team.toResponse());
+ }
+ }
+
if (!org.key) { this.registrationEnabled = false; }
else { this.registrationKey = Buffer.from(org.key).toString('base64'); }
}
diff --git a/src/models/responses/ResponseRunnerTeam.ts b/src/models/responses/ResponseRunnerTeam.ts
index 5d5760b..0434789 100644
--- a/src/models/responses/ResponseRunnerTeam.ts
+++ b/src/models/responses/ResponseRunnerTeam.ts
@@ -28,6 +28,6 @@ export class ResponseRunnerTeam extends ResponseRunnerGroup implements IResponse
*/
public constructor(team: RunnerTeam) {
super(team);
- this.parentGroup = team.parentGroup.toResponse();
+ if (team.parentGroup) { this.parentGroup = team.parentGroup.toResponse(); }
}
}
diff --git a/src/models/responses/ResponseScan.ts b/src/models/responses/ResponseScan.ts
index f8f2142..864b455 100644
--- a/src/models/responses/ResponseScan.ts
+++ b/src/models/responses/ResponseScan.ts
@@ -47,7 +47,7 @@ export class ResponseScan implements IResponse {
*/
public constructor(scan: Scan) {
this.id = scan.id;
- this.runner = scan.runner.toResponse();
+ if (scan.runner) { this.runner = scan.runner.toResponse(); }
this.distance = scan.distance;
this.valid = scan.valid;
}
diff --git a/src/models/responses/ResponseScanStation.ts b/src/models/responses/ResponseScanStation.ts
index 455549b..459d132 100644
--- a/src/models/responses/ResponseScanStation.ts
+++ b/src/models/responses/ResponseScanStation.ts
@@ -72,7 +72,7 @@ export class ResponseScanStation implements IResponse {
this.description = station.description;
this.prefix = station.prefix;
this.key = "Only visible on creation.";
- this.track = station.track.toResponse();
+ if (station.track) { this.track = station.track.toResponse(); }
this.enabled = station.enabled;
}
}
diff --git a/src/models/responses/ResponseStatsRunner.ts b/src/models/responses/ResponseStatsRunner.ts
index bd0b212..3aac437 100644
--- a/src/models/responses/ResponseStatsRunner.ts
+++ b/src/models/responses/ResponseStatsRunner.ts
@@ -4,9 +4,9 @@ import {
IsString
} from "class-validator";
import { Runner } from '../entities/Runner';
-import { RunnerGroup } from '../entities/RunnerGroup';
import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';
+import { ResponseRunnerGroup } from './ResponseRunnerGroup';
/**
* Defines the runner stats response.
@@ -59,7 +59,7 @@ export class ResponseStatsRunner implements IResponse {
* The runner's group.
*/
@IsObject()
- group: RunnerGroup;
+ group: ResponseRunnerGroup;
/**
* Creates a new runner stats response from a runner
@@ -72,6 +72,6 @@ export class ResponseStatsRunner implements IResponse {
this.lastname = runner.lastname;
this.distance = runner.distance;
this.donationAmount = runner.distanceDonationAmount;
- this.group = runner.group;
+ this.group = runner.group.toResponse();
}
}
diff --git a/src/models/responses/ResponseStatsTeam.ts b/src/models/responses/ResponseStatsTeam.ts
index b1fbd22..82e4eb9 100644
--- a/src/models/responses/ResponseStatsTeam.ts
+++ b/src/models/responses/ResponseStatsTeam.ts
@@ -3,10 +3,10 @@ import {
IsObject,
IsString
} from "class-validator";
-import { RunnerGroup } from '../entities/RunnerGroup';
import { RunnerTeam } from '../entities/RunnerTeam';
import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';
+import { ResponseRunnerGroup } from './ResponseRunnerGroup';
/**
* Defines the team stats response.
@@ -47,7 +47,7 @@ export class ResponseStatsTeam implements IResponse {
* The teams's parent group.
*/
@IsObject()
- parent: RunnerGroup;
+ parent: ResponseRunnerGroup;
/**
* Creates a new team stats response from a team
@@ -56,7 +56,7 @@ export class ResponseStatsTeam implements IResponse {
public constructor(team: RunnerTeam) {
this.name = team.name;
this.id = team.id;
- this.parent = team.parentGroup;
+ this.parent = team.parentGroup.toResponse();
this.distance = team.distance;
this.donationAmount = team.distanceDonationAmount;
}
diff --git a/src/models/responses/ResponseTrackScan.ts b/src/models/responses/ResponseTrackScan.ts
index c92bd46..ffd9ceb 100644
--- a/src/models/responses/ResponseTrackScan.ts
+++ b/src/models/responses/ResponseTrackScan.ts
@@ -49,8 +49,8 @@ export class ResponseTrackScan extends ResponseScan implements IResponse {
public constructor(scan: TrackScan) {
super(scan);
this.track = new ResponseTrack(scan.track);
- this.card = scan.card.toResponse();
- this.station = scan.station.toResponse();
+ if (scan.card) { scan.card.toResponse(); }
+ if (scan.station) { scan.station.toResponse(); }
this.timestamp = scan.timestamp;
this.distance = scan.distance;
}
diff --git a/src/models/responses/ResponseUser.ts b/src/models/responses/ResponseUser.ts
index 598189f..1b55e45 100644
--- a/src/models/responses/ResponseUser.ts
+++ b/src/models/responses/ResponseUser.ts
@@ -6,10 +6,10 @@ import {
IsString
} from "class-validator";
import { User } from '../entities/User';
-import { UserGroup } from '../entities/UserGroup';
import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';
import { ResponsePrincipal } from './ResponsePrincipal';
+import { ResponseUserGroup } from './ResponseUserGroup';
/**
* Defines the user response.
@@ -74,7 +74,7 @@ export class ResponseUser extends ResponsePrincipal implements IResponse {
*/
@IsArray()
@IsOptional()
- groups: UserGroup[];
+ groups: ResponseUserGroup[];
/**
* The user's permissions.
@@ -98,10 +98,13 @@ export class ResponseUser extends ResponsePrincipal implements IResponse {
this.username = user.username;
this.enabled = user.enabled;
this.profilePic = user.profilePic;
- this.groups = user.groups;
+ this.groups = new Array();
this.permissions = user.allPermissions;
- if (this.groups) {
- this.groups.forEach(function (g) { delete g.permissions });
+ if (user.groups) {
+ for (let group of user.groups) {
+ delete group.permissions;
+ this.groups.push(group.toResponse());
+ }
}
}
}
diff --git a/src/models/responses/ResponseUserGroup.ts b/src/models/responses/ResponseUserGroup.ts
index 9d1923f..e6f00bb 100644
--- a/src/models/responses/ResponseUserGroup.ts
+++ b/src/models/responses/ResponseUserGroup.ts
@@ -1,8 +1,8 @@
import { IsArray, IsNotEmpty, IsOptional, IsString } from "class-validator";
-import { Permission } from '../entities/Permission';
import { UserGroup } from '../entities/UserGroup';
import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';
+import { ResponsePermission } from './ResponsePermission';
import { ResponsePrincipal } from './ResponsePrincipal';
/**
@@ -34,7 +34,7 @@ export class ResponseUserGroup extends ResponsePrincipal implements IResponse {
*/
@IsArray()
@IsOptional()
- permissions: Permission[];
+ permissions: ResponsePermission[];
/**
* Creates a ResponseUserGroup object from a userGroup.
@@ -44,6 +44,10 @@ export class ResponseUserGroup extends ResponsePrincipal implements IResponse {
super(group);
this.name = group.name;
this.description = group.description;
- this.permissions = group.permissions;
+ if (group.permissions) {
+ for (let permission of group.permissions) {
+ this.permissions.push(permission.toResponse());
+ }
+ }
}
}