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

View File

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