Merge branch 'dev' into feature/14-user-controllers
This commit is contained in:
58
src/models/CreateRunner.ts
Normal file
58
src/models/CreateRunner.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { IsEmail, IsInt, IsNotEmpty, IsOptional, IsPhoneNumber, IsPositive, IsString } from 'class-validator';
|
||||
import { Runner } from '../models/Runner';
|
||||
import { getConnectionManager, Repository } from 'typeorm';
|
||||
import { group } from 'console';
|
||||
import { RunnerOnlyOneGroupAllowedError, RunnerGroupNeededError, RunnerGroupNotFoundError } from '../errors/RunnerErrors';
|
||||
import { RunnerOrganisation } from './RunnerOrganisation';
|
||||
import { RunnerTeam } from './RunnerTeam';
|
||||
import { RunnerGroup } from './RunnerGroup';
|
||||
import { Address } from 'cluster';
|
||||
|
||||
export class CreateRunner {
|
||||
@IsString()
|
||||
firstname: string;
|
||||
@IsString()
|
||||
middlename?: string;
|
||||
@IsString()
|
||||
lastname: string;
|
||||
@IsString()
|
||||
phone?: string;
|
||||
@IsString()
|
||||
email?: string;
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
teamId?: number
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
orgId?: number
|
||||
|
||||
public async toRunner(): Promise<Runner> {
|
||||
let newRunner: Runner = new Runner();
|
||||
|
||||
if (this.teamId !== undefined && this.orgId !== undefined) {
|
||||
throw new RunnerOnlyOneGroupAllowedError();
|
||||
}
|
||||
if (this.teamId === undefined && this.orgId === undefined) {
|
||||
throw new RunnerGroupNeededError();
|
||||
}
|
||||
|
||||
if (this.teamId) {
|
||||
newRunner.group = await getConnectionManager().get().getRepository(RunnerTeam).findOne({ id: this.teamId });
|
||||
}
|
||||
if (this.orgId) {
|
||||
newRunner.group = await getConnectionManager().get().getRepository(RunnerOrganisation).findOne({ id: this.orgId });
|
||||
}
|
||||
if (!newRunner.group) {
|
||||
throw new RunnerGroupNotFoundError();
|
||||
}
|
||||
|
||||
newRunner.firstname = this.firstname;
|
||||
newRunner.middlename = this.middlename;
|
||||
newRunner.lastname = this.lastname;
|
||||
newRunner.phone = this.phone;
|
||||
newRunner.email = this.email;
|
||||
|
||||
console.log(newRunner)
|
||||
return newRunner;
|
||||
}
|
||||
}
|
||||
15
src/models/CreateRunnerOrganisation.ts
Normal file
15
src/models/CreateRunnerOrganisation.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { IsString } from 'class-validator';
|
||||
import { RunnerOrganisation } from './RunnerOrganisation';
|
||||
|
||||
export class CreateRunnerOrganisation {
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
public async toRunnerOrganisation(): Promise<RunnerOrganisation> {
|
||||
let newRunnerOrganisation: RunnerOrganisation = new RunnerOrganisation();
|
||||
|
||||
newRunnerOrganisation.name = this.name;
|
||||
|
||||
return newRunnerOrganisation;
|
||||
}
|
||||
}
|
||||
30
src/models/CreateTrack.ts
Normal file
30
src/models/CreateTrack.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator';
|
||||
import { Track } from './Track';
|
||||
|
||||
export class CreateTrack {
|
||||
/**
|
||||
* The track's name.
|
||||
*/
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* The track's distance in meters (must be greater 0).
|
||||
*/
|
||||
@IsInt()
|
||||
@IsPositive()
|
||||
distance: number;
|
||||
|
||||
/**
|
||||
* Converts a Track object based on this.
|
||||
*/
|
||||
public toTrack(): Track {
|
||||
let newTrack: Track = new Track();
|
||||
|
||||
newTrack.name = this.name;
|
||||
newTrack.distance = this.distance;
|
||||
|
||||
return newTrack;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Entity, Column, ManyToOne } from "typeorm";
|
||||
import { IsInt, IsNotEmpty, IsPositive,} from "class-validator";
|
||||
import { Entity, Column, ManyToOne, ChildEntity } from "typeorm";
|
||||
import { IsInt, IsNotEmpty, IsPositive, } from "class-validator";
|
||||
import { Donation } from "./Donation";
|
||||
import { Runner } from "./Runner";
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Runner } from "./Runner";
|
||||
* Defines a distance based donation.
|
||||
* Here people donate a certain amout per kilometer
|
||||
*/
|
||||
@Entity()
|
||||
@ChildEntity()
|
||||
export class DistanceDonation extends Donation {
|
||||
/**
|
||||
* The runner associated.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PrimaryGeneratedColumn, Column, ManyToOne, Entity } from "typeorm";
|
||||
import { PrimaryGeneratedColumn, Column, ManyToOne, Entity, TableInheritance } from "typeorm";
|
||||
import {
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
@@ -11,6 +11,7 @@ import { Participant } from "./Participant";
|
||||
* Defines the donation interface.
|
||||
*/
|
||||
@Entity()
|
||||
@TableInheritance({ column: { name: "type", type: "varchar" } })
|
||||
export abstract class Donation {
|
||||
/**
|
||||
* Autogenerated unique id (primary key).
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Entity, Column } from "typeorm";
|
||||
import { Entity, Column, ChildEntity } from "typeorm";
|
||||
import { IsBoolean } from "class-validator";
|
||||
import { Participant } from "./Participant";
|
||||
|
||||
/**
|
||||
* Defines a donor.
|
||||
*/
|
||||
@Entity()
|
||||
@ChildEntity()
|
||||
export class Donor extends Participant {
|
||||
/**
|
||||
* Does this donor need a receipt?.
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Entity, Column } from "typeorm";
|
||||
import { IsInt, IsPositive,} from "class-validator";
|
||||
import { Entity, Column, ChildEntity } from "typeorm";
|
||||
import { IsInt, IsPositive, } from "class-validator";
|
||||
import { Donation } from "./Donation";
|
||||
|
||||
/**
|
||||
* Defines a fixed donation.
|
||||
*/
|
||||
@Entity()
|
||||
@ChildEntity()
|
||||
export class FixedDonation extends Donation {
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity } from "typeorm";
|
||||
import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity, TableInheritance } from "typeorm";
|
||||
import {
|
||||
IsEmail,
|
||||
IsInt,
|
||||
@@ -15,6 +15,7 @@ import { Donation } from "./Donation";
|
||||
* Defines the participant interface.
|
||||
*/
|
||||
@Entity()
|
||||
@TableInheritance({ column: { name: "type", type: "varchar" } })
|
||||
export abstract class Participant {
|
||||
/**
|
||||
* Autogenerated unique id (primary key).
|
||||
@@ -36,7 +37,7 @@ export abstract class Participant {
|
||||
* The participant's middle name.
|
||||
* Optional
|
||||
*/
|
||||
@Column({nullable: true})
|
||||
@Column({ nullable: true })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
middlename?: string;
|
||||
@@ -60,7 +61,7 @@ export abstract class Participant {
|
||||
* The participant's phone number.
|
||||
* Optional
|
||||
*/
|
||||
@Column({nullable: true})
|
||||
@Column({ nullable: true })
|
||||
@IsOptional()
|
||||
@IsPhoneNumber("DE")
|
||||
phone?: string;
|
||||
@@ -69,7 +70,7 @@ export abstract class Participant {
|
||||
* The participant's email address.
|
||||
* Optional
|
||||
*/
|
||||
@Column({nullable: true})
|
||||
@Column({ nullable: true })
|
||||
@IsOptional()
|
||||
@IsEmail()
|
||||
email?: string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Entity, Column, OneToMany, ManyToOne } from "typeorm";
|
||||
import { IsInt, IsNotEmpty,} from "class-validator";
|
||||
import { Entity, Column, OneToMany, ManyToOne, ChildEntity } from "typeorm";
|
||||
import { IsInt, IsNotEmpty, } from "class-validator";
|
||||
import { Participant } from "./Participant";
|
||||
import { RunnerGroup } from "./RunnerGroup";
|
||||
import { DistanceDonation } from "./DistanceDonation";
|
||||
@@ -9,7 +9,7 @@ import { Scan } from "./Scan";
|
||||
/**
|
||||
* Defines a runner.
|
||||
*/
|
||||
@Entity()
|
||||
@ChildEntity()
|
||||
export class Runner extends Participant {
|
||||
/**
|
||||
* The runner's associated group.
|
||||
@@ -17,7 +17,7 @@ export class Runner extends Participant {
|
||||
@IsNotEmpty()
|
||||
@ManyToOne(() => RunnerGroup, group => group.runners, { nullable: true })
|
||||
group: RunnerGroup;
|
||||
|
||||
|
||||
/**
|
||||
* Used to link runners to donations.
|
||||
*/
|
||||
@@ -36,9 +36,9 @@ export class Runner extends Participant {
|
||||
@OneToMany(() => Scan, scan => scan.runner, { nullable: true })
|
||||
scans: Scan[];
|
||||
|
||||
@IsInt()
|
||||
public get distance() : number {
|
||||
@IsInt()
|
||||
public get distance(): number {
|
||||
return this.scans.filter(scan => scan.valid === true).reduce((sum, current) => sum + current.distance, 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity } from "typeorm";
|
||||
import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity, TableInheritance } from "typeorm";
|
||||
import {
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
@@ -13,6 +13,7 @@ import { RunnerTeam } from "./RunnerTeam";
|
||||
* Defines the runnerGroup interface.
|
||||
*/
|
||||
@Entity()
|
||||
@TableInheritance({ column: { name: "type", type: "varchar" } })
|
||||
export abstract class RunnerGroup {
|
||||
/**
|
||||
* Autogenerated unique id (primary key).
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Entity, Column, ManyToOne, OneToMany } from "typeorm";
|
||||
import { IsOptional,} from "class-validator";
|
||||
import { Entity, Column, ManyToOne, OneToMany, ChildEntity } from "typeorm";
|
||||
import { IsOptional, } from "class-validator";
|
||||
import { RunnerGroup } from "./RunnerGroup";
|
||||
import { Address } from "./Address";
|
||||
import { RunnerTeam } from "./RunnerTeam";
|
||||
@@ -7,7 +7,7 @@ import { RunnerTeam } from "./RunnerTeam";
|
||||
/**
|
||||
* Defines a runner organisation (business or school for example).
|
||||
*/
|
||||
@Entity()
|
||||
@ChildEntity()
|
||||
export class RunnerOrganisation extends RunnerGroup {
|
||||
|
||||
/**
|
||||
@@ -18,9 +18,9 @@ export class RunnerOrganisation extends RunnerGroup {
|
||||
@ManyToOne(() => Address, address => address.groups, { nullable: true })
|
||||
address?: Address;
|
||||
|
||||
/**
|
||||
* Used to link teams to runner groups.
|
||||
*/
|
||||
/**
|
||||
* Used to link teams to runner groups.
|
||||
*/
|
||||
@OneToMany(() => RunnerTeam, team => team.parentGroup, { nullable: true })
|
||||
teams: RunnerTeam[];
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Entity, Column, ManyToOne } from "typeorm";
|
||||
import { Entity, Column, ManyToOne, ChildEntity } from "typeorm";
|
||||
import { IsNotEmpty } from "class-validator";
|
||||
import { RunnerGroup } from "./RunnerGroup";
|
||||
import { RunnerOrganisation } from "./RunnerOrganisation";
|
||||
@@ -6,7 +6,7 @@ import { RunnerOrganisation } from "./RunnerOrganisation";
|
||||
/**
|
||||
* Defines a runner team (class or deparment for example).
|
||||
*/
|
||||
@Entity()
|
||||
@ChildEntity()
|
||||
export class RunnerTeam extends RunnerGroup {
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PrimaryGeneratedColumn, Column, ManyToOne, Entity } from "typeorm";
|
||||
import { PrimaryGeneratedColumn, Column, ManyToOne, Entity, TableInheritance } from "typeorm";
|
||||
import {
|
||||
IsBoolean,
|
||||
IsInt,
|
||||
@@ -12,6 +12,7 @@ import { Runner } from "./Runner";
|
||||
* Defines the scan interface.
|
||||
*/
|
||||
@Entity()
|
||||
@TableInheritance({ column: { name: "type", type: "varchar" } })
|
||||
export abstract class Scan {
|
||||
/**
|
||||
* Autogenerated unique id (primary key).
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PrimaryGeneratedColumn, Column, ManyToOne, Entity } from "typeorm";
|
||||
import { PrimaryGeneratedColumn, Column, ManyToOne, Entity, ChildEntity } from "typeorm";
|
||||
import {
|
||||
IsBoolean,
|
||||
IsDateString,
|
||||
@@ -16,7 +16,7 @@ import { ScanStation } from "./ScanStation";
|
||||
/**
|
||||
* Defines the scan interface.
|
||||
*/
|
||||
@Entity()
|
||||
@ChildEntity()
|
||||
export class TrackScan extends Scan {
|
||||
/**
|
||||
* The associated track.
|
||||
|
||||
Reference in New Issue
Block a user