async updateUser()

in src/lib/store/modules/user.store.js [56:129]


    async updateUser({commit, getters}, {clientId, username, firstName, lastName, email, realmRoles, clientRoles, attributes, deletedAttributes}) {
        if (deletedAttributes && deletedAttributes.length > 0) {
            await custosService.users.deleteUserAttributes({
                clientId,
                attributes: deletedAttributes,
                usernames: [username]
            });
        }

        if (attributes && attributes.length > 0) {
            await custosService.users.addUserAttribute({clientId, attributes, usernames: [username]});
        }

        if (realmRoles && realmRoles.length > 0) {
            await custosService.users.addRolesToUser({
                clientId,
                roles: realmRoles,
                usernames: [username],
                clientLevel: false
            });

            const realmRolesToBeDeleted = getters.getUser({
                clientId, username
            }).realmRoles.filter(realmRole => realmRoles.indexOf(realmRole) < 0);

            if (realmRolesToBeDeleted.length > 0) {
                await custosService.users.deleteRolesFromUser({
                    clientId,
                    roles: realmRolesToBeDeleted,
                    username: username,
                    clientLevel: false
                });
            }
        }

        if (clientRoles && clientRoles.length > 0) {
            await custosService.users.addRolesToUser({
                clientId,
                roles: clientRoles,
                usernames: [username],
                clientLevel: true
            });

            const clientRolesToBeDeleted = getters.getUser({
                clientId, username
            }).clientRoles.filter(clientRole => clientRoles.indexOf(clientRole) < 0);

            if (clientRolesToBeDeleted.length) {
                await custosService.users.deleteRolesFromUser({
                    clientId,
                    roles: clientRolesToBeDeleted,
                    username: username,
                    clientLevel: true
                });
            }
        }

        let updatedUser = await custosService.users.updateProfile({clientId, username, firstName, lastName, email});
        commit("SET_USER", {
            clientId,
            id: updatedUser.id,
            username: updatedUser.username,
            firstName: updatedUser.first_name,
            lastName: updatedUser.last_name,
            email: updatedUser.email,
            realmRoles: updatedUser.realm_roles,
            clientRoles: updatedUser.client_roles,
            attributes: updatedUser.attributes.map(({key, values}) => {
                return {key, values};
            }),
            membershipType: updatedUser.membership_type,
            status: updatedUser.state
        });
    }