🐞 fixed UserGroupNotFoundError throwing

ref #14
This commit is contained in:
Philipp Dormann 2020-12-04 19:31:10 +01:00
parent 451d0c92dd
commit d4753a02d4
1 changed files with 16 additions and 10 deletions

View File

@ -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
}
}