diff --git a/app/src/helper/transect.service.ts b/app/src/helper/transect.service.ts index 93f10356d27400668dd8aae4e3146772b33c29c6..15ce4cea60e2c29bcf69ee0520b0b7a7344b873e 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 ac83214e22d25c1059a43f262528243fa06e9f0e..f798659223e4c6fa7269ab340c7e2e4232efa1ef 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)); }