Merge branch 'feature/11-new_classes' of git.odit.services:lfk/backend into feature/11-new_classes

# Conflicts:
#	src/models/User.ts
This commit is contained in:
Nicolai Ort 2020-12-02 19:45:30 +01:00
commit 6464033a58
2 changed files with 131 additions and 113 deletions

View File

@ -1,109 +1,123 @@
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() */
export class User { @Entity()
/** export class User {
* autogenerated unique id (primary key). /**
*/ * autogenerated unique id (primary key).
@PrimaryGeneratedColumn() */
@IsOptional() @PrimaryGeneratedColumn()
@IsInt() @IsOptional()
id: number; @IsInt()
id: number;
/**
* autogenerated uuid /**
*/ * autogenerated uuid
@IsOptional() */
@IsInt() @IsOptional()
@Generated("uuid") @IsInt()
uuid: string; @Generated("uuid")
uuid: string;
/**
* user email /**
*/ * user email
@IsEmail() */
email: string; @IsEmail()
email: string;
/**
* username /**
*/ * username
@IsString() */
username: string; @IsString()
username: string;
/**
* firstname /**
*/ * firstname
@IsString() */
@IsNotEmpty() @IsString()
firstname: string; @IsNotEmpty()
firstname: string;
/**
* middlename /**
*/ * middlename
@IsString() */
@IsOptional() @IsString()
middlename: string; @IsOptional()
middlename: string;
/**
* lastname /**
*/ * lastname
@IsString() */
@IsNotEmpty() @IsString()
lastname: string; @IsNotEmpty()
lastname: string;
/**
* password /**
*/ * password
@IsString() */
@IsNotEmpty() @IsString()
password: string; @IsNotEmpty()
password: string;
/**
* permissions /**
*/ * permissions
@ManyToOne(() => Permission, permission => permission.users, { nullable: true }) */
permissions: Permission[]; @ManyToOne(() => Permission, permission => permission.users, { nullable: true })
permissions: Permission[];
/**
* groups /**
*/ * groups
@ManyToMany(() => UserGroup) */
@JoinTable() @ManyToMany(() => UserGroup)
groups: UserGroup[]; @JoinTable()
groups: UserGroup[];
/**
* is user enabled? /**
*/ * is user enabled?
@IsBoolean() */
enabled: boolean; @IsBoolean()
enabled: boolean;
/**
* jwt refresh count /**
*/ * jwt refresh count
@IsInt() */
@Column({ default: 1 }) @IsInt()
refreshTokenCount: number; @Column({ default: 1 })
refreshTokenCount: number;
/**
* profilepic /**
*/ * profilepic
@IsString() */
profilepic: string; @IsString()
profilepic: string;
/**
* calculate all permissions /**
*/ * actions
public get calc_permissions(): Permission[] { */
let final_permissions = this.groups.forEach((permission) => { @OneToMany(() => UserAction, action => action.user)
console.log(permission); actions: UserAction
})
// TODO: add user permissions on top of group permissions + return /**
return [] * calculate all permissions
} */
} 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,10 +1,11 @@
import { PrimaryGeneratedColumn, Column, OneToMany, Entity } from "typeorm"; import { PrimaryGeneratedColumn, Column, OneToMany, Entity, ManyToOne } 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.
@ -19,8 +20,11 @@ export class UserAction {
@IsInt() @IsInt()
id: number; id: number;
// TODO: /**
// user: relation * user
*/
@ManyToOne(() => User, user => user.actions)
user: User
/** /**
* The actions's target (e.g. Track#2) * 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) * 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;