Compare commits

...

11 Commits

28 changed files with 255 additions and 236 deletions

View File

@ -1,7 +1,7 @@
import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers'; import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { getConnectionManager, Repository } from 'typeorm'; import { getConnectionManager, Repository } from 'typeorm';
import { EntityFromBody } from 'typeorm-routing-controllers-extensions'; import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
import { RunnerGroupNeededError, RunnerGroupNotFoundError, RunnerIdsNotMatchingError, RunnerNotFoundError, RunnerOnlyOneGroupAllowedError } from '../errors/RunnerErrors'; import { RunnerGroupNeededError, RunnerGroupNotFoundError, RunnerIdsNotMatchingError, RunnerNotFoundError, RunnerOnlyOneGroupAllowedError } from '../errors/RunnerErrors';
import { CreateRunner } from '../models/creation/CreateRunner'; import { CreateRunner } from '../models/creation/CreateRunner';
import { Runner } from '../models/entities/Runner'; import { Runner } from '../models/entities/Runner';
@ -55,7 +55,8 @@ export class RunnerController {
return error; return error;
} }
return new ResponseRunner(await this.runnerRepository.save(runner)); runner = await this.runnerRepository.save(runner)
return new ResponseRunner(await this.runnerRepository.findOne(runner, { relations: ['scans', 'group'] }));
} }
@Put('/:id') @Put('/:id')
@ -64,7 +65,7 @@ export class RunnerController {
@ResponseSchema(RunnerIdsNotMatchingError, { statusCode: 406 }) @ResponseSchema(RunnerIdsNotMatchingError, { statusCode: 406 })
@OpenAPI({ description: "Update a runner object (id can't be changed)." }) @OpenAPI({ description: "Update a runner object (id can't be changed)." })
async put(@Param('id') id: number, @EntityFromBody() runner: Runner) { async put(@Param('id') id: number, @EntityFromBody() runner: Runner) {
let oldRunner = await this.runnerRepository.findOne({ id: id }); let oldRunner = await this.runnerRepository.findOne({ id: id }, { relations: ['scans', 'group'] });
if (!oldRunner) { if (!oldRunner) {
throw new RunnerNotFoundError(); throw new RunnerNotFoundError();
@ -82,14 +83,15 @@ export class RunnerController {
@ResponseSchema(ResponseRunner) @ResponseSchema(ResponseRunner)
@ResponseSchema(RunnerNotFoundError, { statusCode: 404 }) @ResponseSchema(RunnerNotFoundError, { statusCode: 404 })
@OpenAPI({ description: 'Delete a specified runner (if it exists).' }) @OpenAPI({ description: 'Delete a specified runner (if it exists).' })
async remove(@Param('id') id: number, @QueryParam("force") force: boolean) { async remove(@EntityFromParam('id') runner: Runner, @QueryParam("force") force: boolean) {
let runner = await this.runnerRepository.findOne({ id: id }); if (!runner) { throw new RunnerNotFoundError(); }
const responseRunner = await this.runnerRepository.findOne(runner, { relations: ['scans', 'group'] });
if (!runner) { if (!runner) {
throw new RunnerNotFoundError(); throw new RunnerNotFoundError();
} }
await this.runnerRepository.delete(runner); await this.runnerRepository.delete(runner);
return new ResponseRunner(runner); return new ResponseRunner(responseRunner);
} }
} }

View File

@ -1,12 +1,10 @@
import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers'; import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { getConnectionManager, Repository } from 'typeorm'; import { getConnectionManager, Repository } from 'typeorm';
import { EntityFromBody } from 'typeorm-routing-controllers-extensions'; import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
import { RunnerOrganisationHasRunnersError, RunnerOrganisationHasTeamsError, RunnerOrganisationIdsNotMatchingError, RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors'; import { RunnerOrganisationHasRunnersError, RunnerOrganisationHasTeamsError, RunnerOrganisationIdsNotMatchingError, RunnerOrganisationNotFoundError } from '../errors/RunnerOrganisationErrors';
import { CreateRunnerOrganisation } from '../models/creation/CreateRunnerOrganisation'; import { CreateRunnerOrganisation } from '../models/creation/CreateRunnerOrganisation';
import { Runner } from '../models/entities/Runner';
import { RunnerOrganisation } from '../models/entities/RunnerOrganisation'; import { RunnerOrganisation } from '../models/entities/RunnerOrganisation';
import { RunnerTeam } from '../models/entities/RunnerTeam';
import { ResponseRunnerOrganisation } from '../models/responses/ResponseRunnerOrganisation'; import { ResponseRunnerOrganisation } from '../models/responses/ResponseRunnerOrganisation';
import { RunnerController } from './RunnerController'; import { RunnerController } from './RunnerController';
import { RunnerTeamController } from './RunnerTeamController'; import { RunnerTeamController } from './RunnerTeamController';
@ -58,9 +56,8 @@ export class RunnerOrganisationController {
} }
runnerOrganisation = await this.runnerOrganisationRepository.save(runnerOrganisation); runnerOrganisation = await this.runnerOrganisationRepository.save(runnerOrganisation);
runnerOrganisation = await this.runnerOrganisationRepository.findOne(runnerOrganisation, { relations: ['address', 'contact', 'teams'] });
return new ResponseRunnerOrganisation(runnerOrganisation); return new ResponseRunnerOrganisation(await this.runnerOrganisationRepository.findOne(runnerOrganisation, { relations: ['address', 'contact', 'teams'] }));
} }
@Put('/:id') @Put('/:id')
@ -88,39 +85,35 @@ export class RunnerOrganisationController {
@Delete('/:id') @Delete('/:id')
@ResponseSchema(ResponseRunnerOrganisation) @ResponseSchema(ResponseRunnerOrganisation)
@ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 }) @ResponseSchema(RunnerOrganisationNotFoundError, { statusCode: 404 })
@ResponseSchema(RunnerOrganisationHasTeamsError, { statusCode: 406 })
@ResponseSchema(RunnerOrganisationHasRunnersError, { statusCode: 406 }) @ResponseSchema(RunnerOrganisationHasRunnersError, { statusCode: 406 })
@OpenAPI({ description: 'Delete a specified runnerOrganisation (if it exists).' }) @OpenAPI({ description: 'Delete a specified runnerOrganisation (if it exists).' })
async remove(@Param('id') id: number, @QueryParam("force") force: boolean) { async remove(@EntityFromParam('id') organisation: RunnerOrganisation, @QueryParam("force") force: boolean) {
let runnerOrganisation = await this.runnerOrganisationRepository.findOne({ id: id }, { relations: ['address', 'contact', 'teams'] }); if (!organisation) { throw new RunnerOrganisationNotFoundError() }
let runnerOrganisation = await this.runnerOrganisationRepository.findOne(organisation, { relations: ['address', 'contact', 'runners', 'teams'] });
if (!runnerOrganisation) {
throw new RunnerOrganisationNotFoundError();
}
let runners: Runner[] = await runnerOrganisation.getRunners()
if (!force) { if (!force) {
if (runners.length != 0) { if (runnerOrganisation.teams.length != 0) {
throw new RunnerOrganisationHasRunnersError();
}
}
const runnerController = new RunnerController()
runners.forEach(runner => {
runnerController.remove(runner.id, true)
});
let teams: RunnerTeam[] = await runnerOrganisation.getTeams()
if (!force) {
if (teams.length != 0) {
throw new RunnerOrganisationHasTeamsError(); throw new RunnerOrganisationHasTeamsError();
} }
} }
const teamController = new RunnerTeamController() const teamController = new RunnerTeamController()
teams.forEach(team => { for (let team of runnerOrganisation.teams) {
teamController.remove(team.id, true) await teamController.remove(team, true);
}); }
if (!force) {
if (runnerOrganisation.runners.length != 0) {
throw new RunnerOrganisationHasRunnersError();
}
}
const runnerController = new RunnerController()
for (let runner of runnerOrganisation.runners) {
await runnerController.remove(runner, true);
}
const responseOrganisation = new ResponseRunnerOrganisation(runnerOrganisation); const responseOrganisation = new ResponseRunnerOrganisation(runnerOrganisation);
await this.runnerOrganisationRepository.delete({ id: runnerOrganisation.id }); await this.runnerOrganisationRepository.delete(organisation);
return responseOrganisation; return responseOrganisation;
} }
} }

View File

@ -1,10 +1,9 @@
import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers'; import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put, QueryParam } from 'routing-controllers';
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { getConnectionManager, Repository } from 'typeorm'; import { getConnectionManager, Repository } from 'typeorm';
import { EntityFromBody } from 'typeorm-routing-controllers-extensions'; import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
import { RunnerTeamHasRunnersError, RunnerTeamIdsNotMatchingError, RunnerTeamNotFoundError } from '../errors/RunnerTeamErrors'; import { RunnerTeamHasRunnersError, RunnerTeamIdsNotMatchingError, RunnerTeamNotFoundError } from '../errors/RunnerTeamErrors';
import { CreateRunnerTeam } from '../models/creation/CreateRunnerTeam'; import { CreateRunnerTeam } from '../models/creation/CreateRunnerTeam';
import { Runner } from '../models/entities/Runner';
import { RunnerTeam } from '../models/entities/RunnerTeam'; import { RunnerTeam } from '../models/entities/RunnerTeam';
import { ResponseRunnerTeam } from '../models/responses/ResponseRunnerTeam'; import { ResponseRunnerTeam } from '../models/responses/ResponseRunnerTeam';
import { RunnerController } from './RunnerController'; import { RunnerController } from './RunnerController';
@ -88,26 +87,22 @@ export class RunnerTeamController {
@ResponseSchema(RunnerTeamNotFoundError, { statusCode: 404 }) @ResponseSchema(RunnerTeamNotFoundError, { statusCode: 404 })
@ResponseSchema(RunnerTeamHasRunnersError, { statusCode: 406 }) @ResponseSchema(RunnerTeamHasRunnersError, { statusCode: 406 })
@OpenAPI({ description: 'Delete a specified runnerTeam (if it exists).' }) @OpenAPI({ description: 'Delete a specified runnerTeam (if it exists).' })
async remove(@Param('id') id: number, @QueryParam("force") force: boolean) { async remove(@EntityFromParam('id') team: RunnerTeam, @QueryParam("force") force: boolean) {
let runnerTeam = await this.runnerTeamRepository.findOne({ id: id }, { relations: ['parentGroup', 'contact'] }); if (!team) { throw new RunnerTeamNotFoundError(); }
let runnerTeam = await this.runnerTeamRepository.findOne(team, { relations: ['parentGroup', 'contact', 'runners'] });
if (!runnerTeam) {
throw new RunnerTeamNotFoundError();
}
let runners: Runner[] = await runnerTeam.getRunners()
if (!force) { if (!force) {
if (runners.length != 0) { if (runnerTeam.runners.length != 0) {
throw new RunnerTeamHasRunnersError(); throw new RunnerTeamHasRunnersError();
} }
} }
const runnerController = new RunnerController() const runnerController = new RunnerController()
runners.forEach(runner => { for (let runner of runnerTeam.runners) {
runnerController.remove(runner.id, true) await runnerController.remove(runner, true);
}); }
const responseTeam = new ResponseRunnerTeam(runnerTeam); const responseTeam = new ResponseRunnerTeam(runnerTeam);
await this.runnerTeamRepository.delete({ id: runnerTeam.id }); await this.runnerTeamRepository.delete(team);
return responseTeam; return responseTeam;
} }
} }

View File

@ -1,7 +1,7 @@
import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put } from 'routing-controllers'; import { Body, Delete, Get, JsonController, OnUndefined, Param, Post, Put } from 'routing-controllers';
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { getConnectionManager, Repository } from 'typeorm'; import { getConnectionManager, Repository } from 'typeorm';
import { EntityFromBody } from 'typeorm-routing-controllers-extensions'; import { EntityFromBody, EntityFromParam } from 'typeorm-routing-controllers-extensions';
import { TrackIdsNotMatchingError, TrackNotFoundError } from "../errors/TrackErrors"; import { TrackIdsNotMatchingError, TrackNotFoundError } from "../errors/TrackErrors";
import { CreateTrack } from '../models/creation/CreateTrack'; import { CreateTrack } from '../models/creation/CreateTrack';
import { Track } from '../models/entities/Track'; import { Track } from '../models/entities/Track';
@ -74,14 +74,10 @@ export class TrackController {
@ResponseSchema(ResponseTrack) @ResponseSchema(ResponseTrack)
@ResponseSchema(TrackNotFoundError, { statusCode: 404 }) @ResponseSchema(TrackNotFoundError, { statusCode: 404 })
@OpenAPI({ description: "Delete a specified track (if it exists)." }) @OpenAPI({ description: "Delete a specified track (if it exists)." })
async remove(@Param('id') id: number) { async remove(@EntityFromParam('id') track: Track) {
let track = await this.trackRepository.findOne({ id: id }); if (!track) { throw new TrackNotFoundError(); }
if (!track) {
throw new TrackNotFoundError();
}
await this.trackRepository.delete(track); await this.trackRepository.delete(track);
return new ResponseTrack(track); return new ResponseTrack(track);
} }
} }

View File

@ -0,0 +1,30 @@
import { IsNotEmpty, IsObject, IsOptional, IsString } from 'class-validator';
import { GroupContact } from '../entities/GroupContact';
export abstract class CreateRunnerGroup {
/**
* The group's name.
*/
@IsNotEmpty()
@IsString()
name: string;
/**
* The group's contact.
* Optional
*/
@IsObject()
@IsOptional()
contact?: GroupContact;
/**
* Deals with the contact for groups this.
*/
public async getContact(): Promise<GroupContact> {
let newGroupContact: GroupContact;
//TODO:
return newGroupContact;
}
}

View File

@ -1,13 +1,47 @@
import { IsNotEmpty, IsString } from 'class-validator'; import { IsInt, IsObject, IsOptional } from 'class-validator';
import { getConnectionManager } from 'typeorm';
import { ParticipantOnlyOneAddressAllowedError } from '../../errors/ParticipantErrors';
import { Address } from '../entities/Address';
import { RunnerOrganisation } from '../entities/RunnerOrganisation'; import { RunnerOrganisation } from '../entities/RunnerOrganisation';
import { CreateAddress } from './CreateAddress';
import { CreateRunnerGroup } from './CreateRunnerGroup';
export class CreateRunnerOrganisation { export class CreateRunnerOrganisation extends CreateRunnerGroup {
/** /**
* The Organisation's name. * The new participant's address's id.
* Optional - please provide either addressId or address.
*/ */
@IsString() @IsInt()
@IsNotEmpty() @IsOptional()
name: string; addressId?: number;
/**
* 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> {
let address: Address;
if (this.addressId !== undefined && this.address !== undefined) {
throw new ParticipantOnlyOneAddressAllowedError
}
if (this.addressId === undefined && this.address === undefined) {
return null;
}
if (this.addressId) {
return await getConnectionManager().get().getRepository(Address).findOne({ id: this.addressId });
}
return this.address.toAddress();
}
/** /**
* Creates a RunnerOrganisation entity from this. * Creates a RunnerOrganisation entity from this.
@ -16,6 +50,8 @@ export class CreateRunnerOrganisation {
let newRunnerOrganisation: RunnerOrganisation = new RunnerOrganisation(); let newRunnerOrganisation: RunnerOrganisation = new RunnerOrganisation();
newRunnerOrganisation.name = this.name; newRunnerOrganisation.name = this.name;
newRunnerOrganisation.contact = await this.getContact();
newRunnerOrganisation.address = await this.getAddress();
return newRunnerOrganisation; return newRunnerOrganisation;
} }

View File

@ -7,26 +7,71 @@ import { User } from '../entities/User';
import { UserGroup } from '../entities/UserGroup'; import { UserGroup } from '../entities/UserGroup';
export class CreateUser { export class CreateUser {
/**
* The new user's first name.
*/
@IsString() @IsString()
firstname: string; firstname: string;
/**
* The new user's middle name.
* Optinal.
*/
@IsString() @IsString()
@IsOptional()
middlename?: string; middlename?: string;
/**
* The new user's last name.
*/
@IsString()
lastname: string;
/**
* The new user's username.
* You have to provide at least one of: {email, username}.
*/
@IsOptional() @IsOptional()
@IsString() @IsString()
username?: string; username?: string;
/**
* The new user's email address.
* You have to provide at least one of: {email, username}.
*/
@IsEmail()
@IsString()
@IsOptional()
email?: string;
/**
* The new user's phone number.
* Optional
*/
@IsPhoneNumber("ZZ") @IsPhoneNumber("ZZ")
@IsOptional() @IsOptional()
phone?: string; phone?: string;
/**
* The new user's password.
* This will of course not be saved in plaintext :)
*/
@IsString() @IsString()
password: string; password: string;
@IsString()
lastname: string; /**
@IsEmail() * The new user's groups' id(s).
@IsString() * You can provide either one groupId or an array of groupIDs.
email?: string; * Optional.
*/
@IsOptional() @IsOptional()
groupId?: number[] | number groupId?: number[] | number
//TODO: ProfilePics
/**
* Converts this to a User Entity.
*/
public async toUser(): Promise<User> { public async toUser(): Promise<User> {
let newUser: User = new User(); let newUser: User = new User();
@ -58,17 +103,16 @@ export class CreateUser {
} }
} }
const new_uuid = uuid.v4()
newUser.email = this.email newUser.email = this.email
newUser.username = this.username newUser.username = this.username
newUser.firstname = this.firstname newUser.firstname = this.firstname
newUser.middlename = this.middlename newUser.middlename = this.middlename
newUser.lastname = this.lastname newUser.lastname = this.lastname
newUser.uuid = new_uuid newUser.uuid = uuid.v4()
newUser.password = await argon2.hash(this.password + new_uuid); newUser.phone = this.phone
newUser.password = await argon2.hash(this.password + newUser.uuid);
//TODO: ProfilePics
console.log(newUser)
return newUser; return newUser;
} }
} }

View File

@ -1,28 +1,30 @@
import { IsOptional, IsString } from 'class-validator'; import { IsOptional, IsString } from 'class-validator';
import { GroupNameNeededError } from '../../errors/UserGroupErrors';
import { UserGroup } from '../entities/UserGroup'; import { UserGroup } from '../entities/UserGroup';
export class CreateUserGroup { export class CreateUserGroup {
@IsOptional() /**
* The new group's name.
*/
@IsString() @IsString()
name: string; name: string;
/**
* The new group's description.
* Optinal.
*/
@IsOptional() @IsOptional()
@IsString() @IsString()
description?: string; description?: string;
/**
* Converts this to a UserGroup entity.
*/
public async toUserGroup(): Promise<UserGroup> { public async toUserGroup(): Promise<UserGroup> {
let newUserGroup: UserGroup = new UserGroup(); let newUserGroup: UserGroup = new UserGroup();
if (this.name === undefined) { newUserGroup.name = this.name;
throw new GroupNameNeededError(); newUserGroup.description = this.description;
}
newUserGroup.name = this.name
if (this.description) {
newUserGroup.description = this.description
}
console.log(newUserGroup)
return newUserGroup; return newUserGroup;
} }
} }

View File

@ -1,11 +1,11 @@
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from "typeorm";
import { import {
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
IsOptional, IsOptional,
IsPostalCode, IsPostalCode,
IsString, IsString
} from "class-validator"; } from "class-validator";
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { Participant } from "./Participant"; import { Participant } from "./Participant";
import { RunnerOrganisation } from "./RunnerOrganisation"; import { RunnerOrganisation } from "./RunnerOrganisation";
@ -18,14 +18,13 @@ export class Address {
* Autogenerated unique id (primary key). * Autogenerated unique id (primary key).
*/ */
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
@IsOptional()
@IsInt() @IsInt()
id: number; id: number;
/** /**
* The address's description. * The address's description.
*/ */
@Column({nullable: true}) @Column({ nullable: true })
@IsString() @IsString()
@IsOptional() @IsOptional()
description?: string; description?: string;
@ -43,7 +42,7 @@ export class Address {
* The address's second line. * The address's second line.
* Containing optional information. * Containing optional information.
*/ */
@Column({nullable: true}) @Column({ nullable: true })
@IsString() @IsString()
@IsOptional() @IsOptional()
address2?: string; address2?: string;

View File

@ -13,7 +13,7 @@ export class DistanceDonation extends Donation {
* The runner associated. * The runner associated.
*/ */
@IsNotEmpty() @IsNotEmpty()
@ManyToOne(() => Runner, runner => runner.distanceDonations, { nullable: true }) @ManyToOne(() => Runner, runner => runner.distanceDonations)
runner: Runner; runner: Runner;
/** /**
@ -28,18 +28,10 @@ export class DistanceDonation extends Donation {
* The donation's amount in cents (or whatever your currency's smallest unit is.). * The donation's amount in cents (or whatever your currency's smallest unit is.).
* The exact implementation may differ for each type of donation. * The exact implementation may differ for each type of donation.
*/ */
@IsInt() public get amount(): number {
public get amount() {
return this.getAmount();
}
/**
* The function that calculates the amount based on the runner object's distance.
*/
public async getAmount(): Promise<number> {
let calculatedAmount = -1; let calculatedAmount = -1;
try { try {
calculatedAmount = this.amountPerDistance * await this.runner.distance(); calculatedAmount = this.amountPerDistance * this.runner.distance;
} catch (error) { } catch (error) {
throw error; throw error;
} }

View File

@ -1,7 +1,6 @@
import { import {
IsInt, IsInt,
IsNotEmpty, IsNotEmpty
IsOptional
} from "class-validator"; } from "class-validator";
import { Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm"; import { Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
import { Participant } from "./Participant"; import { Participant } from "./Participant";
@ -16,7 +15,6 @@ export abstract class Donation {
* Autogenerated unique id (primary key). * Autogenerated unique id (primary key).
*/ */
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
@IsOptional()
@IsInt() @IsInt()
id: number; id: number;
@ -24,7 +22,7 @@ export abstract class Donation {
* The donations's donor. * The donations's donor.
*/ */
@IsNotEmpty() @IsNotEmpty()
@ManyToOne(() => Participant, donor => donor.donations, { nullable: true }) @ManyToOne(() => Participant, donor => donor.donations)
donor: Participant; donor: Participant;
/** /**

View File

@ -1,5 +1,5 @@
import { Entity, Column, ChildEntity } from "typeorm";
import { IsBoolean } from "class-validator"; import { IsBoolean } from "class-validator";
import { ChildEntity, Column } from "typeorm";
import { Participant } from "./Participant"; import { Participant } from "./Participant";
/** /**

View File

@ -1,5 +1,5 @@
import { Entity, Column, ChildEntity } from "typeorm"; import { IsInt, IsPositive } from "class-validator";
import { IsInt, IsPositive, } from "class-validator"; import { ChildEntity, Column } from "typeorm";
import { Donation } from "./Donation"; import { Donation } from "./Donation";
/** /**

View File

@ -1,15 +1,14 @@
import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity } from "typeorm";
import { import {
IsEmail, IsEmail,
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
IsOptional, IsOptional,
IsPhoneNumber, IsPhoneNumber,
IsPositive,
IsString, IsString
} from "class-validator"; } from "class-validator";
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { Address } from "./Address"; import { Address } from "./Address";
import { Donation } from "./Donation";
import { RunnerGroup } from "./RunnerGroup"; import { RunnerGroup } from "./RunnerGroup";
/** /**
@ -17,11 +16,10 @@ import { RunnerGroup } from "./RunnerGroup";
*/ */
@Entity() @Entity()
export class GroupContact { export class GroupContact {
/** /**
* Autogenerated unique id (primary key). * Autogenerated unique id (primary key).
*/ */
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
@IsOptional()
@IsInt() @IsInt()
id: number; id: number;
@ -37,7 +35,7 @@ export class GroupContact {
* The contact's middle name. * The contact's middle name.
* Optional * Optional
*/ */
@Column({nullable: true}) @Column({ nullable: true })
@IsOptional() @IsOptional()
@IsString() @IsString()
middlename?: string; middlename?: string;
@ -62,7 +60,7 @@ export class GroupContact {
* The contact's phone number. * The contact's phone number.
* Optional * Optional
*/ */
@Column({nullable: true}) @Column({ nullable: true })
@IsOptional() @IsOptional()
@IsPhoneNumber("DE") @IsPhoneNumber("DE")
phone?: string; phone?: string;
@ -71,19 +69,13 @@ export class GroupContact {
* The contact's email address. * The contact's email address.
* Optional * Optional
*/ */
@Column({nullable: true}) @Column({ nullable: true })
@IsOptional() @IsOptional()
@IsEmail() @IsEmail()
email?: string; email?: string;
/** /**
* Used to link the contact as the donor of a donation. * Used to link contacts to groups.
*/
@OneToMany(() => Donation, donation => donation.donor, { nullable: true })
donations: Donation[];
/**
* Used to link runners to donations.
*/ */
@OneToMany(() => RunnerGroup, group => group.contact, { nullable: true }) @OneToMany(() => RunnerGroup, group => group.contact, { nullable: true })
groups: RunnerGroup[]; groups: RunnerGroup[];

View File

@ -1,13 +1,13 @@
import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity, TableInheritance } from "typeorm";
import { import {
IsEmail, IsEmail,
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
IsOptional, IsOptional,
IsPhoneNumber, IsPhoneNumber,
IsPositive,
IsString, IsString
} from "class-validator"; } from "class-validator";
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
import { Address } from "./Address"; import { Address } from "./Address";
import { Donation } from "./Donation"; import { Donation } from "./Donation";
@ -21,7 +21,6 @@ export abstract class Participant {
* Autogenerated unique id (primary key). * Autogenerated unique id (primary key).
*/ */
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
@IsOptional()
@IsInt() @IsInt()
id: number; id: number;

View File

@ -1,10 +1,10 @@
import { PrimaryGeneratedColumn, Column, OneToMany, Entity, ManyToOne } from "typeorm";
import { import {
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
IsOptional,
IsString, IsString
} from "class-validator"; } from "class-validator";
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { User } from './User'; import { User } from './User';
import { UserGroup } from './UserGroup'; import { UserGroup } from './UserGroup';
/** /**
@ -16,7 +16,6 @@ export abstract class Permission {
* Autogenerated unique id (primary key). * Autogenerated unique id (primary key).
*/ */
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
@IsOptional()
@IsInt() @IsInt()
id: number; id: number;

View File

@ -1,5 +1,5 @@
import { IsInt, IsNotEmpty } from "class-validator"; import { IsInt, IsNotEmpty } from "class-validator";
import { ChildEntity, getConnectionManager, ManyToOne, OneToMany } from "typeorm"; import { ChildEntity, ManyToOne, OneToMany } from "typeorm";
import { DistanceDonation } from "./DistanceDonation"; import { DistanceDonation } from "./DistanceDonation";
import { Participant } from "./Participant"; import { Participant } from "./Participant";
import { RunnerCard } from "./RunnerCard"; import { RunnerCard } from "./RunnerCard";
@ -15,7 +15,7 @@ export class Runner extends Participant {
* The runner's associated group. * The runner's associated group.
*/ */
@IsNotEmpty() @IsNotEmpty()
@ManyToOne(() => RunnerGroup, group => group.runners, { nullable: true }) @ManyToOne(() => RunnerGroup, group => group.runners, { nullable: false })
group: RunnerGroup; group: RunnerGroup;
/** /**
@ -36,25 +36,18 @@ export class Runner extends Participant {
@OneToMany(() => Scan, scan => scan.runner, { nullable: true }) @OneToMany(() => Scan, scan => scan.runner, { nullable: true })
scans: Scan[]; scans: Scan[];
/**
* Returns all scans associated with this runner.
*/
public async getScans(): Promise<Scan[]> {
return await getConnectionManager().get().getRepository(Scan).find({ runner: this });
}
/** /**
* Returns all valid scans associated with this runner. * Returns all valid scans associated with this runner.
*/ */
public async getValidScans(): Promise<Scan[]> { public get validScans(): Scan[] {
return (await this.getScans()).filter(scan => { scan.valid === true }); return this.scans.filter(scan => { scan.valid === true });
} }
/** /**
* Returns the total distance ran by this runner. * Returns the total distance ran by this runner.
*/ */
@IsInt() @IsInt()
public async distance(): Promise<number> { public get distance(): number {
return await (await this.getValidScans()).reduce((sum, current) => sum + current.distance, 0); return this.validScans.reduce((sum, current) => sum + current.distance, 0);
} }
} }

View File

@ -1,12 +1,12 @@
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany } from "typeorm";
import { import {
IsBoolean, IsBoolean,
IsEAN, IsEAN,
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
IsOptional, IsOptional,
IsString, IsString
} from "class-validator"; } from "class-validator";
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { Runner } from "./Runner"; import { Runner } from "./Runner";
import { TrackScan } from "./TrackScan"; import { TrackScan } from "./TrackScan";
@ -19,7 +19,6 @@ export class RunnerCard {
* Autogenerated unique id (primary key). * Autogenerated unique id (primary key).
*/ */
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
@IsOptional()
@IsInt() @IsInt()
id: number; id: number;

View File

@ -18,12 +18,11 @@ export abstract class RunnerGroup {
* Autogenerated unique id (primary key). * Autogenerated unique id (primary key).
*/ */
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
@IsOptional()
@IsInt() @IsInt()
id: number; id: number;
/** /**
* The group's first name. * The group's name.
*/ */
@Column() @Column()
@IsNotEmpty() @IsNotEmpty()
@ -43,6 +42,4 @@ export abstract class RunnerGroup {
*/ */
@OneToMany(() => Runner, runner => runner.group, { nullable: true }) @OneToMany(() => Runner, runner => runner.group, { nullable: true })
runners: Runner[]; runners: Runner[];
public abstract getRunners();
} }

View File

@ -1,7 +1,6 @@
import { IsOptional } from "class-validator"; import { IsOptional } from "class-validator";
import { ChildEntity, getConnectionManager, ManyToOne, OneToMany } from "typeorm"; import { ChildEntity, ManyToOne, OneToMany } from "typeorm";
import { Address } from "./Address"; import { Address } from "./Address";
import { Runner } from './Runner';
import { RunnerGroup } from "./RunnerGroup"; import { RunnerGroup } from "./RunnerGroup";
import { RunnerTeam } from "./RunnerTeam"; import { RunnerTeam } from "./RunnerTeam";
@ -24,27 +23,4 @@ export class RunnerOrganisation extends RunnerGroup {
*/ */
@OneToMany(() => RunnerTeam, team => team.parentGroup, { nullable: true }) @OneToMany(() => RunnerTeam, team => team.parentGroup, { nullable: true })
teams: RunnerTeam[]; teams: RunnerTeam[];
/**
* Returns all runners associated with this organisation or it's teams.
*/
public async getRunners() {
let runners: Runner[] = new Array<Runner>();
const teams = await this.getTeams();
await teams.forEach(async team => {
runners.push(... await team.getRunners());
});
await runners.push(... await getConnectionManager().get().getRepository(Runner).find({ group: this }));
return runners;
}
/**
* Returns all teams associated with this organisation.
*/
public async getTeams() {
return await getConnectionManager().get().getRepository(RunnerTeam).find({ parentGroup: this });
}
} }

View File

@ -1,6 +1,5 @@
import { IsNotEmpty } from "class-validator"; import { IsNotEmpty } from "class-validator";
import { ChildEntity, getConnectionManager, ManyToOne } from "typeorm"; import { ChildEntity, ManyToOne } from "typeorm";
import { Runner } from './Runner';
import { RunnerGroup } from "./RunnerGroup"; import { RunnerGroup } from "./RunnerGroup";
import { RunnerOrganisation } from "./RunnerOrganisation"; import { RunnerOrganisation } from "./RunnerOrganisation";
@ -17,11 +16,4 @@ export class RunnerTeam extends RunnerGroup {
@IsNotEmpty() @IsNotEmpty()
@ManyToOne(() => RunnerOrganisation, org => org.teams, { nullable: true }) @ManyToOne(() => RunnerOrganisation, org => org.teams, { nullable: true })
parentGroup?: RunnerOrganisation; parentGroup?: RunnerOrganisation;
/**
* Returns all runners associated with this team.
*/
public async getRunners() {
return await getConnectionManager().get().getRepository(Runner).find({ group: this });
}
} }

View File

@ -1,11 +1,11 @@
import { PrimaryGeneratedColumn, Column, ManyToOne, Entity, TableInheritance } from "typeorm";
import { import {
IsBoolean, IsBoolean,
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
IsOptional,
IsPositive, IsPositive
} from "class-validator"; } from "class-validator";
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
import { Runner } from "./Runner"; import { Runner } from "./Runner";
/** /**
@ -18,7 +18,6 @@ export abstract class Scan {
* Autogenerated unique id (primary key). * Autogenerated unique id (primary key).
*/ */
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
@IsOptional()
@IsInt() @IsInt()
id: number; id: number;
@ -26,7 +25,7 @@ export abstract class Scan {
* The associated runner. * The associated runner.
*/ */
@IsNotEmpty() @IsNotEmpty()
@ManyToOne(() => Runner, runner => runner.scans, { nullable: true }) @ManyToOne(() => Runner, runner => runner.scans, { nullable: false })
runner: Runner; runner: Runner;
/** /**
@ -43,12 +42,4 @@ export abstract class Scan {
@Column() @Column()
@IsBoolean() @IsBoolean()
valid: boolean = true; valid: boolean = true;
}
/**
* seconds since last scan
*/
@IsInt()
@IsOptional()
secondsSinceLastScan: number;
}

View File

@ -1,11 +1,11 @@
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany } from "typeorm";
import { import {
IsBoolean, IsBoolean,
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
IsOptional, IsOptional,
IsString, IsString
} from "class-validator"; } from "class-validator";
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { Track } from "./Track"; import { Track } from "./Track";
import { TrackScan } from "./TrackScan"; import { TrackScan } from "./TrackScan";
@ -18,14 +18,13 @@ export class ScanStation {
* Autogenerated unique id (primary key). * Autogenerated unique id (primary key).
*/ */
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
@IsOptional()
@IsInt() @IsInt()
id: number; id: number;
/** /**
* The station's description. * The station's description.
*/ */
@Column({nullable: true}) @Column({ nullable: true })
@IsOptional() @IsOptional()
@IsString() @IsString()
description?: string; description?: string;
@ -34,7 +33,7 @@ export class ScanStation {
* The track this station is associated with. * The track this station is associated with.
*/ */
@IsNotEmpty() @IsNotEmpty()
@ManyToOne(() => Track, track => track.stations, { nullable: true }) @ManyToOne(() => Track, track => track.stations, { nullable: false })
track: Track; track: Track;
/** /**

View File

@ -1,11 +1,11 @@
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from "typeorm";
import { import {
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
IsOptional,
IsPositive, IsPositive,
IsString, IsString
} from "class-validator"; } from "class-validator";
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { ScanStation } from "./ScanStation"; import { ScanStation } from "./ScanStation";
import { TrackScan } from "./TrackScan"; import { TrackScan } from "./TrackScan";
@ -18,7 +18,6 @@ export class Track {
* Autogenerated unique id (primary key). * Autogenerated unique id (primary key).
*/ */
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
@IsOptional()
@IsInt() @IsInt()
id: number;; id: number;;

View File

@ -1,17 +1,15 @@
import { PrimaryGeneratedColumn, Column, ManyToOne, Entity, ChildEntity } from "typeorm";
import { import {
IsBoolean,
IsDateString, IsDateString,
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
IsOptional,
IsPositive, IsPositive
} from "class-validator"; } from "class-validator";
import { Scan } from "./Scan"; import { ChildEntity, Column, ManyToOne } from "typeorm";
import { Runner } from "./Runner";
import { Track } from "./Track";
import { RunnerCard } from "./RunnerCard"; import { RunnerCard } from "./RunnerCard";
import { Scan } from "./Scan";
import { ScanStation } from "./ScanStation"; import { ScanStation } from "./ScanStation";
import { Track } from "./Track";
/** /**
* Defines the scan interface. * Defines the scan interface.

View File

@ -13,7 +13,6 @@ export class User {
* autogenerated unique id (primary key). * autogenerated unique id (primary key).
*/ */
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
@IsOptional()
@IsInt() @IsInt()
id: number; id: number;
@ -21,30 +20,30 @@ export class User {
* uuid * uuid
*/ */
@Column() @Column()
@IsUUID("4") @IsUUID(4)
uuid: string; uuid: string;
/** /**
* user email * user email
*/ */
@Column() @Column({ nullable: true })
@IsEmail() @IsEmail()
email: string; email?: string;
/** /**
* user phone * user phone
*/ */
@Column() @Column({ nullable: true })
@IsPhoneNumber("ZZ")
@IsOptional() @IsOptional()
phone: string; @IsPhoneNumber("ZZ")
phone?: string;
/** /**
* username * username
*/ */
@Column() @Column({ nullable: true })
@IsString() @IsString()
username: string; username?: string;
/** /**
* firstname * firstname
@ -57,10 +56,10 @@ export class User {
/** /**
* middlename * middlename
*/ */
@Column() @Column({ nullable: true })
@IsString() @IsString()
@IsOptional() @IsOptional()
middlename: string; middlename?: string;
/** /**
* lastname * lastname
@ -83,7 +82,7 @@ export class User {
*/ */
@IsOptional() @IsOptional()
@ManyToOne(() => Permission, permission => permission.users, { nullable: true }) @ManyToOne(() => Permission, permission => permission.users, { nullable: true })
permissions: Permission[]; permissions?: Permission[];
/** /**
* groups * groups
@ -105,21 +104,22 @@ export class User {
*/ */
@IsInt() @IsInt()
@Column({ default: 1 }) @Column({ default: 1 })
refreshTokenCount: number; refreshTokenCount?: number;
/** /**
* profilepic * profilepic
*/ */
@Column() @Column({ nullable: true })
@IsString() @IsString()
profilePic: string; @IsOptional()
profilePic?: string;
/** /**
* actions * actions
*/ */
@IsOptional() @IsOptional()
@OneToMany(() => UserAction, action => action.user, { nullable: true }) @OneToMany(() => UserAction, action => action.user, { nullable: true })
actions: UserAction actions: UserAction[]
/** /**
* calculate all permissions * calculate all permissions

View File

@ -1,10 +1,10 @@
import { PrimaryGeneratedColumn, Column, OneToMany, Entity, ManyToOne } from "typeorm";
import { import {
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
IsOptional, IsOptional,
IsString, IsString
} from "class-validator"; } from "class-validator";
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
import { User } from './User'; import { User } from './User';
/** /**
@ -16,7 +16,6 @@ export class UserAction {
* Autogenerated unique id (primary key). * Autogenerated unique id (primary key).
*/ */
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
@IsOptional()
@IsInt() @IsInt()
id: number; id: number;

View File

@ -16,7 +16,6 @@ export class UserGroup {
* Autogenerated unique id (primary key). * Autogenerated unique id (primary key).
*/ */
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
@IsOptional()
@IsInt() @IsInt()
id: number; id: number;