Cleaned up a load of relations and optional stuff

ref #11
This commit is contained in:
Nicolai Ort 2020-12-05 10:43:28 +01:00
parent 109e145a19
commit a1105f06ab
18 changed files with 50 additions and 80 deletions

View File

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

View File

@ -13,7 +13,7 @@ export class DistanceDonation extends Donation {
* The runner associated.
*/
@IsNotEmpty()
@ManyToOne(() => Runner, runner => runner.distanceDonations, { nullable: true })
@ManyToOne(() => Runner, runner => runner.distanceDonations)
runner: Runner;
/**

View File

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

View File

@ -1,5 +1,5 @@
import { Entity, Column, ChildEntity } from "typeorm";
import { IsBoolean } from "class-validator";
import { ChildEntity, Column } from "typeorm";
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";
/**

View File

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

View File

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

View File

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

View File

@ -15,7 +15,7 @@ export class Runner extends Participant {
* The runner's associated group.
*/
@IsNotEmpty()
@ManyToOne(() => RunnerGroup, group => group.runners, { nullable: true })
@ManyToOne(() => RunnerGroup, group => group.runners, { nullable: false })
group: RunnerGroup;
/**

View File

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

View File

@ -18,12 +18,11 @@ export abstract class RunnerGroup {
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
/**
* The group's first name.
* The group's name.
*/
@Column()
@IsNotEmpty()

View File

@ -15,7 +15,7 @@ export class RunnerTeam extends RunnerGroup {
* Optional
*/
@IsNotEmpty()
@ManyToOne(() => RunnerOrganisation, org => org.teams, { nullable: true })
@ManyToOne(() => RunnerOrganisation, org => org.teams, { nullable: false })
parentGroup?: RunnerOrganisation;
/**

View File

@ -1,11 +1,11 @@
import { PrimaryGeneratedColumn, Column, ManyToOne, Entity, TableInheritance } from "typeorm";
import {
IsBoolean,
IsInt,
IsNotEmpty,
IsOptional,
IsPositive,
IsPositive
} from "class-validator";
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
import { Runner } from "./Runner";
/**
@ -18,7 +18,6 @@ export abstract class Scan {
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
@ -26,7 +25,7 @@ export abstract class Scan {
* The associated runner.
*/
@IsNotEmpty()
@ManyToOne(() => Runner, runner => runner.scans, { nullable: true })
@ManyToOne(() => Runner, runner => runner.scans, { nullable: false })
runner: Runner;
/**
@ -43,12 +42,4 @@ export abstract class Scan {
@Column()
@IsBoolean()
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 {
IsBoolean,
IsInt,
IsNotEmpty,
IsOptional,
IsString,
IsString
} from "class-validator";
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { Track } from "./Track";
import { TrackScan } from "./TrackScan";
@ -18,14 +18,13 @@ export class ScanStation {
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
/**
* The station's description.
*/
@Column({nullable: true})
@Column({ nullable: true })
@IsOptional()
@IsString()
description?: string;
@ -34,7 +33,7 @@ export class ScanStation {
* The track this station is associated with.
*/
@IsNotEmpty()
@ManyToOne(() => Track, track => track.stations, { nullable: true })
@ManyToOne(() => Track, track => track.stations, { nullable: false })
track: Track;
/**

View File

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

View File

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

View File

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

View File

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