From 48e28e7b7a19e1ad66ba12461826676bd9074a58 Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Wed, 2 Dec 2020 18:07:33 +0100 Subject: [PATCH] User + UserGroup --- src/models/User.ts | 100 ++++++++++++++++++++++++++++++++++++++++ src/models/UserGroup.ts | 44 ++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 src/models/User.ts create mode 100644 src/models/UserGroup.ts diff --git a/src/models/User.ts b/src/models/User.ts new file mode 100644 index 0000000..e575a79 --- /dev/null +++ b/src/models/User.ts @@ -0,0 +1,100 @@ +import { Entity, Column, OneToMany, ManyToOne, PrimaryGeneratedColumn, Generated, Unique } from "typeorm"; +import { IsBoolean, IsEmail, IsInt, IsNotEmpty, IsOptional, IsString, isUUID, } from "class-validator"; +import { UserGroup } from './UserGroup'; + +/** + * Defines a admin user. +*/ +@Entity() +export class User { + /** + * autogenerated unique id (primary key). + */ + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + id: number; + + /** + * autogenerated uuid + */ + @PrimaryGeneratedColumn() + @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; + + /** + * userpermissions + */ + // TODO: UserPermission implementation + // @OneToMany(() => UserPermission,userpermission=>) + // userpermissions: UserPermission[]; + + /** + * groups + */ + // TODO: UserGroup implementation + // @OneToMany(() => UserGroup, usergroup => usergroup.) + @IsOptional() + groups: UserGroup[]; + + /** + * is user enabled? + */ + @IsBoolean() + enabled: boolean; + + /** + * jwt refresh count + */ + @IsInt() + @Column({ default: 1 }) + refreshTokenCount: number; + + /** + * profilepic + */ + @IsString() + profilepic: string; +} diff --git a/src/models/UserGroup.ts b/src/models/UserGroup.ts new file mode 100644 index 0000000..61a434e --- /dev/null +++ b/src/models/UserGroup.ts @@ -0,0 +1,44 @@ +import { PrimaryGeneratedColumn, Column, OneToMany, Entity } from "typeorm"; +import { + IsInt, + IsNotEmpty, + IsOptional, + IsString, +} from "class-validator"; +import { User } from "./User"; + +/** + * Defines the UserGroup interface. +*/ +@Entity() +export abstract class UserGroup { + /** + * Autogenerated unique id (primary key). + */ + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + id: number; + + /** + * The group's name + */ + @Column() + @IsNotEmpty() + @IsString() + name: string; + + /** + * The group's description + */ + @Column() + @IsOptional() + @IsString() + description: string; + + /** + * Used to link users to a user group. + */ + // TODO: + // grouppermissions: GroupPermissions[]; +} \ No newline at end of file