| @@ -40,17 +40,23 @@ export class CreateUser { | ||||
|             if (!Array.isArray(this.groupId)) { | ||||
|                 this.groupId = [this.groupId] | ||||
|             } | ||||
|             let found_groups = [] | ||||
|             this.groupId.forEach(async (g) => { | ||||
|                 const foundGroup = await getConnectionManager().get().getRepository(UserGroup).findOne({ id: g }); | ||||
|                 console.log(foundGroup); | ||||
|                 found_groups.push(foundGroup) | ||||
|             }); | ||||
|             console.log(found_groups); | ||||
|             if (found_groups.includes(undefined) || found_groups.includes(null)) { | ||||
|             const groupIDs: number[] = this.groupId | ||||
|             let errors = 0 | ||||
|             const validateusergroups = async () => { | ||||
|                 let foundgroups = [] | ||||
|                 for (const g of groupIDs) { | ||||
|                     const found = await getConnectionManager().get().getRepository(UserGroup).find({ id: g }); | ||||
|                     if (found.length === 0) { | ||||
|                         errors++ | ||||
|                     } else { | ||||
|                         foundgroups.push(found) | ||||
|                     } | ||||
|                 } | ||||
|                 newUser.groups = foundgroups | ||||
|             } | ||||
|             await validateusergroups() | ||||
|             if (errors !== 0) { | ||||
|                 throw new UserGroupNotFoundError(); | ||||
|             } else { | ||||
|                 newUser.groups = found_groups | ||||
|             } | ||||
|         } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user