Merge pull request 'Switched to accepting ids (numbers/number arrays) feature/90-accept_objects' (#101) from feature/90-accept_objects into dev
Reviewed-on: #101
This commit is contained in:
commit
29c8e00477
|
@ -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);
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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<Address> {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<Address> {
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
|
|
|
@ -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<GroupContact> {
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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<Address> {
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -19,7 +19,7 @@ export class CreateScanStation {
|
|||
description?: string;
|
||||
|
||||
/**
|
||||
* The station's associated track.
|
||||
* The station's associated track's id.
|
||||
*/
|
||||
@IsInt()
|
||||
@IsPositive()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
|
|
|
@ -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<Address> {
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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<TrackScan> {
|
||||
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<ScanStation> {
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
});
|
||||
});
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue