Compare commits

..

No commits in common. "65b2399eaa83ae97a8ade0f4eef5a17f15773fcb" and "8870b26ce63d6294567863c76d9dcfccd18e681d" have entirely different histories.

12 changed files with 120 additions and 214 deletions

View File

@ -1,18 +0,0 @@
import { IsString } from 'class-validator';
import { NotAcceptableError, NotFoundError } from 'routing-controllers';
export class AddressWrongTypeError extends NotAcceptableError {
@IsString()
name = "AddressWrongTypeError"
@IsString()
message = "The address must be an existing adress's id. \n You provided a object of another type."
}
export class AddressNotFoundError extends NotFoundError {
@IsString()
name = "AddressNotFoundError"
@IsString()
message = "The address you provided couldn't be located in the system. \n Please check your request."
}

View File

@ -1,18 +0,0 @@
import { IsString } from 'class-validator';
import { NotAcceptableError, NotFoundError } from 'routing-controllers';
export class GroupContactWrongTypeError extends NotAcceptableError {
@IsString()
name = "GroupContactWrongTypeError"
@IsString()
message = "The groupContact must be an existing groupContact's id. \n You provided a object of another type."
}
export class GroupContactNotFoundError extends NotFoundError {
@IsString()
name = "GroupContactNotFoundError"
@IsString()
message = "The groupContact you provided couldn't be located in the system. \n Please check your request."
}

View File

@ -0,0 +1,18 @@
import { IsString } from 'class-validator';
import { NotAcceptableError, NotFoundError } from 'routing-controllers';
export class ParticipantOnlyOneAddressAllowedError extends NotAcceptableError {
@IsString()
name = "ParticipantOnlyOneAddressAllowedError"
@IsString()
message = "Participant's can only have one address! \n You provided an id and address object.."
}
export class ParticipantAddressNotFoundError extends NotFoundError {
@IsString()
name = "ParticipantAddressNotFoundError"
@IsString()
message = "The address you provided couldn't be located in the system. \n Please check your request."
}

View File

@ -1,5 +1,5 @@
import { IsString } from 'class-validator'; import { JsonController, Param, Body, Get, Post, Put, Delete, NotFoundError, OnUndefined, NotAcceptableError } from 'routing-controllers';
import { NotAcceptableError, NotFoundError } from 'routing-controllers'; import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator';
/** /**
* Error to throw when a runner couldn't be found. * Error to throw when a runner couldn't be found.

View File

@ -49,11 +49,3 @@ export class RunnerOrganisationHasTeamsError extends NotAcceptableError {
@IsString() @IsString()
message = "This organisation still has teams associated with it. \n If you want to delete this organisation with all it's runners and teams ass `?force` to your query." message = "This organisation still has teams associated with it. \n If you want to delete this organisation with all it's runners and teams ass `?force` to your query."
} }
export class RunnerOrganisationWrongTypeError extends NotAcceptableError {
@IsString()
name = "RunnerOrganisationWrongTypeError"
@IsString()
message = "The runner organisation must be an existing organisation's id. \n You provided a object of another type."
}

View File

@ -37,15 +37,3 @@ export class RunnerTeamHasRunnersError extends NotAcceptableError {
@IsString() @IsString()
message = "This team still has runners associated with it. \n If you want to delete this team with all it's runners and teams ass `?force` to your query." message = "This team still has runners associated with it. \n If you want to delete this team with all it's runners and teams ass `?force` to your query."
} }
/**
* Error to throw when a team still has runners associated.
* Implemented this waysto work with the json-schema conversion for openapi.
*/
export class RunnerTeamNeedsParentError extends NotAcceptableError {
@IsString()
name = "RunnerTeamNeedsParentError"
@IsString()
message = "You provided no runner organisation as this team's parent group."
}

View File

@ -1,83 +0,0 @@
import { IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
import { getConnectionManager } from 'typeorm';
import { AddressNotFoundError, AddressWrongTypeError } from '../../errors/AddressErrors';
import { Address } from '../entities/Address';
import { GroupContact } from '../entities/GroupContact';
export class CreateGroupContact {
/**
* The contact's first name.
*/
@IsNotEmpty()
@IsString()
firstname: string;
/**
* The contact's middle name.
* Optional
*/
@IsOptional()
@IsString()
middlename?: string;
/**
* The contact's last name.
*/
@IsNotEmpty()
@IsString()
lastname: string;
/**
* The contact's address.
* Optional
*/
@IsInt()
@IsOptional()
address?: number;
/**
* The contact's phone number.
* Optional
*/
@IsOptional()
@IsPhoneNumber("DE")
phone?: string;
/**
* The contact's email address.
* Optional
*/
@IsOptional()
@IsEmail()
email?: string;
/**
* Get's this participant's address from this.address.
*/
public async getAddress(): Promise<Address> {
if (this.address === undefined) {
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;
}
/**
* Creates a Address object based on this.
*/
public async toGroupContact(): Promise<GroupContact> {
let contact: GroupContact = new GroupContact();
contact.firstname = this.firstname;
contact.middlename = this.middlename;
contact.lastname = this.lastname;
contact.email = this.email;
contact.phone = this.phone;
contact.address = await this.getAddress();
return null;
}
}

View File

@ -1,7 +1,8 @@
import { IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsString } from 'class-validator'; import { IsEmail, IsInt, IsNotEmpty, IsObject, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
import { getConnectionManager } from 'typeorm'; import { getConnectionManager } from 'typeorm';
import { AddressNotFoundError, AddressWrongTypeError } from '../../errors/AddressErrors'; import { ParticipantOnlyOneAddressAllowedError } from '../../errors/ParticipantErrors';
import { Address } from '../entities/Address'; import { Address } from '../entities/Address';
import { CreateAddress } from './CreateAddress';
export abstract class CreateParticipant { export abstract class CreateParticipant {
/** /**
@ -45,27 +46,38 @@ export abstract class CreateParticipant {
email?: string; email?: string;
/** /**
* The new participant's address. * The new participant's address's id.
* Must be of type number (address id), createAddress (new address) or address (existing address) * Optional - please provide either addressId or address.
* Optional.
*/ */
@IsInt() @IsInt()
@IsOptional() @IsOptional()
address?: number; addressId?: number;
/** /**
* Get's this participant's address from this.address. * The new participant's address.
* Optional - please provide either addressId or address.
*/
@IsObject()
@IsOptional()
address?: CreateAddress;
/**
* Creates a Participant entity from this.
*/ */
public async getAddress(): Promise<Address> { public async getAddress(): Promise<Address> {
if (this.address === undefined) { let address: Address;
if (this.addressId !== undefined && this.address !== undefined) {
throw new ParticipantOnlyOneAddressAllowedError
}
if (this.addressId === undefined && this.address === undefined) {
return null; return null;
} }
if (!isNaN(this.address)) {
let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address }); if (this.addressId) {
if (!address) { throw new AddressNotFoundError; } return await getConnectionManager().get().getRepository(Address).findOne({ id: this.addressId });
return address;
} }
throw new AddressWrongTypeError; return this.address.toAddress();
} }
} }

View File

@ -1,10 +1,10 @@
import { IsInt } from 'class-validator'; import { IsInt, IsOptional } from 'class-validator';
import { getConnectionManager } from 'typeorm'; import { getConnectionManager } from 'typeorm';
import { RunnerGroupNotFoundError } from '../../errors/RunnerErrors'; import { RunnerGroupNeededError, RunnerGroupNotFoundError, RunnerOnlyOneGroupAllowedError } from '../../errors/RunnerErrors';
import { RunnerOrganisationWrongTypeError } from '../../errors/RunnerOrganisationErrors';
import { RunnerTeamNeedsParentError } from '../../errors/RunnerTeamErrors';
import { Runner } from '../entities/Runner'; import { Runner } from '../entities/Runner';
import { RunnerGroup } from '../entities/RunnerGroup'; import { RunnerGroup } from '../entities/RunnerGroup';
import { RunnerOrganisation } from '../entities/RunnerOrganisation';
import { RunnerTeam } from '../entities/RunnerTeam';
import { CreateParticipant } from './CreateParticipant'; import { CreateParticipant } from './CreateParticipant';
export class CreateRunner extends CreateParticipant { export class CreateRunner extends CreateParticipant {
@ -14,7 +14,16 @@ export class CreateRunner extends CreateParticipant {
* Either provide this or his organisation's id. * Either provide this or his organisation's id.
*/ */
@IsInt() @IsInt()
group: number; @IsOptional()
teamId?: number;
/**
* The new runner's organisation's id.
* Either provide this or his teams's id.
*/
@IsInt()
@IsOptional()
orgId?: number;
/** /**
* Creates a Runner entity from this. * Creates a Runner entity from this.
@ -37,15 +46,23 @@ export class CreateRunner extends CreateParticipant {
* Manages all the different ways a group can be provided. * Manages all the different ways a group can be provided.
*/ */
public async getGroup(): Promise<RunnerGroup> { public async getGroup(): Promise<RunnerGroup> {
if (this.group === undefined) { let group: RunnerGroup;
throw new RunnerTeamNeedsParentError(); if (this.teamId !== undefined && this.orgId !== undefined) {
throw new RunnerOnlyOneGroupAllowedError();
} }
if (!isNaN(this.group)) { if (this.teamId === undefined && this.orgId === undefined) {
let group = await getConnectionManager().get().getRepository(RunnerGroup).findOne({ id: this.group }); throw new RunnerGroupNeededError();
if (!group) { throw new RunnerGroupNotFoundError; }
return group;
} }
throw new RunnerOrganisationWrongTypeError; if (this.teamId) {
group = await getConnectionManager().get().getRepository(RunnerTeam).findOne({ id: this.teamId });
}
if (this.orgId) {
group = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: this.orgId });
}
if (!group) {
throw new RunnerGroupNotFoundError();
}
return group;
} }
} }

View File

@ -1,6 +1,4 @@
import { IsInt, IsNotEmpty, IsOptional, IsString } from 'class-validator'; import { IsNotEmpty, IsObject, IsOptional, IsString } from 'class-validator';
import { getConnectionManager } from 'typeorm';
import { GroupContactNotFoundError, GroupContactWrongTypeError } from '../../errors/GroupContactErrors';
import { GroupContact } from '../entities/GroupContact'; import { GroupContact } from '../entities/GroupContact';
export abstract class CreateRunnerGroup { export abstract class CreateRunnerGroup {
@ -15,23 +13,18 @@ export abstract class CreateRunnerGroup {
* The group's contact. * The group's contact.
* Optional * Optional
*/ */
@IsInt() @IsObject()
@IsOptional() @IsOptional()
contact?: number; contact?: GroupContact;
/** /**
* Deals with the contact for groups this. * Deals with the contact for groups this.
*/ */
public async getContact(): Promise<GroupContact> { public async getContact(): Promise<GroupContact> {
if (this.contact === undefined) { let newGroupContact: GroupContact;
return null;
}
if (!isNaN(this.contact)) {
let address = await getConnectionManager().get().getRepository(GroupContact).findOne({ id: this.contact });
if (!address) { throw new GroupContactNotFoundError; }
return address;
}
throw new GroupContactWrongTypeError; //TODO:
return newGroupContact;
} }
} }

View File

@ -1,34 +1,46 @@
import { IsInt, IsOptional } from 'class-validator'; import { IsInt, IsObject, IsOptional } from 'class-validator';
import { getConnectionManager } from 'typeorm'; import { getConnectionManager } from 'typeorm';
import { AddressNotFoundError, AddressWrongTypeError } from '../../errors/AddressErrors'; import { ParticipantOnlyOneAddressAllowedError } from '../../errors/ParticipantErrors';
import { Address } from '../entities/Address'; import { Address } from '../entities/Address';
import { RunnerOrganisation } from '../entities/RunnerOrganisation'; import { RunnerOrganisation } from '../entities/RunnerOrganisation';
import { CreateAddress } from './CreateAddress';
import { CreateRunnerGroup } from './CreateRunnerGroup'; import { CreateRunnerGroup } from './CreateRunnerGroup';
export class CreateRunnerOrganisation extends CreateRunnerGroup { export class CreateRunnerOrganisation extends CreateRunnerGroup {
/** /**
* The new organisation's address. * The new participant's address's id.
* Must be of type number (address id), createAddress (new address) or address (existing address) * Optional - please provide either addressId or address.
* Optional.
*/ */
@IsInt() @IsInt()
@IsOptional() @IsOptional()
address?: number; addressId?: number;
/**
* The new participant's address.
* Optional - please provide either addressId or address.
*/
@IsObject()
@IsOptional()
address?: CreateAddress;
/** /**
* Creates a Participant entity from this. * Creates a Participant entity from this.
*/ */
public async getAddress(): Promise<Address> { public async getAddress(): Promise<Address> {
if (this.address === undefined) { let address: Address;
if (this.addressId !== undefined && this.address !== undefined) {
throw new ParticipantOnlyOneAddressAllowedError
}
if (this.addressId === undefined && this.address === undefined) {
return null; return null;
} }
if (!isNaN(this.address)) {
let address = await getConnectionManager().get().getRepository(Address).findOne({ id: this.address }); if (this.addressId) {
if (!address) { throw new AddressNotFoundError; } return await getConnectionManager().get().getRepository(Address).findOne({ id: this.addressId });
return address;
} }
throw new AddressWrongTypeError; return this.address.toAddress();
} }
/** /**

View File

@ -1,32 +1,23 @@
import { IsInt, IsNotEmpty } from 'class-validator'; import { IsInt, IsNotEmpty, IsString } from 'class-validator';
import { getConnectionManager } from 'typeorm'; 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 { RunnerOrganisation } from '../entities/RunnerOrganisation';
import { RunnerTeam } from '../entities/RunnerTeam'; import { RunnerTeam } from '../entities/RunnerTeam';
import { CreateRunnerGroup } from './CreateRunnerGroup';
export class CreateRunnerTeam extends CreateRunnerGroup { export class CreateRunnerTeam {
/**
* The teams's name.
*/
@IsString()
@IsNotEmpty()
name: string;
/** /**
* The team's parent group (organisation). * The team's parent group (organisation).
*/ */
@IsInt() @IsInt()
@IsNotEmpty() @IsNotEmpty()
parentGroup: number; parentId: number
public async getParent(): Promise<RunnerOrganisation> {
if (this.parentGroup === undefined) {
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;
}
/** /**
* Creates a RunnerTeam entity from this. * Creates a RunnerTeam entity from this.
@ -35,8 +26,10 @@ export class CreateRunnerTeam extends CreateRunnerGroup {
let newRunnerTeam: RunnerTeam = new RunnerTeam(); let newRunnerTeam: RunnerTeam = new RunnerTeam();
newRunnerTeam.name = this.name; newRunnerTeam.name = this.name;
newRunnerTeam.parentGroup = await this.getParent(); newRunnerTeam.parentGroup = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: this.parentId });
newRunnerTeam.contact = await this.getContact() if (!newRunnerTeam.parentGroup) {
throw new RunnerOrganisationNotFoundError();
}
return newRunnerTeam; return newRunnerTeam;
} }