Compare commits

...

57 Commits

Author SHA1 Message Date
18fdd367ac Merge branch 'dev' into feature/13-runner_controllers 2020-12-02 18:48:53 +01:00
7d9e003a6d Merge pull request 'feature/11-new_classes' (#15) from feature/11-new_classes into dev
Reviewed-on: #15
2020-12-02 17:48:16 +00:00
a78bbb1de5 🚧 User + Permissions 2020-12-02 18:46:36 +01:00
e4d5afbebe 🚧 Permission 2020-12-02 18:28:48 +01:00
63843cc4c9 Merge branch 'feature/11-new_classes' of https://git.odit.services/lfk/backend into feature/11-new_classes 2020-12-02 18:27:16 +01:00
1d57264922 🚧 Permissions 2020-12-02 18:27:06 +01:00
82ca8f48dc 🚧 UserAction 2020-12-02 18:27:00 +01:00
4a9fd57356 Fixed user<-> Group relationship 2020-12-02 18:20:53 +01:00
d47983a032 🚧 User class WIP 2020-12-02 18:11:23 +01:00
4ad8afd512 Merge branch 'feature/11-new_classes' of https://git.odit.services/lfk/backend into feature/11-new_classes 2020-12-02 18:07:36 +01:00
48e28e7b7a User + UserGroup 2020-12-02 18:07:33 +01:00
932e782a14 Added defaults back in 2020-12-02 18:05:18 +01:00
ac0ce799f9 Fixed the cirvular import BS
ref #11
2020-12-02 17:40:03 +01:00
5bf978d32d Turned the abstracts into entities
ref #11
2020-12-02 16:07:18 +01:00
dd5f4488be Cleaned up relations
ref #11
2020-12-02 16:00:09 +01:00
d0a1ea3292 Renamed getter
ref #11
2020-12-02 15:49:19 +01:00
84dd1fe4a5 Added missing getter 2020-12-02 15:46:53 +01:00
abf7aaeda3 Fixed import
ref #11
2020-12-02 15:46:43 +01:00
c82cc9a670 Moved attribute to super
ref #11
2020-12-02 15:44:56 +01:00
c1242b2a2a Added TrackScan relationships
ref #11
2020-12-02 15:40:25 +01:00
4d593eb840 Removed relation that was already implemented in the super
ref #11
2020-12-02 15:36:11 +01:00
f32291d714 Added scan station relationship
ref #11
2020-12-02 15:34:04 +01:00
8e2eac9dc0 Added relations for Scans
ref #11
2020-12-02 15:32:11 +01:00
0d9d72c223 Added relations for RunnerTeams
ref #11
2020-12-01 19:51:16 +01:00
7ac46a7cc7 Added relations to RunnerOrganisation 2020-12-01 19:48:20 +01:00
f28b08ed65 Added relations to RunnerGroup
ref #11
2020-12-01 19:44:51 +01:00
029e4beaf5 Added relations for runner cards
ref #11
2020-12-01 19:27:36 +01:00
a6222a8025 Added relations for runners
ref #11
2020-12-01 19:20:27 +01:00
4075276130 Added relations for participants
ref #11
2020-12-01 19:17:53 +01:00
2b693917b0 Added relationships for donation
ref #11
2020-12-01 19:13:56 +01:00
1c43442300 Relations for distanceDonation
ref #11
2020-12-01 19:10:52 +01:00
dca9aef258 Other classed are now using the new Address class rather than the old location placeholder
ref #11
2020-12-01 19:06:56 +01:00
2bd0cbadbe Added the address class
ref #11
2020-12-01 19:03:41 +01:00
8b2d6840a8 Added the track scan class
ref #11
2020-12-01 18:57:44 +01:00
df3715d8d6 Changed the distance to be an abstract
ref #11
2020-12-01 18:57:34 +01:00
084e2d9930 Renamed property, so it fits with the rest of the nameing
ref #11
2020-12-01 18:50:06 +01:00
79eecbb329 fixxed missing imports and commented out a non-implemented function call
ref #11
2020-12-01 18:48:28 +01:00
f7beebce3f Added scanstation class
ref #11
2020-12-01 18:39:33 +01:00
fbbb5df64f Added runnerCard class
ref #11
2020-12-01 18:16:17 +01:00
96d70d5048 Added group contact class
ref #11
2020-12-01 18:07:39 +01:00
ac40527fa2 Added the runnerteam class
ref #11
2020-12-01 18:01:32 +01:00
66f7a7928c Added the runner org class
ref #11
2020-12-01 17:58:23 +01:00
deae0bb84b Added finxed donations
ref #11
2020-12-01 17:53:43 +01:00
6c32a9ebe9 Added distance Donation 2020-12-01 17:51:30 +01:00
a8d1ec6f9b Marked amount as abstract
ref #11
2020-12-01 17:50:43 +01:00
daea0568a8 Amount no longer is a column by default 2020-12-01 17:45:59 +01:00
b632c09924 Added donor
ref #11
2020-12-01 17:41:56 +01:00
7ce8c375a2 Fixed copy-paste slip up
ref #11
2020-12-01 17:39:03 +01:00
5a04e61d1c Added the runner class
ref #11
2020-12-01 17:38:28 +01:00
748fff5c32 Cleaned up imports and descriptions
ref #11
2020-12-01 17:32:21 +01:00
57ba0c3051 Added the donation abstract/interface 2020-12-01 17:31:05 +01:00
72f80859a9 Added todo's for relationships 2020-12-01 17:27:48 +01:00
f999c416c4 Added Runnergroup abstract class
ref #11
2020-12-01 17:27:18 +01:00
f8e1bf715b Changed nameing scheme for the abstract classes since we're not useing interfaces
ref #11
2020-12-01 17:21:44 +01:00
f350007ae5 Added participant abstract class
ref #11
2020-12-01 17:20:43 +01:00
a2cf8d1f2c Switched from implementing the "interfaces" as interface to abstract classes
ref #11
This was done to take advantage of typeorm and class validator
2020-12-01 17:16:50 +01:00
abb7f7f894 Added Basic Scan interface
ref #11
2020-12-01 17:10:17 +01:00
20 changed files with 992 additions and 3 deletions

87
src/models/Address.ts Normal file
View File

@ -0,0 +1,87 @@
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from "typeorm";
import {
IsInt,
IsNotEmpty,
IsOptional,
IsPostalCode,
IsString,
} from "class-validator";
import { Participant } from "./Participant";
import { RunnerOrganisation } from "./RunnerOrganisation";
/**
* Defines a address (to be used for contact information).
*/
@Entity()
export class Address {
/**
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
/**
* The address's description.
*/
@Column()
@IsString()
@IsOptional()
description?: string;
/**
* The address's first line.
* Containing the street and house number.
*/
@Column()
@IsString()
@IsNotEmpty()
address1: string;
/**
* The address's second line.
* Containing optional information.
*/
@Column()
@IsString()
@IsOptional()
address2?: string;
/**
* The address's postal code.
*/
@Column()
@IsString()
@IsNotEmpty()
@IsPostalCode("DE")
postalcode: string;
/**
* The address's city.
*/
@Column()
@IsString()
@IsNotEmpty()
city: string;
/**
* The address's country.
*/
@Column()
@IsString()
@IsNotEmpty()
country: string;
/**
* Used to link the address to participants.
*/
@OneToMany(() => Participant, participant => participant.address)
participants: Participant[];
/**
* Used to link the address to runner groups.
*/
@OneToMany(() => RunnerOrganisation, group => group.address)
groups: RunnerOrganisation[];
}

View File

@ -0,0 +1,41 @@
import { Entity, Column, ManyToOne } from "typeorm";
import { IsInt, IsNotEmpty, IsPositive,} from "class-validator";
import { Donation } from "./Donation";
import { Runner } from "./Runner";
/**
* Defines a distance based donation.
* Here people donate a certain amout per kilometer
*/
@Entity()
export class DistanceDonation extends Donation {
/**
* The runner associated.
*/
@IsNotEmpty()
@ManyToOne(() => Runner, runner => runner.distanceDonations)
runner: Runner;
/**
* The amount the donor set to be donated per kilometer that the runner ran.
*/
@Column()
@IsInt()
@IsPositive()
amountPerDistance: number;
/**
* The donation's amount in cents (or whatever your currency's smallest unit is.).
* The exact implementation may differ for each type of donation.
*/
@IsInt()
public get amount(): number {
let calculatedAmount = -1;
try {
calculatedAmount = this.amountPerDistance * this.runner.distance;
} catch (error) {
throw error;
}
return calculatedAmount;
}
}

35
src/models/Donation.ts Normal file
View File

@ -0,0 +1,35 @@
import { PrimaryGeneratedColumn, Column, ManyToOne, Entity } from "typeorm";
import {
IsInt,
IsNotEmpty,
IsOptional,
IsPositive,
} from "class-validator";
import { Participant } from "./Participant";
/**
* Defines the donation interface.
*/
@Entity()
export abstract class Donation {
/**
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
/**
* The donations's donor.
*/
@IsNotEmpty()
@ManyToOne(() => Participant, donor => donor.donations)
donor: Participant;
/**
* The donation's amount in cents (or whatever your currency's smallest unit is.).
* The exact implementation may differ for each type of donation.
*/
abstract amount: number;
}

17
src/models/Donor.ts Normal file
View File

@ -0,0 +1,17 @@
import { Entity, Column } from "typeorm";
import { IsBoolean } from "class-validator";
import { Participant } from "./Participant";
/**
* Defines a donor.
*/
@Entity()
export class Donor extends Participant {
/**
* Does this donor need a receipt?.
* Default: false
*/
@Column()
@IsBoolean()
receiptNeeded: boolean = false;
}

View File

@ -0,0 +1,18 @@
import { Entity, Column } from "typeorm";
import { IsInt, IsPositive,} from "class-validator";
import { Donation } from "./Donation";
/**
* Defines a fixed donation.
*/
@Entity()
export class FixedDonation extends Donation {
/**
* The donation's amount in cents (or whatever your currency's smallest unit is.).
*/
@Column()
@IsInt()
@IsPositive()
amount: number;
}

View File

@ -0,0 +1,89 @@
import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity } from "typeorm";
import {
IsEmail,
IsInt,
IsNotEmpty,
IsOptional,
IsPhoneNumber,
IsString,
} from "class-validator";
import { Address } from "./Address";
import { Donation } from "./Donation";
import { RunnerGroup } from "./RunnerGroup";
/**
* Defines a group's contact.
*/
@Entity()
export class GroupContact {
/**
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
/**
* The contact's first name.
*/
@Column()
@IsNotEmpty()
@IsString()
firstname: string;
/**
* The contact's middle name.
* Optional
*/
@Column()
@IsOptional()
@IsString()
middlename?: string;
/**
* The contact's last name.
*/
@Column()
@IsOptional()
@IsString()
lastname: string;
/**
* The contact's address.
* Optional
*/
@IsOptional()
@ManyToOne(() => Address, address => address.participants)
address?: Address;
/**
* The contact's phone number.
* Optional
*/
@Column()
@IsOptional()
@IsPhoneNumber("DE")
phone?: string;
/**
* The contact's email address.
* Optional
*/
@Column()
@IsOptional()
@IsEmail()
email?: string;
/**
* Used to link the contact as the donor of a donation.
*/
@OneToMany(() => Donation, donation => donation.donor)
donations: Donation[];
/**
* Used to link runners to donations.
*/
@OneToMany(() => RunnerGroup, group => group.contact)
groups: RunnerGroup[];
}

82
src/models/Participant.ts Normal file
View File

@ -0,0 +1,82 @@
import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity } from "typeorm";
import {
IsEmail,
IsInt,
IsNotEmpty,
IsOptional,
IsPhoneNumber,
IsString,
} from "class-validator";
import { Address } from "./Address";
import { Donation } from "./Donation";
/**
* Defines the participant interface.
*/
@Entity()
export abstract class Participant {
/**
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
/**
* The participant's first name.
*/
@Column()
@IsNotEmpty()
@IsString()
firstname: string;
/**
* The participant's middle name.
* Optional
*/
@Column()
@IsOptional()
@IsString()
middlename?: string;
/**
* The participant's last name.
*/
@Column()
@IsOptional()
@IsString()
lastname: string;
/**
* The participant's address.
* Optional
*/
@IsOptional()
@ManyToOne(() => Address, address => address.participants)
address?: Address;
/**
* The participant's phone number.
* Optional
*/
@Column()
@IsOptional()
@IsPhoneNumber("DE")
phone?: string;
/**
* The participant's email address.
* Optional
*/
@Column()
@IsOptional()
@IsEmail()
email?: string;
/**
* Used to link the participant as the donor of a donation.
*/
@OneToMany(() => Donation, donation => donation.donor)
donations: Donation[];
}

50
src/models/Permission.ts Normal file
View File

@ -0,0 +1,50 @@
import { PrimaryGeneratedColumn, Column, OneToMany, Entity, ManyToOne } from "typeorm";
import {
IsInt,
IsNotEmpty,
IsOptional,
IsString,
} from "class-validator";
import { User } from './User';
import { UserGroup } from './UserGroup';
/**
* Defines the Permission interface.
*/
@Entity()
export abstract class Permission {
/**
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
/**
* users
*/
@OneToMany(() => User, user => user.permissions)
users: User[]
/**
* groups
*/
@OneToMany(() => UserGroup, group => group.permissions)
groups: UserGroup[]
/**
* The target
*/
@Column()
@IsNotEmpty()
@IsString()
target: string;
/**
* The action type
*/
@Column()
@IsNotEmpty()
@IsString()
action: string;
}

44
src/models/Runner.ts Normal file
View File

@ -0,0 +1,44 @@
import { Entity, Column, OneToMany, ManyToOne } from "typeorm";
import { IsInt, IsNotEmpty,} from "class-validator";
import { Participant } from "./Participant";
import { RunnerGroup } from "./RunnerGroup";
import { DistanceDonation } from "./DistanceDonation";
import { RunnerCard } from "./RunnerCard";
import { Scan } from "./Scan";
/**
* Defines a runner.
*/
@Entity()
export class Runner extends Participant {
/**
* The runner's associated group.
*/
@IsNotEmpty()
@ManyToOne(() => RunnerGroup, group => group.runners)
group: RunnerGroup;
/**
* Used to link runners to donations.
*/
@OneToMany(() => DistanceDonation, distanceDonation => distanceDonation.runner)
distanceDonations: DistanceDonation[];
/**
* Used to link runners to cards.
*/
@OneToMany(() => RunnerCard, card => card.runner)
cards: RunnerCard[];
/**
* Used to link runners to a scans
*/
@OneToMany(() => Scan, scan => scan.runner)
scans: Scan[];
@IsInt()
public get distance() : number {
return this.scans.filter(scan => scan.valid === true).reduce((sum, current) => sum + current.distance, 0);
}
}

56
src/models/RunnerCard.ts Normal file
View File

@ -0,0 +1,56 @@
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany } from "typeorm";
import {
IsBoolean,
IsInt,
IsNotEmpty,
IsOptional,
IsString,
} from "class-validator";
import { Runner } from "./Runner";
import { TrackScan } from "./TrackScan";
/**
* Defines a card that can be scanned via a scanner station.
*/
@Entity()
export class RunnerCard {
/**
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
/**
* The runner that is currently associated with this card.
*/
@IsOptional()
@ManyToOne(() => Runner, runner => runner.cards)
runner: Runner;
/**
* The card's code.
* This has to be able to being converted to something barcode compatible.
* Probably gonna be autogenerated.
*/
@Column()
@IsString()
@IsNotEmpty()
//TODO: Generate this
code: string;
/**
* Is the card enabled (for fraud reasons)?
* Default: true
*/
@Column()
@IsBoolean()
enabled: boolean = true;
/**
* Used to link cards to a track scans.
*/
@OneToMany(() => TrackScan, scan => scan.track)
scans: TrackScan[];
}

46
src/models/RunnerGroup.ts Normal file
View File

@ -0,0 +1,46 @@
import { PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, Entity } from "typeorm";
import {
IsInt,
IsNotEmpty,
IsOptional,
IsString,
} from "class-validator";
import { GroupContact } from "./GroupContact";
import { Runner } from "./Runner";
import { RunnerTeam } from "./RunnerTeam";
/**
* Defines the runnerGroup interface.
*/
@Entity()
export abstract class RunnerGroup {
/**
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
/**
* The group's first name.
*/
@Column()
@IsNotEmpty()
@IsString()
name: string;
/**
* The group's contact.
* Optional
*/
@IsOptional()
@ManyToOne(() => GroupContact, contact => contact.groups)
contact?: GroupContact;
/**
* Used to link runners to a runner group.
*/
@OneToMany(() => Runner, runner => runner.group)
runners: Runner[];
}

View File

@ -0,0 +1,26 @@
import { Entity, Column, ManyToOne, OneToMany } from "typeorm";
import { IsOptional,} from "class-validator";
import { RunnerGroup } from "./RunnerGroup";
import { Address } from "./Address";
import { RunnerTeam } from "./RunnerTeam";
/**
* Defines a runner organisation (business or school for example).
*/
@Entity()
export class RunnerOrganisation extends RunnerGroup {
/**
* The organisations's address.
* Optional
*/
@IsOptional()
@ManyToOne(() => Address, address => address.groups)
address?: Address;
/**
* Used to link teams to runner groups.
*/
@OneToMany(() => RunnerTeam, team => team.parentGroup)
teams: RunnerTeam[];
}

19
src/models/RunnerTeam.ts Normal file
View File

@ -0,0 +1,19 @@
import { Entity, Column, ManyToOne } from "typeorm";
import { IsNotEmpty } from "class-validator";
import { RunnerGroup } from "./RunnerGroup";
import { RunnerOrganisation } from "./RunnerOrganisation";
/**
* Defines a runner team (class or deparment for example).
*/
@Entity()
export class RunnerTeam extends RunnerGroup {
/**
* The team's parent group.
* Optional
*/
@IsNotEmpty()
@ManyToOne(() => RunnerOrganisation, org => org.teams)
parentGroup?: RunnerOrganisation;
}

45
src/models/Scan.ts Normal file
View File

@ -0,0 +1,45 @@
import { PrimaryGeneratedColumn, Column, ManyToOne, Entity } from "typeorm";
import {
IsBoolean,
IsInt,
IsNotEmpty,
IsOptional,
IsPositive,
} from "class-validator";
import { Runner } from "./Runner";
/**
* Defines the scan interface.
*/
@Entity()
export abstract class Scan {
/**
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
/**
* The associated runner.
*/
@IsNotEmpty()
@ManyToOne(() => Runner, runner => runner.scans)
runner: Runner;
/**
* The scan's distance in meters.
*/
@IsInt()
@IsPositive()
abstract distance: number;
/**
* Is the scan valid (for fraud reasons).
* Default: true
*/
@Column()
@IsBoolean()
valid: boolean = true;
}

61
src/models/ScanStation.ts Normal file
View File

@ -0,0 +1,61 @@
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany } from "typeorm";
import {
IsBoolean,
IsInt,
IsNotEmpty,
IsOptional,
IsString,
} from "class-validator";
import { Track } from "./Track";
import { TrackScan } from "./TrackScan";
/**
* ScannerStations have the ability to create scans for specific tracks.
*/
@Entity()
export class ScanStation {
/**
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
/**
* The station's description.
*/
@Column()
@IsNotEmpty()
@IsString()
description: string;
/**
* The track this station is associated with.
*/
@IsNotEmpty()
@ManyToOne(() => Track, track => track.stations)
track: Track;
/**
* The station's api key.
*/
@Column()
@IsNotEmpty()
@IsString()
key: string;
/**
* Is the station enabled (for fraud reasons)?
* Default: true
*/
@Column()
@IsBoolean()
enabled: boolean = true;
/**
* Used to link track scans to a scan station.
*/
@OneToMany(() => TrackScan, scan => scan.track)
scans: TrackScan[];
}

View File

@ -1,4 +1,4 @@
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm";
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from "typeorm";
import {
IsInt,
IsNotEmpty,
@ -6,6 +6,8 @@ import {
IsPositive,
IsString,
} from "class-validator";
import { ScanStation } from "./ScanStation";
import { TrackScan } from "./TrackScan";
/**
* Defines a track of given length.
@ -29,10 +31,22 @@ export class Track {
name: string;
/**
* The track's length in meters.
* The track's length/distance in meters.
*/
@Column()
@IsInt()
@IsPositive()
length: number;
distance: number;
/**
* Used to link scan stations to track.
*/
@OneToMany(() => ScanStation, station => station.track)
stations: ScanStation[];
/**
* Used to link track scans to a track.
*/
@OneToMany(() => TrackScan, scan => scan.track)
scans: TrackScan[];
}

58
src/models/TrackScan.ts Normal file
View File

@ -0,0 +1,58 @@
import { PrimaryGeneratedColumn, Column, ManyToOne, Entity } from "typeorm";
import {
IsBoolean,
IsDateString,
IsInt,
IsNotEmpty,
IsOptional,
IsPositive,
} from "class-validator";
import { Scan } from "./Scan";
import { Runner } from "./Runner";
import { Track } from "./Track";
import { RunnerCard } from "./RunnerCard";
import { ScanStation } from "./ScanStation";
/**
* Defines the scan interface.
*/
@Entity()
export class TrackScan extends Scan {
/**
* The associated track.
*/
@IsNotEmpty()
@ManyToOne(() => Track, track => track.scans)
track: Track;
/**
* The associated card.
*/
@IsNotEmpty()
@ManyToOne(() => RunnerCard, card => card.scans)
card: RunnerCard;
/**
* The scanning station.
*/
@IsNotEmpty()
@ManyToOne(() => ScanStation, station => station.scans)
station: ScanStation;
/**
* The scan's distance in meters.
*/
@IsInt()
@IsPositive()
public get distance(): number {
return this.track.distance;
}
/**
* The scan's creation timestamp.
*/
@Column()
@IsDateString()
@IsNotEmpty()
timestamp: string;
}

109
src/models/User.ts Normal file
View File

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

48
src/models/UserAction.ts Normal file
View File

@ -0,0 +1,48 @@
import { PrimaryGeneratedColumn, Column, OneToMany, Entity } from "typeorm";
import {
IsInt,
IsNotEmpty,
IsOptional,
IsString,
} from "class-validator";
/**
* Defines the UserAction interface.
*/
@Entity()
export class UserAction {
/**
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
// TODO:
// user: relation
/**
* The actions's target (e.g. Track#2)
*/
@Column()
@IsNotEmpty()
@IsString()
target: string;
/**
* The actions's action (e.g. UPDATE)
*/
@Column()
@IsNotEmpty()
@IsString()
action: string;
/**
* The description of change (before-> after; e.g. distance:15->17)
*/
@Column()
@IsOptional()
@IsString()
changed: string;
}

44
src/models/UserGroup.ts Normal file
View File

@ -0,0 +1,44 @@
import { PrimaryGeneratedColumn, Column, OneToMany, Entity, ManyToOne } from "typeorm";
import {
IsInt,
IsNotEmpty,
IsOptional,
IsString,
} from "class-validator";
import { Permission } from "./Permission";
/**
* Defines the UserGroup interface.
*/
@Entity()
export abstract class UserGroup {
/**
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number;
/**
* permissions
*/
@ManyToOne(() => Permission, permission => permission.groups)
permissions: Permission[];
/**
* The group's name
*/
@Column()
@IsNotEmpty()
@IsString()
name: string;
/**
* The group's description
*/
@Column()
@IsOptional()
@IsString()
description: string;
}