diff --git a/src/controllers/PermissionController.ts b/src/controllers/PermissionController.ts index e123e81..663343c 100644 --- a/src/controllers/PermissionController.ts +++ b/src/controllers/PermissionController.ts @@ -90,7 +90,7 @@ export class PermissionController { if (oldPermission.id != permission.id) { throw new PermissionIdsNotMatchingError(); } - let existingPermission = await this.permissionRepository.findOne({ target: permission.target, action: permission.action, principal: permission.principal }, { relations: ['principal'] }); + let existingPermission = await this.permissionRepository.findOne({ target: permission.target, action: permission.action, principal: await permission.getPrincipal() }, { relations: ['principal'] }); if (existingPermission) { await this.remove(permission.id, true); return new ResponsePermission(existingPermission); diff --git a/src/models/actions/create/CreateAddress.ts b/src/models/actions/create/CreateAddress.ts index c399bb8..0241301 100644 --- a/src/models/actions/create/CreateAddress.ts +++ b/src/models/actions/create/CreateAddress.ts @@ -32,7 +32,6 @@ export class CreateAddress { /** * The new address's postal code. * This will get checked against the postal code syntax for the configured country. - * TODO: Implement the config option. */ @IsString() @IsNotEmpty() diff --git a/src/models/actions/create/CreateDistanceDonation.ts b/src/models/actions/create/CreateDistanceDonation.ts index e212068..b1ba1dd 100644 --- a/src/models/actions/create/CreateDistanceDonation.ts +++ b/src/models/actions/create/CreateDistanceDonation.ts @@ -11,7 +11,7 @@ import { CreateDonation } from './CreateDonation'; export class CreateDistanceDonation extends CreateDonation { /** - * The donation's associated runner. + * The donation's associated runner's id. * This is important to link the runner's distance ran to the donation. */ @IsInt() diff --git a/src/models/actions/create/CreateDonation.ts b/src/models/actions/create/CreateDonation.ts index 3b9218f..50d7cd7 100644 --- a/src/models/actions/create/CreateDonation.ts +++ b/src/models/actions/create/CreateDonation.ts @@ -9,7 +9,7 @@ import { Donor } from '../../entities/Donor'; */ export abstract class CreateDonation { /** - * The donation's associated donor. + * The donation's associated donor's id. * This is important to link donations to donors. */ @IsInt() diff --git a/src/models/actions/create/CreateGroupContact.ts b/src/models/actions/create/CreateGroupContact.ts index c6e10a8..b9a9d41 100644 --- a/src/models/actions/create/CreateGroupContact.ts +++ b/src/models/actions/create/CreateGroupContact.ts @@ -1,7 +1,7 @@ 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 { AddressNotFoundError } from '../../../errors/AddressErrors'; import { Address } from '../../entities/Address'; import { GroupContact } from '../../entities/GroupContact'; @@ -31,8 +31,7 @@ export class CreateGroupContact { lastname: string; /** - * The new contact's address. - * Must be the address's id. + * The new contact's address's id. */ @IsInt() @IsOptional() @@ -57,16 +56,10 @@ export class CreateGroupContact { * Gets the new contact's address by it's id. */ public async getAddress(): Promise
{ - if (this.address === undefined || this.address === null) { - return null; - } - if (!isNaN(this.address)) { - let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address }); - if (!address) { throw new AddressNotFoundError; } - return address; - } - - throw new AddressWrongTypeError; + if (!this.address) { return null; } + let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address }); + if (!address) { throw new AddressNotFoundError; } + return address; } /** diff --git a/src/models/actions/create/CreateParticipant.ts b/src/models/actions/create/CreateParticipant.ts index 17e7c56..6518666 100644 --- a/src/models/actions/create/CreateParticipant.ts +++ b/src/models/actions/create/CreateParticipant.ts @@ -1,7 +1,7 @@ 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 { AddressNotFoundError } from '../../../errors/AddressErrors'; import { Address } from '../../entities/Address'; /** @@ -47,26 +47,19 @@ export abstract class CreateParticipant { email?: string; /** - * The new participant's address. - * Must be of type number (address id). + * The new participant's address's id. */ @IsInt() @IsOptional() address?: number; /** - * Gets the new participant's address by it's address. + * Gets the new participant's address by it's id. */ public async getAddress(): Promise
{ - if (this.address === undefined || this.address === null) { - return null; - } - if (!isNaN(this.address)) { - let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address }); - if (!address) { throw new AddressNotFoundError; } - return address; - } - - throw new AddressWrongTypeError; + if (!this.address) { return null; } + let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address }); + if (!address) { throw new AddressNotFoundError; } + return address; } } \ No newline at end of file diff --git a/src/models/actions/create/CreateRunnerCard.ts b/src/models/actions/create/CreateRunnerCard.ts index b661e6f..20dc903 100644 --- a/src/models/actions/create/CreateRunnerCard.ts +++ b/src/models/actions/create/CreateRunnerCard.ts @@ -9,7 +9,7 @@ import { RunnerCard } from '../../entities/RunnerCard'; */ export class CreateRunnerCard { /** - * The card's associated runner. + * The card's associated runner's id. */ @IsInt() @IsOptional() diff --git a/src/models/actions/create/CreateRunnerGroup.ts b/src/models/actions/create/CreateRunnerGroup.ts index 0b62024..aadea29 100644 --- a/src/models/actions/create/CreateRunnerGroup.ts +++ b/src/models/actions/create/CreateRunnerGroup.ts @@ -1,6 +1,6 @@ import { IsInt, IsNotEmpty, IsOptional, IsString } from 'class-validator'; import { getConnectionManager } from 'typeorm'; -import { GroupContactNotFoundError, GroupContactWrongTypeError } from '../../../errors/GroupContactErrors'; +import { GroupContactNotFoundError } from '../../../errors/GroupContactErrors'; import { GroupContact } from '../../entities/GroupContact'; /** @@ -15,7 +15,7 @@ export abstract class CreateRunnerGroup { name: string; /** - * The new group's contact. + * The new group's contact's id. * Optional */ @IsInt() @@ -26,15 +26,10 @@ export abstract class CreateRunnerGroup { * Gets the new group's contact by it's id. */ public async getContact(): Promise { - if (this.contact === undefined || this.contact === null) { - return null; - } - if (!isNaN(this.contact)) { - let contact = await getConnectionManager().get().getRepository(GroupContact).findOne({ id: this.contact }); - if (!contact) { throw new GroupContactNotFoundError; } - return contact; - } + if (!this.contact) { return null; } + let contact = await getConnectionManager().get().getRepository(GroupContact).findOne({ id: this.contact }); + if (!contact) { throw new GroupContactNotFoundError; } + return contact; - throw new GroupContactWrongTypeError; } } \ No newline at end of file diff --git a/src/models/actions/create/CreateRunnerOrganisation.ts b/src/models/actions/create/CreateRunnerOrganisation.ts index 04edf93..1938eee 100644 --- a/src/models/actions/create/CreateRunnerOrganisation.ts +++ b/src/models/actions/create/CreateRunnerOrganisation.ts @@ -1,6 +1,6 @@ import { IsInt, IsOptional } from 'class-validator'; import { getConnectionManager } from 'typeorm'; -import { AddressNotFoundError, AddressWrongTypeError } from '../../../errors/AddressErrors'; +import { AddressNotFoundError } from '../../../errors/AddressErrors'; import { Address } from '../../entities/Address'; import { RunnerOrganisation } from '../../entities/RunnerOrganisation'; import { CreateRunnerGroup } from './CreateRunnerGroup'; @@ -10,8 +10,7 @@ import { CreateRunnerGroup } from './CreateRunnerGroup'; */ export class CreateRunnerOrganisation extends CreateRunnerGroup { /** - * The new organisation's address. - * Must be of type number (address id). + * The new organisation's address's id. */ @IsInt() @IsOptional() @@ -21,16 +20,10 @@ export class CreateRunnerOrganisation extends CreateRunnerGroup { * Gets the org's address by it's id. */ public async getAddress(): Promise
{ - if (this.address === undefined || this.address === null) { - return null; - } - if (!isNaN(this.address)) { - let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address }); - if (!address) { throw new AddressNotFoundError; } - return address; - } - - throw new AddressWrongTypeError; + if (!this.address) { return null; } + let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address }); + if (!address) { throw new AddressNotFoundError; } + return address; } /** @@ -41,7 +34,7 @@ export class CreateRunnerOrganisation extends CreateRunnerGroup { newRunnerOrganisation.name = this.name; newRunnerOrganisation.contact = await this.getContact(); - // newRunnerOrganisation.address = await this.getAddress(); + newRunnerOrganisation.address = await this.getAddress(); return newRunnerOrganisation; } diff --git a/src/models/actions/create/CreateRunnerTeam.ts b/src/models/actions/create/CreateRunnerTeam.ts index fc5c310..451d9d6 100644 --- a/src/models/actions/create/CreateRunnerTeam.ts +++ b/src/models/actions/create/CreateRunnerTeam.ts @@ -1,6 +1,6 @@ import { IsInt, IsNotEmpty } from 'class-validator'; import { getConnectionManager } from 'typeorm'; -import { RunnerOrganisationNotFoundError, RunnerOrganisationWrongTypeError } from '../../../errors/RunnerOrganisationErrors'; +import { RunnerOrganisationNotFoundError } from '../../../errors/RunnerOrganisationErrors'; import { RunnerTeamNeedsParentError } from '../../../errors/RunnerTeamErrors'; import { RunnerOrganisation } from '../../entities/RunnerOrganisation'; import { RunnerTeam } from '../../entities/RunnerTeam'; @@ -12,7 +12,7 @@ import { CreateRunnerGroup } from './CreateRunnerGroup'; export class CreateRunnerTeam extends CreateRunnerGroup { /** - * The new team's parent group (organisation). + * The new team's parent org's id. */ @IsInt() @IsNotEmpty() @@ -25,13 +25,9 @@ export class CreateRunnerTeam extends CreateRunnerGroup { if (this.parentGroup === undefined || this.parentGroup === null) { throw new RunnerTeamNeedsParentError(); } - if (!isNaN(this.parentGroup)) { - let parentGroup = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: this.parentGroup }); - if (!parentGroup) { throw new RunnerOrganisationNotFoundError();; } - return parentGroup; - } - - throw new RunnerOrganisationWrongTypeError; + let parentGroup = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: this.parentGroup }); + if (!parentGroup) { throw new RunnerOrganisationNotFoundError();; } + return parentGroup; } /** @@ -42,7 +38,6 @@ export class CreateRunnerTeam extends CreateRunnerGroup { newRunnerTeam.name = this.name; newRunnerTeam.parentGroup = await this.getParent(); - newRunnerTeam.contact = await this.getContact() return newRunnerTeam; diff --git a/src/models/actions/create/CreateScan.ts b/src/models/actions/create/CreateScan.ts index 496b8a0..fed4971 100644 --- a/src/models/actions/create/CreateScan.ts +++ b/src/models/actions/create/CreateScan.ts @@ -9,7 +9,7 @@ import { Scan } from '../../entities/Scan'; */ export abstract class CreateScan { /** - * The scan's associated runner. + * The scan's associated runner's id. * This is important to link ran distances to runners. */ @IsInt() diff --git a/src/models/actions/create/CreateScanStation.ts b/src/models/actions/create/CreateScanStation.ts index 0804b9f..7025eb2 100644 --- a/src/models/actions/create/CreateScanStation.ts +++ b/src/models/actions/create/CreateScanStation.ts @@ -19,7 +19,7 @@ export class CreateScanStation { description?: string; /** - * The station's associated track. + * The station's associated track's id. */ @IsInt() @IsPositive() diff --git a/src/models/actions/create/CreateTrackScan.ts b/src/models/actions/create/CreateTrackScan.ts index db63cf2..89ccb5b 100644 --- a/src/models/actions/create/CreateTrackScan.ts +++ b/src/models/actions/create/CreateTrackScan.ts @@ -12,7 +12,7 @@ import { TrackScan } from '../../entities/TrackScan'; */ export class CreateTrackScan { /** - * The runnerCard associated with the scan. + * The id of the runnerCard associated with the scan. * This get's saved for documentation and management purposes. */ @IsInt() @@ -20,8 +20,8 @@ export class CreateTrackScan { card: number; /** - * The scanning station that created the scan. - * Mainly used for logging and traceing back scans (or errors) + * The scanning station's id that created the scan. + * Mainly used for logging and traceing back scans (or errors). */ @IsInt() @IsPositive() diff --git a/src/models/actions/create/CreateUser.ts b/src/models/actions/create/CreateUser.ts index 1942e59..06c2507 100644 --- a/src/models/actions/create/CreateUser.ts +++ b/src/models/actions/create/CreateUser.ts @@ -71,7 +71,7 @@ export class CreateUser { enabled?: boolean = true; /** - * The new user's groups' id(s). + * The new user's groups' ids. * You can provide either one groupId or an array of groupIDs. */ @IsOptional() diff --git a/src/models/actions/update/UpdateDistanceDonation.ts b/src/models/actions/update/UpdateDistanceDonation.ts index 85a5473..67407b9 100644 --- a/src/models/actions/update/UpdateDistanceDonation.ts +++ b/src/models/actions/update/UpdateDistanceDonation.ts @@ -11,7 +11,7 @@ import { UpdateDonation } from './UpdateDonation'; export class UpdateDistanceDonation extends UpdateDonation { /** - * The donation's associated runner. + * The donation's associated runner's id. * This is important to link the runner's distance ran to the donation. */ @IsInt() diff --git a/src/models/actions/update/UpdateDonation.ts b/src/models/actions/update/UpdateDonation.ts index 7f10f97..569454a 100644 --- a/src/models/actions/update/UpdateDonation.ts +++ b/src/models/actions/update/UpdateDonation.ts @@ -16,7 +16,7 @@ export abstract class UpdateDonation { id: number; /** - * The updated donation's associated donor. + * The updated donation's associated donor's id. * This is important to link donations to donors. */ @IsInt() diff --git a/src/models/actions/update/UpdatePermission.ts b/src/models/actions/update/UpdatePermission.ts index e591e20..54a43a0 100644 --- a/src/models/actions/update/UpdatePermission.ts +++ b/src/models/actions/update/UpdatePermission.ts @@ -1,7 +1,7 @@ -import { IsInt, IsNotEmpty, IsObject } from 'class-validator'; +import { IsInt, IsNotEmpty, IsPositive } from 'class-validator'; import { getConnectionManager } from 'typeorm'; import { PermissionNeedsPrincipalError } from '../../../errors/PermissionErrors'; -import { PrincipalNotFoundError, PrincipalWrongTypeError } from '../../../errors/PrincipalErrors'; +import { PrincipalNotFoundError } from '../../../errors/PrincipalErrors'; import { Permission } from '../../entities/Permission'; import { Principal } from '../../entities/Principal'; import { PermissionAction } from '../../enums/PermissionAction'; @@ -20,12 +20,11 @@ export class UpdatePermission { id: number; /** - * The updated permissions's principal. - * Just has to contain the principal's id -everything else won't be checked or changed. + * The updated permissions's principal's id. */ - @IsObject() - @IsNotEmpty() - principal: Principal; + @IsInt() + @IsPositive() + principal: number; /** * The permissions's target. @@ -57,12 +56,8 @@ export class UpdatePermission { if (this.principal === undefined || this.principal === null) { throw new PermissionNeedsPrincipalError(); } - if (!isNaN(this.principal.id)) { - let principal = await getConnectionManager().get().getRepository(Principal).findOne({ id: this.principal.id }); - if (!principal) { throw new PrincipalNotFoundError(); } - return principal; - } - - throw new PrincipalWrongTypeError(); + let principal = await getConnectionManager().get().getRepository(Principal).findOne({ id: this.principal }); + if (!principal) { throw new PrincipalNotFoundError(); } + return principal; } } \ No newline at end of file diff --git a/src/models/actions/update/UpdateRunner.ts b/src/models/actions/update/UpdateRunner.ts index 29a2423..e9e323b 100644 --- a/src/models/actions/update/UpdateRunner.ts +++ b/src/models/actions/update/UpdateRunner.ts @@ -1,7 +1,6 @@ -import { IsInt, IsObject } from 'class-validator'; +import { IsInt, IsPositive } from 'class-validator'; import { getConnectionManager } from 'typeorm'; import { RunnerGroupNotFoundError } from '../../../errors/RunnerGroupErrors'; -import { RunnerOrganisationWrongTypeError } from '../../../errors/RunnerOrganisationErrors'; import { RunnerTeamNeedsParentError } from '../../../errors/RunnerTeamErrors'; import { Runner } from '../../entities/Runner'; import { RunnerGroup } from '../../entities/RunnerGroup'; @@ -20,11 +19,11 @@ export class UpdateRunner extends CreateParticipant { id: number; /** - * The updated runner's new team/org. - * Just has to contain the group's id -everything else won't be checked or changed. + * The updated runner's group's id. */ - @IsObject() - group: RunnerGroup; + @IsInt() + @IsPositive() + group: number; /** * Updates a provided Runner entity based on this. @@ -48,12 +47,8 @@ export class UpdateRunner extends CreateParticipant { if (this.group === undefined || this.group === null) { throw new RunnerTeamNeedsParentError(); } - if (!isNaN(this.group.id)) { - let group = await getConnectionManager().get().getRepository(RunnerGroup).findOne({ id: this.group.id }); - if (!group) { throw new RunnerGroupNotFoundError; } - return group; - } - - throw new RunnerOrganisationWrongTypeError; + let group = await getConnectionManager().get().getRepository(RunnerGroup).findOne({ id: this.group }); + if (!group) { throw new RunnerGroupNotFoundError; } + return group; } } \ No newline at end of file diff --git a/src/models/actions/update/UpdateRunnerCard.ts b/src/models/actions/update/UpdateRunnerCard.ts index 51f70bf..1449600 100644 --- a/src/models/actions/update/UpdateRunnerCard.ts +++ b/src/models/actions/update/UpdateRunnerCard.ts @@ -17,7 +17,7 @@ export class UpdateRunnerCard { id?: number; /** - * The updated card's associated runner. + * The updated card's associated runner's id. */ @IsInt() @IsOptional() diff --git a/src/models/actions/update/UpdateRunnerOrganisation.ts b/src/models/actions/update/UpdateRunnerOrganisation.ts index 7270923..20656ec 100644 --- a/src/models/actions/update/UpdateRunnerOrganisation.ts +++ b/src/models/actions/update/UpdateRunnerOrganisation.ts @@ -18,22 +18,18 @@ export class UpdateRunnerOrganisation extends CreateRunnerGroup { id: number; /** - * The updated organisation's address. - * Just has to contain the address's id - everything else won't be checked or changed. - * Optional. + * The updated organisation's address's id. */ @IsInt() @IsOptional() - address?: Address; + address?: number; /** * Loads the organisation's address based on it's id. */ public async getAddress(): Promise
{ - if (this.address === undefined || this.address === null) { - return null; - } - let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address.id }); + if (!this.address) { return null; } + let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address }); if (!address) { throw new AddressNotFoundError; } return address; } @@ -45,7 +41,7 @@ export class UpdateRunnerOrganisation extends CreateRunnerGroup { organisation.name = this.name; organisation.contact = await this.getContact(); - // organisation.address = await this.getAddress(); + organisation.address = await this.getAddress(); return organisation; } diff --git a/src/models/actions/update/UpdateRunnerTeam.ts b/src/models/actions/update/UpdateRunnerTeam.ts index d7e435d..b5cc7a5 100644 --- a/src/models/actions/update/UpdateRunnerTeam.ts +++ b/src/models/actions/update/UpdateRunnerTeam.ts @@ -1,6 +1,6 @@ -import { IsInt, IsNotEmpty, IsObject } from 'class-validator'; +import { IsInt, IsPositive } from 'class-validator'; import { getConnectionManager } from 'typeorm'; -import { RunnerOrganisationNotFoundError, RunnerOrganisationWrongTypeError } from '../../../errors/RunnerOrganisationErrors'; +import { RunnerOrganisationNotFoundError } from '../../../errors/RunnerOrganisationErrors'; import { RunnerTeamNeedsParentError } from '../../../errors/RunnerTeamErrors'; import { RunnerOrganisation } from '../../entities/RunnerOrganisation'; import { RunnerTeam } from '../../entities/RunnerTeam'; @@ -19,12 +19,11 @@ export class UpdateRunnerTeam extends CreateRunnerGroup { id: number; /** - * The updated team's parentGroup. - * Just has to contain the organisation's id - everything else won't be checked or changed. + * The updated team's parentGroup's id. */ - @IsObject() - @IsNotEmpty() - parentGroup: RunnerOrganisation; + @IsInt() + @IsPositive() + parentGroup: number; /** * Loads the updated teams's parentGroup based on it's id. @@ -33,13 +32,9 @@ export class UpdateRunnerTeam extends CreateRunnerGroup { if (this.parentGroup === undefined || this.parentGroup === null) { throw new RunnerTeamNeedsParentError(); } - if (!isNaN(this.parentGroup.id)) { - let parentGroup = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: this.parentGroup.id }); - if (!parentGroup) { throw new RunnerOrganisationNotFoundError();; } - return parentGroup; - } - - throw new RunnerOrganisationWrongTypeError; + let parentGroup = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: this.parentGroup }); + if (!parentGroup) { throw new RunnerOrganisationNotFoundError();; } + return parentGroup; } /** diff --git a/src/models/actions/update/UpdateScan.ts b/src/models/actions/update/UpdateScan.ts index a0d6633..3357a88 100644 --- a/src/models/actions/update/UpdateScan.ts +++ b/src/models/actions/update/UpdateScan.ts @@ -16,7 +16,7 @@ export abstract class UpdateScan { id: number; /** - * The updated scan's associated runner. + * The updated scan's associated runner's id. * This is important to link ran distances to runners. */ @IsInt() diff --git a/src/models/actions/update/UpdateTrackScan.ts b/src/models/actions/update/UpdateTrackScan.ts index 1280e94..6bdc83e 100644 --- a/src/models/actions/update/UpdateTrackScan.ts +++ b/src/models/actions/update/UpdateTrackScan.ts @@ -1,4 +1,4 @@ -import { IsBoolean, IsInt, IsOptional } from 'class-validator'; +import { IsBoolean, IsInt, IsOptional, IsPositive } from 'class-validator'; import { getConnection } from 'typeorm'; import { RunnerNotFoundError } from '../../../errors/RunnerErrors'; import { ScanStationNotFoundError } from '../../../errors/ScanStationErrors'; @@ -18,12 +18,12 @@ export abstract class UpdateTrackScan { id: number; /** - * The updated scan's associated runner. + * The updated scan's associated runner's id. * This is important to link ran distances to runners. */ @IsInt() - @IsOptional() - runner?: number; + @IsPositive() + runner: number; /** * Is the updated scan valid (for fraud reasons). @@ -33,12 +33,12 @@ export abstract class UpdateTrackScan { valid?: boolean = true; /** - * The updated scan's associated station. + * The updated scan's associated station's id. * This is important to link ran distances to runners. */ @IsInt() - @IsOptional() - public station?: number; + @IsPositive() + public station: number; /** * Update a TrackScan entity based on this. @@ -46,12 +46,8 @@ export abstract class UpdateTrackScan { */ public async update(scan: TrackScan): Promise { scan.valid = this.valid; - if (this.runner) { - scan.runner = await this.getRunner(); - } - if (this.station) { - scan.station = await this.getStation(); - } + scan.runner = await this.getRunner(); + scan.station = await this.getStation(); scan.track = scan.station.track; return scan; @@ -72,7 +68,7 @@ export abstract class UpdateTrackScan { * Gets a runner based on the runner id provided via this.runner. */ public async getStation(): Promise { - const station = await getConnection().getRepository(ScanStation).findOne({ id: this.station }); + const station = await getConnection().getRepository(ScanStation).findOne({ id: this.station }, { relations: ['track'] }); if (!station) { throw new ScanStationNotFoundError(); } diff --git a/src/models/actions/update/UpdateUser.ts b/src/models/actions/update/UpdateUser.ts index 2797b34..c9dedcf 100644 --- a/src/models/actions/update/UpdateUser.ts +++ b/src/models/actions/update/UpdateUser.ts @@ -79,11 +79,10 @@ export class UpdateUser { enabled: boolean = true; /** - * The updated user's groups. - * This just has to contain the group's id - everything else won't be changed. + * The updated user's groups' ids. */ @IsOptional() - groups?: UserGroup[] + groups?: number | number[] /** * The user's profile pic (or rather a url pointing to it). @@ -124,7 +123,7 @@ export class UpdateUser { } /** - * Loads the updated user's groups based on their ids. + * Get's all groups for this user by their id's; */ public async getGroups() { if (!this.groups) { return null; } @@ -133,7 +132,7 @@ export class UpdateUser { this.groups = [this.groups] } for (let group of this.groups) { - let found = await getConnectionManager().get().getRepository(UserGroup).findOne({ id: group.id }); + let found = await getConnectionManager().get().getRepository(UserGroup).findOne({ id: group }); if (!found) { throw new UserGroupNotFoundError(); } groups.push(found); } diff --git a/src/tests/donors/donor_add.spec.ts b/src/tests/donors/donor_add.spec.ts index 8022184..954fd2e 100644 --- a/src/tests/donors/donor_add.spec.ts +++ b/src/tests/donors/donor_add.spec.ts @@ -34,7 +34,7 @@ describe('POST /api/donors with errors', () => { "firstname": "first", "middlename": "middle", "lastname": "last", - "address": 0 + "address": 99999999999999999999999999 }, axios_config); expect(res2.status).toEqual(404); expect(res2.headers['content-type']).toContain("application/json") diff --git a/src/tests/runnerTeams/team_update.spec.ts b/src/tests/runnerTeams/team_update.spec.ts index 5d1355d..7acacd7 100644 --- a/src/tests/runnerTeams/team_update.spec.ts +++ b/src/tests/runnerTeams/team_update.spec.ts @@ -43,7 +43,7 @@ describe('adding + updating name', () => { "id": added_team_id, "name": "testlelele", "contact": null, - "parentGroup": added_org + "parentGroup": added_org.id }, axios_config); expect(res3.status).toEqual(200); expect(res3.headers['content-type']).toContain("application/json") @@ -79,6 +79,7 @@ describe('adding + try updating id (should return 406)', () => { }); it('update team', async () => { added_team.id = added_team.id + 1; + added_team.parentGroup = added_team.parentGroup.id; const res3 = await axios.put(base + '/api/teams/' + added_team_id, added_team, axios_config); expect(res3.status).toEqual(406); expect(res3.headers['content-type']).toContain("application/json") @@ -117,7 +118,7 @@ describe('add+update parent org (valid)', () => { expect(res3.headers['content-type']).toContain("application/json") }); it('update team', async () => { - added_team.parentGroup = added_org2; + added_team.parentGroup = added_org2.id; const res4 = await axios.put(base + '/api/teams/' + added_team_id, added_team, axios_config); let updated_team = res4.data; expect(res4.status).toEqual(200); @@ -125,6 +126,6 @@ describe('add+update parent org (valid)', () => { delete added_org2.address; delete added_org2.contact; delete added_org2.teams; - expect(updated_team).toEqual(added_team) + expect(updated_team.parentGroup).toEqual(added_org2) }); }); \ No newline at end of file diff --git a/src/tests/runners/runner_update.spec.ts b/src/tests/runners/runner_update.spec.ts index d9a1266..39acc5f 100644 --- a/src/tests/runners/runner_update.spec.ts +++ b/src/tests/runners/runner_update.spec.ts @@ -15,15 +15,14 @@ beforeAll(async () => { }); describe('Update runner name after adding', () => { - let added_org_id; + let added_org; let added_runner; let updated_runner; it('creating a new org with just a name should return 200', async () => { const res1 = await axios.post(base + '/api/organisations', { "name": "test123" }, axios_config); - let added_org = res1.data - added_org_id = added_org.id; + added_org = res1.data expect(res1.status).toEqual(200); expect(res1.headers['content-type']).toContain("application/json") }); @@ -31,7 +30,7 @@ describe('Update runner name after adding', () => { const res2 = await axios.post(base + '/api/runners', { "firstname": "first", "lastname": "last", - "group": added_org_id + "group": added_org.id }, axios_config); added_runner = res2.data; expect(res2.status).toEqual(200); @@ -40,10 +39,15 @@ describe('Update runner name after adding', () => { it('valid update should return 200', async () => { let runnercopy = added_runner runnercopy.firstname = "second" + runnercopy.group = added_runner.group.id; const res3 = await axios.put(base + '/api/runners/' + added_runner.id, runnercopy, axios_config); expect(res3.status).toEqual(200); expect(res3.headers['content-type']).toContain("application/json") - updated_runner = res3.data + updated_runner = res3.data; + delete added_org.address; + delete added_org.contact; + delete added_org.teams; + runnercopy.group = added_org; expect(updated_runner).toEqual(runnercopy); }); }); @@ -83,13 +87,13 @@ describe('Update runner group after adding', () => { expect(res3.status).toEqual(200); expect(res3.headers['content-type']).toContain("application/json") }); - it('valid update should return 200', async () => { - added_runner.group = added_org_2; + it('valid group update should return 200', async () => { + added_runner.group = added_org_2.id; const res3 = await axios.put(base + '/api/runners/' + added_runner.id, added_runner, axios_config); expect(res3.status).toEqual(200); expect(res3.headers['content-type']).toContain("application/json") updated_runner = res3.data - expect(updated_runner).toEqual(added_runner); + expect(updated_runner.group).toEqual(added_org_2); }); }); // --------------- @@ -119,6 +123,7 @@ describe('Update runner id after adding(should fail)', () => { }); it('invalid update should return 406', async () => { added_runner.id++; + added_runner.group = added_runner.group.id; const res3 = await axios.put(base + '/api/runners/' + added_runner_id, added_runner, axios_config); expect(res3.status).toEqual(406); expect(res3.headers['content-type']).toContain("application/json") @@ -146,9 +151,8 @@ describe('Update runner group with invalid group after adding', () => { expect(res2.status).toEqual(200); expect(res2.headers['content-type']).toContain("application/json") }); - it('invalid update should return 404', async () => { - added_org.id = 0; - added_runner.group = added_org; + it('invalid group update should return 404', async () => { + added_runner.group = 99999999999999999; const res3 = await axios.put(base + '/api/runners/' + added_runner.id, added_runner, axios_config); expect(res3.status).toEqual(404); expect(res3.headers['content-type']).toContain("application/json")