Refactoring: switched update user groups from objects to ids

ref #90
This commit is contained in:
Nicolai Ort 2021-01-15 18:35:21 +01:00
parent bae8290273
commit aa0fd9cafd
1 changed files with 4 additions and 5 deletions

View File

@ -79,11 +79,10 @@ export class UpdateUser {
enabled: boolean = true;
/**
* The updated user's groups.
* This just has to contain the group's id - everything else won't be changed.
* The updated user's groups' ids.
*/
@IsOptional()
groups?: UserGroup[]
groups?: number | number[]
/**
* The user's profile pic (or rather a url pointing to it).
@ -124,7 +123,7 @@ export class UpdateUser {
}
/**
* Loads the updated user's groups based on their ids.
* Get's all groups for this user by their id's;
*/
public async getGroups() {
if (!this.groups) { return null; }
@ -133,7 +132,7 @@ export class UpdateUser {
this.groups = [this.groups]
}
for (let group of this.groups) {
let found = await getConnectionManager().get().getRepository(UserGroup).findOne({ id: group.id });
let found = await getConnectionManager().get().getRepository(UserGroup).findOne({ id: group });
if (!found) { throw new UserGroupNotFoundError(); }
groups.push(found);
}