Implemented the second round of the toResponse normalisationf for all classes

ref #67
This commit is contained in:
Nicolai Ort 2021-01-03 19:18:31 +01:00
parent 58156e0d61
commit 2cad2ac2e9
12 changed files with 83 additions and 0 deletions

View File

@ -80,4 +80,11 @@ export class Address {
*/
@OneToMany(() => IAddressUser, addressUser => addressUser.address, { nullable: true })
addressUsers: IAddressUser[];
/**
* Turns this entity into it's response class.
*/
public toResponse() {
return new Error("NotImplemented");
}
}

View File

@ -39,4 +39,11 @@ export class DistanceDonation extends Donation {
}
return calculatedAmount;
}
/**
* Turns this entity into it's response class.
*/
public toResponse() {
return new Error("NotImplemented");
}
}

View File

@ -32,4 +32,11 @@ export abstract class Donation {
* The exact implementation may differ for each type of donation.
*/
abstract amount: number;
/**
* Turns this entity into it's response class.
*/
public toResponse() {
return new Error("NotImplemented");
}
}

View File

@ -1,5 +1,6 @@
import { IsBoolean } from "class-validator";
import { ChildEntity, Column, OneToMany } from "typeorm";
import { ResponseDonor } from '../responses/ResponseDonor';
import { Donation } from './Donation';
import { Participant } from "./Participant";
@ -22,4 +23,11 @@ export class Donor extends Participant {
*/
@OneToMany(() => Donation, donation => donation.donor, { nullable: true })
donations: Donation[];
/**
* Turns this entity into it's response class.
*/
public toResponse(): ResponseDonor {
return new ResponseDonor(this);
}
}

View File

@ -16,4 +16,11 @@ export class FixedDonation extends Donation {
@IsInt()
@IsPositive()
amount: number;
/**
* Turns this entity into it's response class.
*/
public toResponse() {
return new Error("NotImplemented");
}
}

View File

@ -81,4 +81,11 @@ export class GroupContact implements IAddressUser {
*/
@OneToMany(() => RunnerGroup, group => group.contact, { nullable: true })
groups: RunnerGroup[];
/**
* Turns this entity into it's response class.
*/
public toResponse() {
return new Error("NotImplemented");
}
}

View File

@ -12,4 +12,9 @@ export abstract class IAddressUser {
@ManyToOne(() => Address, address => address.addressUsers, { nullable: true })
address?: Address
/**
* Turns this entity into it's response class.
*/
public abstract toResponse();
}

View File

@ -9,6 +9,7 @@ import {
} from "class-validator";
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
import { config } from '../../config';
import { ResponseParticipant } from '../responses/ResponseParticipant';
import { Address } from "./Address";
import { IAddressUser } from './IAddressUser';
@ -74,4 +75,9 @@ export abstract class Participant implements IAddressUser {
@IsOptional()
@IsEmail()
email?: string;
/**
* Turns this entity into it's response class.
*/
public abstract toResponse(): ResponseParticipant;
}

View File

@ -6,6 +6,7 @@ import {
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
import { PermissionAction } from '../enums/PermissionAction';
import { PermissionTarget } from '../enums/PermissionTargets';
import { ResponsePermission } from '../responses/ResponsePermission';
import { Principal } from './Principal';
/**
* Defines the Permission entity.
@ -51,4 +52,11 @@ export class Permission {
public toString(): string {
return this.target + ":" + this.action;
}
/**
* Turns this entity into it's response class.
*/
public toResponse(): ResponsePermission {
return new ResponsePermission(this);
}
}

View File

@ -1,5 +1,6 @@
import { IsInt, IsNotEmpty } from "class-validator";
import { ChildEntity, ManyToOne, OneToMany } from "typeorm";
import { ResponseRunner } from '../responses/ResponseRunner';
import { DistanceDonation } from "./DistanceDonation";
import { Participant } from "./Participant";
import { RunnerCard } from "./RunnerCard";
@ -66,4 +67,11 @@ export class Runner extends Participant {
public get distanceDonationAmount(): number {
return this.distanceDonations.reduce((sum, current) => sum + current.amountPerDistance, 0) * this.distance;
}
/**
* Turns this entity into it's response class.
*/
public toResponse(): ResponseRunner {
return new ResponseRunner(this);
}
}

View File

@ -57,4 +57,11 @@ export class RunnerCard {
*/
@OneToMany(() => TrackScan, scan => scan.track, { nullable: true })
scans: TrackScan[];
/**
* Turns this entity into it's response class.
*/
public toResponse() {
return new Error("NotImplemented");
}
}

View File

@ -5,6 +5,7 @@ import {
IsString
} from "class-validator";
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
import { ResponseRunnerGroup } from '../responses/ResponseRunnerGroup';
import { GroupContact } from "./GroupContact";
import { Runner } from "./Runner";
@ -60,4 +61,9 @@ export abstract class RunnerGroup {
public get distanceDonationAmount(): number {
return this.runners.reduce((sum, current) => sum + current.distanceDonationAmount, 0);
}
/**
* Turns this entity into it's response class.
*/
public abstract toResponse(): ResponseRunnerGroup;
}