Compare commits

..

No commits in common. "a86465c554576ff6afdcf552933b097542df5423" and "3ade01def931fbb7feb1a1fe8b8b8e29a22b0a58" have entirely different histories.

18 changed files with 144 additions and 162 deletions

View File

@ -76,12 +76,12 @@ export class Address {
/** /**
* Used to link the address to participants. * Used to link the address to participants.
*/ */
@OneToMany(() => Participant, participant => participant.address, { nullable: true }) @OneToMany(() => Participant, participant => participant.address)
participants: Participant[]; participants: Participant[];
/** /**
* Used to link the address to runner groups. * Used to link the address to runner groups.
*/ */
@OneToMany(() => RunnerOrganisation, group => group.address, { nullable: true }) @OneToMany(() => RunnerOrganisation, group => group.address)
groups: RunnerOrganisation[]; groups: RunnerOrganisation[];
} }

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;
/** /**

View File

@ -24,7 +24,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

@ -55,7 +55,7 @@ export class GroupContact {
* Optional * Optional
*/ */
@IsOptional() @IsOptional()
@ManyToOne(() => Address, address => address.participants, { nullable: true }) @ManyToOne(() => Address, address => address.participants)
address?: Address; address?: Address;
/** /**
@ -79,12 +79,12 @@ export class GroupContact {
/** /**
* Used to link the contact as the donor of a donation. * Used to link the contact as the donor of a donation.
*/ */
@OneToMany(() => Donation, donation => donation.donor, { nullable: true }) @OneToMany(() => Donation, donation => donation.donor)
donations: Donation[]; donations: Donation[];
/** /**
* Used to link runners to donations. * Used to link runners to donations.
*/ */
@OneToMany(() => RunnerGroup, group => group.contact, { nullable: true }) @OneToMany(() => RunnerGroup, group => group.contact)
groups: RunnerGroup[]; groups: RunnerGroup[];
} }

View File

@ -53,7 +53,7 @@ export abstract class Participant {
* The participant's address. * The participant's address.
* Optional * Optional
*/ */
@ManyToOne(() => Address, address => address.participants, { nullable: true }) @ManyToOne(() => Address, address => address.participants)
address?: Address; address?: Address;
/** /**
@ -77,6 +77,6 @@ export abstract class Participant {
/** /**
* Used to link the participant as the donor of a donation. * Used to link the participant as the donor of a donation.
*/ */
@OneToMany(() => Donation, donation => donation.donor, { nullable: true }) @OneToMany(() => Donation, donation => donation.donor)
donations: Donation[]; donations: Donation[];
} }

View File

@ -23,13 +23,13 @@ export abstract class Permission {
/** /**
* users * users
*/ */
@OneToMany(() => User, user => user.permissions, { nullable: true }) @OneToMany(() => User, user => user.permissions)
users: User[] users: User[]
/** /**
* groups * groups
*/ */
@OneToMany(() => UserGroup, group => group.permissions, { nullable: true }) @OneToMany(() => UserGroup, group => group.permissions)
groups: UserGroup[] groups: UserGroup[]
/** /**

View File

@ -15,25 +15,25 @@ 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)
group: RunnerGroup; group: RunnerGroup;
/** /**
* Used to link runners to donations. * Used to link runners to donations.
*/ */
@OneToMany(() => DistanceDonation, distanceDonation => distanceDonation.runner, { nullable: true }) @OneToMany(() => DistanceDonation, distanceDonation => distanceDonation.runner)
distanceDonations: DistanceDonation[]; distanceDonations: DistanceDonation[];
/** /**
* Used to link runners to cards. * Used to link runners to cards.
*/ */
@OneToMany(() => RunnerCard, card => card.runner, { nullable: true }) @OneToMany(() => RunnerCard, card => card.runner)
cards: RunnerCard[]; cards: RunnerCard[];
/** /**
* Used to link runners to a scans * Used to link runners to a scans
*/ */
@OneToMany(() => Scan, scan => scan.runner, { nullable: true }) @OneToMany(() => Scan, scan => scan.runner)
scans: Scan[]; scans: Scan[];
@IsInt() @IsInt()

View File

@ -26,7 +26,7 @@ export class RunnerCard {
* The runner that is currently associated with this card. * The runner that is currently associated with this card.
*/ */
@IsOptional() @IsOptional()
@ManyToOne(() => Runner, runner => runner.cards, { nullable: true }) @ManyToOne(() => Runner, runner => runner.cards)
runner: Runner; runner: Runner;
/** /**
@ -51,6 +51,6 @@ export class RunnerCard {
/** /**
* Used to link cards to a track scans. * Used to link cards to a track scans.
*/ */
@OneToMany(() => TrackScan, scan => scan.track, { nullable: true }) @OneToMany(() => TrackScan, scan => scan.track)
scans: TrackScan[]; scans: TrackScan[];
} }

View File

@ -35,12 +35,12 @@ export abstract class RunnerGroup {
* Optional * Optional
*/ */
@IsOptional() @IsOptional()
@ManyToOne(() => GroupContact, contact => contact.groups, { nullable: true }) @ManyToOne(() => GroupContact, contact => contact.groups)
contact?: GroupContact; contact?: GroupContact;
/** /**
* Used to link runners to a runner group. * Used to link runners to a runner group.
*/ */
@OneToMany(() => Runner, runner => runner.group, { nullable: true }) @OneToMany(() => Runner, runner => runner.group)
runners: Runner[]; runners: Runner[];
} }

View File

@ -15,12 +15,12 @@ export class RunnerOrganisation extends RunnerGroup {
* Optional * Optional
*/ */
@IsOptional() @IsOptional()
@ManyToOne(() => Address, address => address.groups, { nullable: true }) @ManyToOne(() => Address, address => address.groups)
address?: Address; address?: Address;
/** /**
* Used to link teams to runner groups. * Used to link teams to runner groups.
*/ */
@OneToMany(() => RunnerTeam, team => team.parentGroup, { nullable: true }) @OneToMany(() => RunnerTeam, team => team.parentGroup)
teams: RunnerTeam[]; teams: RunnerTeam[];
} }

View File

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

View File

@ -25,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)
runner: Runner; runner: Runner;
/** /**

View File

@ -34,7 +34,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)
track: Track; track: Track;
/** /**
@ -56,6 +56,6 @@ export class ScanStation {
/** /**
* Used to link track scans to a scan station. * Used to link track scans to a scan station.
*/ */
@OneToMany(() => TrackScan, scan => scan.track, { nullable: true }) @OneToMany(() => TrackScan, scan => scan.track)
scans: TrackScan[]; scans: TrackScan[];
} }

View File

@ -41,12 +41,12 @@ export class Track {
/** /**
* Used to link scan stations to track. * Used to link scan stations to track.
*/ */
@OneToMany(() => ScanStation, station => station.track, { nullable: true }) @OneToMany(() => ScanStation, station => station.track)
stations: ScanStation[]; stations: ScanStation[];
/** /**
* Used to link track scans to a track. * Used to link track scans to a track.
*/ */
@OneToMany(() => TrackScan, scan => scan.track, { nullable: true }) @OneToMany(() => TrackScan, scan => scan.track)
scans: TrackScan[]; scans: TrackScan[];
} }

View File

@ -22,21 +22,21 @@ export class TrackScan extends Scan {
* The associated track. * The associated track.
*/ */
@IsNotEmpty() @IsNotEmpty()
@ManyToOne(() => Track, track => track.scans, { nullable: true }) @ManyToOne(() => Track, track => track.scans)
track: Track; track: Track;
/** /**
* The associated card. * The associated card.
*/ */
@IsNotEmpty() @IsNotEmpty()
@ManyToOne(() => RunnerCard, card => card.scans, { nullable: true }) @ManyToOne(() => RunnerCard, card => card.scans)
card: RunnerCard; card: RunnerCard;
/** /**
* The scanning station. * The scanning station.
*/ */
@IsNotEmpty() @IsNotEmpty()
@ManyToOne(() => ScanStation, station => station.scans, { nullable: true }) @ManyToOne(() => ScanStation, station => station.scans)
station: ScanStation; station: ScanStation;
/** /**

View File

@ -1,123 +1,109 @@
import { Entity, Column, OneToMany, ManyToOne, PrimaryGeneratedColumn, Generated, Unique, JoinTable, ManyToMany } from "typeorm"; import { Entity, Column, OneToMany, ManyToOne, PrimaryGeneratedColumn, Generated, Unique, JoinTable, ManyToMany } from "typeorm";
import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsString, isUUID, } from "class-validator"; import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsString, isUUID, } from "class-validator";
import { UserGroup } from './UserGroup'; import { UserGroup } from './UserGroup';
import { Permission } from './Permission'; import { Permission } from './Permission';
import { UserAction } from './UserAction';
/**
/** * Defines a admin user.
* Defines a admin user. */
*/ @Entity()
@Entity() export class User {
export class User { /**
/** * autogenerated unique id (primary key).
* autogenerated unique id (primary key). */
*/ @PrimaryGeneratedColumn()
@PrimaryGeneratedColumn() @IsOptional()
@IsOptional() @IsInt()
@IsInt() id: number;
id: number;
/**
/** * autogenerated uuid
* autogenerated uuid */
*/ @IsOptional()
@IsOptional() @IsInt()
@IsInt() @Generated("uuid")
@Generated("uuid") uuid: string;
uuid: string;
/**
/** * user email
* user email */
*/ @IsEmail()
@IsEmail() email: string;
email: string;
/**
/** * username
* username */
*/ @IsString()
@IsString() username: string;
username: string;
/**
/** * firstname
* firstname */
*/ @IsString()
@IsString() @IsNotEmpty()
@IsNotEmpty() firstname: string;
firstname: string;
/**
/** * middlename
* middlename */
*/ @IsString()
@IsString() @IsOptional()
@IsOptional() middlename: string;
middlename: string;
/**
/** * lastname
* lastname */
*/ @IsString()
@IsString() @IsNotEmpty()
@IsNotEmpty() lastname: string;
lastname: string;
/**
/** * password
* password */
*/ @IsString()
@IsString() @IsNotEmpty()
@IsNotEmpty() password: string;
password: string;
/**
/** * permissions
* permissions */
*/ @ManyToOne(() => Permission, permission => permission.users)
@ManyToOne(() => Permission, permission => permission.users, { nullable: true }) permissions: Permission[];
permissions: Permission[];
/**
/** * groups
* groups */
*/ @ManyToMany(() => UserGroup)
@ManyToMany(() => UserGroup) @JoinTable()
@JoinTable() groups: UserGroup[];
groups: UserGroup[];
/**
/** * is user enabled?
* is user enabled? */
*/ @IsBoolean()
@IsBoolean() enabled: boolean;
enabled: boolean;
/**
/** * jwt refresh count
* jwt refresh count */
*/ @IsInt()
@IsInt() @Column({ default: 1 })
@Column({ default: 1 }) refreshTokenCount: number;
refreshTokenCount: number;
/**
/** * profilepic
* profilepic */
*/ @IsString()
@IsString() profilepic: string;
profilepic: string;
/**
/** * calculate all permissions
* actions */
*/ public get calc_permissions(): Permission[] {
@OneToMany(() => UserAction, action => action.user) let final_permissions = this.groups.forEach((permission) => {
actions: UserAction console.log(permission);
})
/** // TODO: add user permissions on top of group permissions + return
* calculate all permissions return []
*/ }
public get calc_permissions(): Permission[] { }
let final_permissions = []
this.groups.forEach((permission) => {
if (!final_permissions.includes(permission)) {
final_permissions.push(permission)
}
})
this.permissions.forEach((permission) => {
if (!final_permissions.includes(permission)) {
final_permissions.push(permission)
}
})
return final_permissions
}
}

View File

@ -1,11 +1,10 @@
import { PrimaryGeneratedColumn, Column, OneToMany, Entity, ManyToOne } from "typeorm"; import { PrimaryGeneratedColumn, Column, OneToMany, Entity } from "typeorm";
import { import {
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
IsOptional, IsOptional,
IsString, IsString,
} from "class-validator"; } from "class-validator";
import { User } from './User';
/** /**
* Defines the UserAction interface. * Defines the UserAction interface.
@ -20,11 +19,8 @@ export class UserAction {
@IsInt() @IsInt()
id: number; id: number;
/** // TODO:
* user // user: relation
*/
@ManyToOne(() => User, user => user.actions)
user: User
/** /**
* The actions's target (e.g. Track#2) * The actions's target (e.g. Track#2)
@ -45,7 +41,7 @@ export class UserAction {
/** /**
* The description of change (before-> after; e.g. distance:15->17) * The description of change (before-> after; e.g. distance:15->17)
*/ */
@Column({ nullable: true }) @Column({nullable: true})
@IsOptional() @IsOptional()
@IsString() @IsString()
changed: string; changed: string;

View File

@ -23,7 +23,7 @@ export abstract class UserGroup {
/** /**
* permissions * permissions
*/ */
@ManyToOne(() => Permission, permission => permission.groups, { nullable: true }) @ManyToOne(() => Permission, permission => permission.groups)
permissions: Permission[]; permissions: Permission[];
/** /**