Skip to content
Snippets Groups Projects
Commit ad191318 authored by Chris Steinmann's avatar Chris Steinmann
Browse files

#301 add query for userRoles

parent 51f62f9d
No related branches found
No related tags found
2 merge requests!314Merging for 0.8.1 Hotfix,!286Resolve "Transektsteckbrief: Zuweisung/Änderungsmöglichkeit eines Nutzers zum Transekt und seine Rolle zum Transekt"
Pipeline #421037 failed
......@@ -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);
}
}
......@@ -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));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment