🐞 fixed UserGroupNotFoundError throwing

ref #14
This commit is contained in:
Philipp Dormann 2020-12-04 19:31:10 +01:00
parent 451d0c92dd
commit d4753a02d4

View File

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