Skip to content

Commit

Permalink
Fix codacy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
KraPete committed Jan 22, 2025
1 parent a51203e commit 7e8a0c0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
4 changes: 3 additions & 1 deletion app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ async function getUserType(rolesFactory) {
if (response.status === 401) {
return 'login';
}
} catch (e) {}
} catch (e) {
/* empty */
}
rolesFactory.setRole('user', true);
return 'ok';
}
Expand Down
44 changes: 25 additions & 19 deletions app/scripts/react-directives/users/pageStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ class UsersPageStore {
this.users = users;
}

async execRequest(url, request) {
async fetchWrapper(fetchFn) {
try {
this.pageWrapperStore.clearError();
this.pageWrapperStore.setLoading(true);
const res = await fetch(url, request);
const res = await fetchFn();
if (res.ok) {
this.pageWrapperStore.setLoading(false);
return res;
Expand All @@ -157,13 +157,15 @@ class UsersPageStore {
if (!user) {
return;
}
const res = await this.execRequest('/auth/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(user),
});
const res = await this.fetchWrapper(() =>
fetch('/auth/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(user),
})
);
if (res === null) {
return;
}
Expand All @@ -187,13 +189,15 @@ class UsersPageStore {
if (!modifiedUser) {
return;
}
const res = await this.execRequest(`/auth/users/${user.id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(modifiedUser),
});
const res = await this.fetchWrapper(() =>
fetch(`/auth/users/${user.id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(modifiedUser),
})
);
if (res == null) {
return;
}
Expand All @@ -216,9 +220,11 @@ class UsersPageStore {

async deleteUser(user) {
if ((await this.showDeleteConfirmModal(user)) == 'ok') {
const res = await this.execRequest(`/auth/users/${user.id}`, {
method: 'DELETE',
});
const res = await this.fetchWrapper(() =>
fetch(`/auth/users/${user.id}`, {
method: 'DELETE',
})
);
if (res === null) {
return;
}
Expand Down

0 comments on commit 7e8a0c0

Please sign in to comment.