feat: endpoint get all users connected

This commit is contained in:
Angie 2025-07-25 00:26:49 +02:00
parent bc585465ce
commit aea23f7776
2 changed files with 67 additions and 64 deletions

View File

@ -108,6 +108,7 @@ function logout() {
document.getElementById("logoutBtn").addEventListener("click", logout);
document.getElementById("adminLogoutBtn").addEventListener("click", logout);
//Users
//GET all users (admin only)
async function getAllUsers() {
@ -140,6 +141,8 @@ async function loadUsers() {
const result = await getAllUsers();
console.log("getAllUsers result:", result);
if (!result.success) {
showNotification(result.error, "error");
return;

View File

@ -248,27 +248,27 @@ function showAdminInterface() {
}
// Загрузка магазинов для пользователя
// function loadUserStores() {
// const select = document.getElementById("storeSelect");
// select.innerHTML = '<option value="">Выберите магазин</option>';
function loadUserStores() {
const select = document.getElementById("storeSelect");
select.innerHTML = '<option value="">Выберите магазин</option>';
// let userStores = [];
let userStores = [];
// if (currentUser.role === "admin") {
// userStores = database.stores;
// } else {
// userStores = database.stores.filter((store) =>
// currentUser.stores.includes(store.id)
// );
// }
if (currentUser.role === "admin") {
userStores = database.stores;
} else {
userStores = database.stores.filter((store) =>
currentUser.stores.includes(store.id)
);
}
// userStores.forEach((store) => {
// const option = document.createElement("option");
// option.value = store.id;
// option.textContent = store.name;
// select.appendChild(option);
// });
// }
userStores.forEach((store) => {
const option = document.createElement("option");
option.value = store.id;
option.textContent = store.name;
select.appendChild(option);
});
}
// Настройка автоматических расчетов в форме
function setupFormCalculations() {
@ -1382,54 +1382,54 @@ function exportToExcel() {
// === УПРАВЛЕНИЕ ПОЛЬЗОВАТЕЛЯМИ ===
// Загрузка пользователей
function loadUsers() {
const tbody = document.getElementById("usersTableBody");
tbody.innerHTML = "";
// function loadUsers() {
// const tbody = document.getElementById("usersTableBody");
// tbody.innerHTML = "";
database.users.forEach((user) => {
const userStores = database.stores.filter((s) =>
user.stores.includes(s.id)
);
const storeNames =
userStores.map((s) => s.name).join(", ") || "Нет доступа";
// database.users.forEach((user) => {
// const userStores = database.stores.filter((s) =>
// user.stores.includes(s.id)
// );
// const storeNames =
// userStores.map((s) => s.name).join(", ") || "Нет доступа";
const row = document.createElement("tr");
row.className = "hover:bg-gray-50";
row.innerHTML = `
<td class="px-6 py-4 text-sm text-gray-900">${user.id}</td>
<td class="px-6 py-4 text-sm text-gray-900">${
user.username
}</td>
<td class="px-6 py-4 text-sm">
<span class="px-2 py-1 text-xs rounded-full ${
user.role === "admin"
? "bg-purple-100 text-purple-800"
: "bg-blue-100 text-blue-800"
}">
${
user.role === "admin"
? "Администратор"
: "Сотрудник"
}
</span>
</td>
<td class="px-6 py-4 text-sm text-gray-900">${storeNames}</td>
<td class="px-6 py-4 text-sm">
<button class="text-blue-600 hover:text-blue-900 mr-2" onclick="editUser(${
user.id
})">
<i class="fas fa-edit"></i> Редактировать
</button>
<button class="text-red-600 hover:text-red-900" onclick="deleteUser(${
user.id
})">
<i class="fas fa-trash"></i> Удалить
</button>
</td>
`;
tbody.appendChild(row);
});
}
// const row = document.createElement("tr");
// row.className = "hover:bg-gray-50";
// row.innerHTML = `
// <td class="px-6 py-4 text-sm text-gray-900">${user.id}</td>
// <td class="px-6 py-4 text-sm text-gray-900">${
// user.username
// }</td>
// <td class="px-6 py-4 text-sm">
// <span class="px-2 py-1 text-xs rounded-full ${
// user.role === "admin"
// ? "bg-purple-100 text-purple-800"
// : "bg-blue-100 text-blue-800"
// }">
// ${
// user.role === "admin"
// ? "Администратор"
// : "Сотрудник"
// }
// </span>
// </td>
// <td class="px-6 py-4 text-sm text-gray-900">${storeNames}</td>
// <td class="px-6 py-4 text-sm">
// <button class="text-blue-600 hover:text-blue-900 mr-2" onclick="editUser(${
// user.id
// })">
// <i class="fas fa-edit"></i> Редактировать
// </button>
// <button class="text-red-600 hover:text-red-900" onclick="deleteUser(${
// user.id
// })">
// <i class="fas fa-trash"></i> Удалить
// </button>
// </td>
// `;
// tbody.appendChild(row);
// });
// }
// Добавление пользователя
document.addEventListener("DOMContentLoaded", function () {