From ad19131883f02676f0858759442518166d7b607b Mon Sep 17 00:00:00 2001 From: Chris Steinmann <steinmann@infai.org> Date: Thu, 2 Sep 2021 15:15:45 +0200 Subject: [PATCH] #301 add query for userRoles --- app/src/helper/transect.service.ts | 38 +++++++++++++++++++++++++++++- app/src/views/TransectProfile.ts | 22 +++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/app/src/helper/transect.service.ts b/app/src/helper/transect.service.ts index 93f10356d..15ce4cea6 100644 --- a/app/src/helper/transect.service.ts +++ b/app/src/helper/transect.service.ts @@ -298,6 +298,8 @@ export class TransectService { /** * Update users for a transect + * @param transectId id of the transect e.g ("/transects/1") + * @param userIds ids of users that should be assigned to this transect (in a string array) */ public updateUsersForTransect = async (transectId: string, userIds: string[]) => { let userString = ""; @@ -323,7 +325,41 @@ export class TransectService { } } } - }` + }`; + return await ApiService.getInstance().postQuery(query); + } + + /** + * Update roles for a specific user + * @param userId id of the user which roles are to be changed e.g ("/tmd/api/index.php/users/1") + * @param userRoles roles that should be assigned to this user (in a string array) + */ + public updateUserRolesForTransect = async (userId: string, userRoles: string[]) => { + let userRolesString = ""; + for (const userId of userRoles) { + userRolesString = userRolesString + userId + ","; + }; + const query = `mutation { + updateUser ( + input: { + id: "${userId}" + userRoles: [ + "${userRolesString}" + ] + } + ) { + user { + id, + username, + userRoles { + collection { + id, + label + } + } + } + } + }`; return await ApiService.getInstance().postQuery(query); } } diff --git a/app/src/views/TransectProfile.ts b/app/src/views/TransectProfile.ts index ac83214e2..f79865922 100644 --- a/app/src/views/TransectProfile.ts +++ b/app/src/views/TransectProfile.ts @@ -167,6 +167,28 @@ export default class TransectManagement extends Vue { }); } + private async assignUserRolesToUser(userId: string) { + const userRoleIds: string[] = []; + for (const userRole of this.selectedRoles) { + userRoleIds.push(userRole.toString()); + } + return await TransectService.getInstance().updateUserRolesForTransect(userId, userRoleIds) + .then((response: AxiosResponse) => { + const isValidReponse = response && response.data && response.data.data; + if (isValidReponse) { + if (response.data.data.errors) { + this.showFailAlert(response.data.data.errors[0]); + } else { + this.showConfirmationAlert(); + this.requestTransectProfileData(); + } + } + this.delay(2000).then(() => { + this.showAssignDialog = false; + }); + }); + } + private delay(millis: number) { return new Promise((resolve) => setTimeout(resolve, millis)); } -- GitLab