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:
		@@ -1,109 +1,123 @@
 | 
			
		||||
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, { nullable: true })
 | 
			
		||||
  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 []
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
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';
 | 
			
		||||
import { UserAction } from './UserAction';
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 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, { nullable: true })
 | 
			
		||||
  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;
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 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)
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
    this.permissions.forEach((permission) => {
 | 
			
		||||
      if (!final_permissions.includes(permission)) {
 | 
			
		||||
        final_permissions.push(permission)
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
    return final_permissions
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user