🚧 reference new Errors from CreateUser
This commit is contained in:
parent
091b455460
commit
1efca47336
@ -1,8 +1,10 @@
|
|||||||
import * as argon2 from "argon2";
|
import * as argon2 from "argon2";
|
||||||
import { IsInt, IsOptional, IsPhoneNumber, IsString, IsUUID } from 'class-validator';
|
import { IsEmail, IsOptional, IsPhoneNumber, IsString, IsUUID } from 'class-validator';
|
||||||
|
import { getConnectionManager } from 'typeorm';
|
||||||
import * as uuid from 'uuid';
|
import * as uuid from 'uuid';
|
||||||
import { UserGroupNotFoundError, UsernameOrEmailNeededError } from '../../errors/CreateUserErrors';
|
import { UsernameOrEmailNeededError } from '../../errors/UserErrors';
|
||||||
import { User } from '../entities/User';
|
import { User } from '../entities/User';
|
||||||
|
import { UserGroup } from '../entities/UserGroup';
|
||||||
|
|
||||||
export class CreateUser {
|
export class CreateUser {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ -19,9 +21,11 @@ export class CreateUser {
|
|||||||
password: string;
|
password: string;
|
||||||
@IsString()
|
@IsString()
|
||||||
lastname: string;
|
lastname: string;
|
||||||
|
@IsEmail()
|
||||||
@IsString()
|
@IsString()
|
||||||
email?: string;
|
email?: string;
|
||||||
@IsInt()
|
// @IsArray()
|
||||||
|
// @IsInt()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
groupId?: number[] | number
|
groupId?: number[] | number
|
||||||
@IsUUID("4")
|
@IsUUID("4")
|
||||||
@ -36,9 +40,13 @@ export class CreateUser {
|
|||||||
|
|
||||||
if (this.groupId) {
|
if (this.groupId) {
|
||||||
// TODO: link user groups
|
// TODO: link user groups
|
||||||
// newUser.groups = await getConnectionManager().get().getRepository(UserGroup).findOne({ id: this.teamId });
|
if (Array.isArray(this.groupId)) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
newUser.groups = await getConnectionManager().get().getRepository(UserGroup).find({ id: this.groupId });
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new UserGroupNotFoundError();
|
// throw new UserGroupNotFoundError();
|
||||||
}
|
}
|
||||||
|
|
||||||
const new_uuid = uuid.v4()
|
const new_uuid = uuid.v4()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user