refactor user editing functionality to remove password handling
This commit is contained in:
@@ -237,7 +237,6 @@ const UserTable: React.FC = () => {
|
||||
user.id,
|
||||
user.username,
|
||||
user.role,
|
||||
user.password
|
||||
).then((response) => {
|
||||
if (response.success) {
|
||||
setError(
|
||||
|
@@ -24,19 +24,18 @@ export const handleDelete = async (userId: number) => {
|
||||
export const handleEdit = async (
|
||||
userId: number,
|
||||
username: string,
|
||||
role: string,
|
||||
password: string
|
||||
role: string
|
||||
) => {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`http://localhost:8002/api/editUser/${userId}`,
|
||||
{
|
||||
method: "PUT",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${Cookies.get("token")}`,
|
||||
},
|
||||
body: JSON.stringify({ username, role, password }),
|
||||
body: JSON.stringify({ username, role }),
|
||||
}
|
||||
);
|
||||
if (!response.ok) {
|
||||
|
@@ -224,10 +224,10 @@ router.get("/verifyToken", authenticate, async (req, res) => {
|
||||
res.status(200).json({ message: "Token is valid" });
|
||||
});
|
||||
|
||||
router.put("/editUser/:id", authenticate, async (req, res) => {
|
||||
router.post("/editUser/:id", authenticate, async (req, res) => {
|
||||
const userId = req.params.id;
|
||||
const { username, role, password } = req.body || {};
|
||||
const result = await handleEdit(userId, username, role, password);
|
||||
const { username, role } = req.body || {};
|
||||
const result = await handleEdit(userId, username, role);
|
||||
if (result.success) {
|
||||
return res.status(200).json({ message: "User edited successfully" });
|
||||
}
|
||||
|
@@ -340,10 +340,10 @@ export const deleteUserID = async (userId) => {
|
||||
return { success: false };
|
||||
};
|
||||
|
||||
export const handleEdit = async (userId, username, role, password) => {
|
||||
export const handleEdit = async (userId, username, role) => {
|
||||
const [result] = await pool.query(
|
||||
"UPDATE users SET username = ?, role = ?, password = ? WHERE id = ?",
|
||||
[username, role, password, userId]
|
||||
"UPDATE users SET username = ?, role = ? WHERE id = ?",
|
||||
[username, role, userId]
|
||||
);
|
||||
if (result.affectedRows > 0) return { success: true };
|
||||
return { success: false };
|
||||
|
Reference in New Issue
Block a user