Switched emails to being mandetory for users

ref #93
This commit is contained in:
2021-01-13 17:44:22 +01:00
parent cf788fe07b
commit 9feeb302e8
8 changed files with 40 additions and 24 deletions

View File

@@ -1,9 +1,9 @@
import * as argon2 from "argon2";
import { IsBoolean, IsEmail, IsOptional, IsPhoneNumber, IsString, IsUrl } from 'class-validator';
import { IsBoolean, IsEmail, IsNotEmpty, IsOptional, IsPhoneNumber, IsString, IsUrl } from 'class-validator';
import { getConnectionManager } from 'typeorm';
import * as uuid from 'uuid';
import { config } from '../../../config';
import { UsernameOrEmailNeededError } from '../../../errors/UserErrors';
import { UserEmailNeededError } from '../../../errors/UserErrors';
import { UserGroupNotFoundError } from '../../../errors/UserGroupErrors';
import { User } from '../../entities/User';
import { UserGroup } from '../../entities/UserGroup';
@@ -33,7 +33,7 @@ export class CreateUser {
/**
* The new user's username.
* You have to provide at least one of: {email, username}.
* You have to provide a email addres, so this is optional.
*/
@IsOptional()
@IsString()
@@ -41,12 +41,11 @@ export class CreateUser {
/**
* The new user's email address.
* You have to provide at least one of: {email, username}.
*/
@IsEmail()
@IsString()
@IsOptional()
email?: string;
@IsNotEmpty()
email: string;
/**
* The new user's phone number.
@@ -92,8 +91,8 @@ export class CreateUser {
public async toEntity(): Promise<User> {
let newUser: User = new User();
if (this.email === undefined && this.username === undefined) {
throw new UsernameOrEmailNeededError();
if (!this.email) {
throw new UserEmailNeededError();
}
newUser.email = this.email