Cleaned up the createUser a little bit

ref #11 #14
This commit is contained in:
Nicolai Ort 2020-12-05 10:23:53 +01:00
parent dadaacfaae
commit a42595bd15

View File

@ -7,35 +7,71 @@ import { User } from '../entities/User';
import { UserGroup } from '../entities/UserGroup'; import { UserGroup } from '../entities/UserGroup';
export class CreateUser { export class CreateUser {
/**
* The new user's first name.
*/
@IsString() @IsString()
firstname: string; firstname: string;
/**
* The new user's middle name.
* Optinal.
*/
@IsString() @IsString()
@IsOptional() @IsOptional()
middlename?: string; middlename?: string;
/**
* The new user's last name.
*/
@IsString()
lastname: string;
/**
* The new user's username.
* You have to provide at least one of: {email, username}.
*/
@IsOptional() @IsOptional()
@IsString() @IsString()
username?: string; username?: string;
@IsPhoneNumber("ZZ") /**
@IsOptional() * The new user's email address.
phone?: string; * You have to provide at least one of: {email, username}.
*/
@IsString()
password: string;
@IsString()
lastname: string;
@IsEmail() @IsEmail()
@IsString() @IsString()
@IsOptional() @IsOptional()
email?: string; email?: string;
/**
* The new user's phone number.
* Optional
*/
@IsPhoneNumber("ZZ")
@IsOptional()
phone?: string;
/**
* The new user's password.
* This will of course not be saved in plaintext :)
*/
@IsString()
password: string;
/**
* The new user's groups' id(s).
* You can provide either one groupId or an array of groupIDs.
* Optional.
*/
@IsOptional() @IsOptional()
groupId?: number[] | number groupId?: number[] | number
//TODO: ProfilePics
/**
* Converts this to a User Entity.
*/
public async toUser(): Promise<User> { public async toUser(): Promise<User> {
let newUser: User = new User(); let newUser: User = new User();
@ -75,8 +111,8 @@ export class CreateUser {
newUser.uuid = uuid.v4() newUser.uuid = uuid.v4()
newUser.phone = this.phone newUser.phone = this.phone
newUser.password = await argon2.hash(this.password + newUser.uuid); newUser.password = await argon2.hash(this.password + newUser.uuid);
//TODO: ProfilePics
console.log(newUser)
return newUser; return newUser;
} }
} }