diff --git a/src/models/creation/CreateUser.ts b/src/models/creation/CreateUser.ts index 102919a..9595039 100644 --- a/src/models/creation/CreateUser.ts +++ b/src/models/creation/CreateUser.ts @@ -2,7 +2,7 @@ import * as argon2 from "argon2"; import { IsEmail, IsOptional, IsPhoneNumber, IsString, IsUUID } from 'class-validator'; import { getConnectionManager } from 'typeorm'; import * as uuid from 'uuid'; -import { UsernameOrEmailNeededError } from '../../errors/UserErrors'; +import { UserGroupNotFoundError, UsernameOrEmailNeededError } from '../../errors/UserErrors'; import { User } from '../entities/User'; import { UserGroup } from '../entities/UserGroup'; @@ -24,8 +24,6 @@ export class CreateUser { @IsEmail() @IsString() email?: string; - // @IsArray() - // @IsInt() @IsOptional() groupId?: number[] | number @IsUUID("4") @@ -39,14 +37,20 @@ export class CreateUser { } if (this.groupId) { - // TODO: link user groups 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 { newUser.groups = await getConnectionManager().get().getRepository(UserGroup).find({ id: this.groupId }); } - } else { - // throw new UserGroupNotFoundError(); } const new_uuid = uuid.v4()