@@ -2,7 +2,7 @@ import * as argon2 from "argon2";
 | 
				
			|||||||
import { IsEmail, IsOptional, IsPhoneNumber, IsString, IsUUID } from 'class-validator';
 | 
					import { IsEmail, IsOptional, IsPhoneNumber, IsString, IsUUID } from 'class-validator';
 | 
				
			||||||
import { getConnectionManager } from 'typeorm';
 | 
					import { getConnectionManager } from 'typeorm';
 | 
				
			||||||
import * as uuid from 'uuid';
 | 
					import * as uuid from 'uuid';
 | 
				
			||||||
import { UsernameOrEmailNeededError } from '../../errors/UserErrors';
 | 
					import { UserGroupNotFoundError, UsernameOrEmailNeededError } from '../../errors/UserErrors';
 | 
				
			||||||
import { User } from '../entities/User';
 | 
					import { User } from '../entities/User';
 | 
				
			||||||
import { UserGroup } from '../entities/UserGroup';
 | 
					import { UserGroup } from '../entities/UserGroup';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -24,8 +24,6 @@ export class CreateUser {
 | 
				
			|||||||
    @IsEmail()
 | 
					    @IsEmail()
 | 
				
			||||||
    @IsString()
 | 
					    @IsString()
 | 
				
			||||||
    email?: string;
 | 
					    email?: string;
 | 
				
			||||||
    // @IsArray()
 | 
					 | 
				
			||||||
    // @IsInt()
 | 
					 | 
				
			||||||
    @IsOptional()
 | 
					    @IsOptional()
 | 
				
			||||||
    groupId?: number[] | number
 | 
					    groupId?: number[] | number
 | 
				
			||||||
    @IsUUID("4")
 | 
					    @IsUUID("4")
 | 
				
			||||||
@@ -39,14 +37,20 @@ export class CreateUser {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (this.groupId) {
 | 
					        if (this.groupId) {
 | 
				
			||||||
            // TODO: link user groups
 | 
					 | 
				
			||||||
            if (Array.isArray(this.groupId)) {
 | 
					            if (Array.isArray(this.groupId)) {
 | 
				
			||||||
 | 
					                let found_groups = []
 | 
				
			||||||
 | 
					                this.groupId.forEach(async (g) => {
 | 
				
			||||||
 | 
					                    const foundGroup = await getConnectionManager().get().getRepository(UserGroup).find({ id: g });
 | 
				
			||||||
 | 
					                    if (foundGroup) {
 | 
				
			||||||
 | 
					                        found_groups.push(foundGroup)
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        throw new UserGroupNotFoundError();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					                newUser.groups = found_groups
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                newUser.groups = await getConnectionManager().get().getRepository(UserGroup).find({ id: this.groupId });
 | 
					                newUser.groups = await getConnectionManager().get().getRepository(UserGroup).find({ id: this.groupId });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            // throw new UserGroupNotFoundError();
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const new_uuid = uuid.v4()
 | 
					        const new_uuid = uuid.v4()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user