Fixed the user->Group relation

ref #6
This commit is contained in:
2020-12-18 21:42:43 +01:00
parent 1a9c860188
commit d670b814a4
3 changed files with 6 additions and 36 deletions

View File

@@ -27,7 +27,7 @@ export class CreateAuth {
if (!this.password) {
throw new PasswordNeededError();
}
const found_user = await getConnectionManager().get().getRepository(User).findOne({ relations: ['groups', 'permissions'], where: [{ username: this.username }, { email: this.email }] });
const found_user = await getConnectionManager().get().getRepository(User).findOne({ relations: ['groups', 'permissions', 'groups.permissions'], where: [{ username: this.username }, { email: this.email }] });
if (!found_user) {
throw new UserNotFoundError();
}

View File

@@ -101,22 +101,11 @@ export class CreateUser {
if (!Array.isArray(this.group)) {
this.group = [this.group]
}
const groupIDs: number[] = this.group
let errors = 0
const validateusergroups = async () => {
for (const g of groupIDs) {
const found = await getConnectionManager().get().getRepository(UserGroup).find({ id: g });
if (found.length === 0) {
errors++
} else {
groups.push(found[0]);
}
}
return groups;
}
await validateusergroups()
if (errors !== 0) {
throw new UserGroupNotFoundError();
for (let group of this.group) {
let found = await getConnectionManager().get().getRepository(UserGroup).findOne({ id: group });
if (!found) { throw new UserGroupNotFoundError(); }
groups.push(found);
}
return groups;
}
}