Refactor loan and user management components and backend routes
- Updated LoanTable component to fetch loan data from new API endpoint and display notes. - Enhanced UserTable component to include additional user fields (first name, last name, email, admin status) and updated input handling. - Modified fetcher utility to use new user data API endpoint. - Adjusted login functionality to point to the new admin login endpoint and handle unauthorized access. - Refactored user actions utility to align with updated API endpoints for user management. - Updated backend routes for user and loan data management to reflect new structure and naming conventions. - Revised SQL schema and mock data to accommodate new fields and constraints. - Changed Docker configuration to use the new database name.
This commit is contained in:
@@ -19,10 +19,10 @@ export const getAllApiKeys = async () => {
|
||||
return { success: false };
|
||||
};
|
||||
|
||||
export const createAPIentry = async (apiKey, user) => {
|
||||
export const createAPIentry = async (apiKey, entryName) => {
|
||||
const [result] = await pool.query(
|
||||
"INSERT INTO apiKeys (api_key, username) VALUES (?, ?)",
|
||||
[apiKey, user]
|
||||
"INSERT INTO apiKeys (api_key, entry_name) VALUES (?, ?)",
|
||||
[apiKey, entryName]
|
||||
);
|
||||
if (result.affectedRows > 0) return { success: true };
|
||||
return { success: false };
|
||||
|
||||
@@ -26,7 +26,7 @@ export const deleteItemById = async (itemId) => {
|
||||
export const createItem = async (item_name, can_borrow_role, in_safe) => {
|
||||
const [result] = await pool.query(
|
||||
"INSERT INTO items (item_name, can_borrow_role, in_safe) VALUES (?, ?, ?)",
|
||||
[item_name, can_borrow_role, in_safe]
|
||||
[item_name, can_borrow_role, true]
|
||||
);
|
||||
if (result.affectedRows > 0) return { success: true };
|
||||
return { success: false };
|
||||
@@ -34,9 +34,37 @@ export const createItem = async (item_name, can_borrow_role, in_safe) => {
|
||||
|
||||
export const editItemById = async (itemId, item_name, can_borrow_role) => {
|
||||
const [result] = await pool.query(
|
||||
"UPDATE items SET item_name = ?, can_borrow_role = ? WHERE id = ?",
|
||||
"UPDATE items SET item_name = ?, can_borrow_role = ?, entry_updated_at = NOW() WHERE id = ?",
|
||||
[item_name, can_borrow_role, itemId]
|
||||
);
|
||||
if (result.affectedRows > 0) return { success: true };
|
||||
return { success: false };
|
||||
};
|
||||
|
||||
export const changeSafeState = async (itemId) => {
|
||||
const currentState = await pool.query(
|
||||
"SELECT in_safe FROM items WHERE id = ?",
|
||||
[itemId]
|
||||
);
|
||||
if (currentState[0].length === 0) {
|
||||
return { success: false };
|
||||
}
|
||||
|
||||
if (currentState[0][0].in_safe) {
|
||||
const [result] = await pool.query(
|
||||
"UPDATE items SET in_safe = false WHERE id = ?",
|
||||
[itemId]
|
||||
);
|
||||
if (result.affectedRows > 0) return { success: true };
|
||||
}
|
||||
|
||||
if (!currentState[0][0].in_safe) {
|
||||
const [result] = await pool.query(
|
||||
"UPDATE items SET in_safe = true WHERE id = ?",
|
||||
[itemId]
|
||||
);
|
||||
if (result.affectedRows > 0) return { success: true };
|
||||
}
|
||||
|
||||
return { success: false };
|
||||
};
|
||||
|
||||
@@ -61,7 +61,7 @@ export const editUserById = async (
|
||||
|
||||
export const getAllUsers = async () => {
|
||||
const [result] = await pool.query(
|
||||
"SELECT id, username, first_name, last_name, role, email, is_admin FROM users"
|
||||
"SELECT id, username, first_name, last_name, role, email, is_admin, entry_created_at, entry_updated_at FROM users"
|
||||
);
|
||||
if (result.length > 0) return { success: true, data: result };
|
||||
return { success: false };
|
||||
|
||||
Reference in New Issue
Block a user