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

View File

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