Merge branch 'dev' into feature/13-runner_controllers

This commit is contained in:
2020-12-05 10:44:27 +01:00
21 changed files with 145 additions and 118 deletions

View File

@@ -1,5 +1,5 @@
import * as argon2 from "argon2";
import { IsEmail, IsOptional, IsPhoneNumber, IsString, IsUUID } from 'class-validator';
import { IsEmail, IsOptional, IsPhoneNumber, IsString } from 'class-validator';
import { getConnectionManager } from 'typeorm';
import * as uuid from 'uuid';
import { UserGroupNotFoundError, UsernameOrEmailNeededError } from '../../errors/UserErrors';
@@ -7,28 +7,71 @@ import { User } from '../entities/User';
import { UserGroup } from '../entities/UserGroup';
export class CreateUser {
/**
* The new user's first name.
*/
@IsString()
firstname: string;
/**
* The new user's middle name.
* Optinal.
*/
@IsString()
@IsOptional()
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()
@IsString()
username?: string;
/**
* The new user's email address.
* You have to provide at least one of: {email, username}.
*/
@IsEmail()
@IsString()
@IsOptional()
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;
@IsString()
lastname: string;
@IsEmail()
@IsString()
email?: string;
/**
* The new user's groups' id(s).
* You can provide either one groupId or an array of groupIDs.
* Optional.
*/
@IsOptional()
groupId?: number[] | number
@IsUUID("4")
uuid: string;
//TODO: ProfilePics
/**
* Converts this to a User Entity.
*/
public async toUser(): Promise<User> {
let newUser: User = new User();
@@ -60,17 +103,16 @@ export class CreateUser {
}
}
const new_uuid = uuid.v4()
newUser.email = this.email
newUser.username = this.username
newUser.firstname = this.firstname
newUser.middlename = this.middlename
newUser.lastname = this.lastname
newUser.uuid = new_uuid
newUser.password = await argon2.hash(this.password + new_uuid);
newUser.uuid = uuid.v4()
newUser.phone = this.phone
newUser.password = await argon2.hash(this.password + newUser.uuid);
//TODO: ProfilePics
console.log(newUser)
return newUser;
}
}

View File

@@ -1,28 +1,30 @@
import { IsOptional, IsString } from 'class-validator';
import { GroupNameNeededError } from '../../errors/UserGroupErrors';
import { UserGroup } from '../entities/UserGroup';
export class CreateUserGroup {
@IsOptional()
/**
* The new group's name.
*/
@IsString()
name: string;
/**
* The new group's description.
* Optinal.
*/
@IsOptional()
@IsString()
description?: string;
/**
* Converts this to a UserGroup entity.
*/
public async toUserGroup(): Promise<UserGroup> {
let newUserGroup: UserGroup = new UserGroup();
if (this.name === undefined) {
throw new GroupNameNeededError();
}
newUserGroup.name = this.name;
newUserGroup.description = this.description;
newUserGroup.name = this.name
if (this.description) {
newUserGroup.description = this.description
}
console.log(newUserGroup)
return newUserGroup;
}
}