Compare commits

..

No commits in common. "1cf35f016b0aeb0f1224648b301044b2ea76dc60" and "aa565c6b344f62521b9b53575ffce36e8b77af74" have entirely different histories.

2 changed files with 38 additions and 56 deletions

View File

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

View File

@ -1,11 +1,10 @@
import { PrimaryGeneratedColumn, Column, OneToMany, Entity, ManyToOne } from "typeorm";
import { PrimaryGeneratedColumn, Column, OneToMany, Entity } from "typeorm";
import {
IsInt,
IsNotEmpty,
IsOptional,
IsString,
} from "class-validator";
import { User } from './User';
/**
* Defines the UserAction interface.
@ -20,11 +19,8 @@ export class UserAction {
@IsInt()
id: number;
/**
* user
*/
@ManyToOne(() => User, user => user.actions)
user: User
// TODO:
// user: relation
/**
* 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)
*/
@Column({ nullable: true })
@Column({nullable: true})
@IsOptional()
@IsString()
changed: string;