diff --git a/src/models/User.ts b/src/models/User.ts index fce74e8..b039d20 100644 --- a/src/models/User.ts +++ b/src/models/User.ts @@ -2,6 +2,7 @@ import { Entity, Column, OneToMany, ManyToOne, PrimaryGeneratedColumn, Generated import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsString, isUUID, } from "class-validator"; import { UserGroup } from './UserGroup'; import { Permission } from './Permission'; +import { UserAction } from './UserAction'; /** * Defines a admin user. @@ -11,10 +12,10 @@ export class User { /** * autogenerated unique id (primary key). */ - @PrimaryGeneratedColumn() - @IsOptional() - @IsInt() - id: number; + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + id: number; /** * autogenerated uuid @@ -96,6 +97,12 @@ export class User { @IsString() profilepic: string; + /** + * actions + */ + @OneToMany(() => UserAction, action => action.user) + actions: UserAction + /** * calculate all permissions */ diff --git a/src/models/UserAction.ts b/src/models/UserAction.ts index ea794a5..c9caf60 100644 --- a/src/models/UserAction.ts +++ b/src/models/UserAction.ts @@ -1,10 +1,11 @@ -import { PrimaryGeneratedColumn, Column, OneToMany, Entity } from "typeorm"; +import { PrimaryGeneratedColumn, Column, OneToMany, Entity, ManyToOne } from "typeorm"; import { IsInt, IsNotEmpty, IsOptional, IsString, } from "class-validator"; +import { User } from './User'; /** * Defines the UserAction interface. @@ -19,8 +20,11 @@ export class UserAction { @IsInt() id: number; - // TODO: - // user: relation + /** + * user + */ + @ManyToOne(() => User, user => user.actions) + user: User /** * The actions's target (e.g. Track#2) @@ -41,7 +45,7 @@ export class UserAction { /** * The description of change (before-> after; e.g. distance:15->17) */ - @Column({nullable: true}) + @Column({ nullable: true }) @IsOptional() @IsString() changed: string;