-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor tool management and search functionality #184
Conversation
Refactored code in `tool.js` to enhance readability, maintainability, and efficiency. Standardized functions for checking in and out tools, searching tools, creating and updating tool entries, and archiving tools. Improved error handling and validation across the board to ensure robustness. Default values for `serviceAssignment` and `category` in `Tool.model.js` were set to prevent issues with tool creation where these fields might be undefined, improving data integrity and user experience when interacting with the tool management system. Additionally, introduced a bulk update mechanism and optimized tool lookup to reduce load times and improve efficiency when processing large sets of tools. These changes aim to streamline the tool management process, making it more intuitive and less error-prone for users. - Set default values for `serviceAssignment` and `category` in `Tool` model to improve tool creation UX. - Cleaned up and documented middleware functions for better maintainability. - Implemented better error handling and validation for tool operations to enhance system robustness. These improvements directly address usability concerns and potential data inconsistencies, markedly enhancing the application's overall functionality and user satisfaction.
Here's the code health analysis summary for commits Analysis Summary
|
} | ||
|
||
async function updateToolHistory(toolID) { | ||
const oldTool = await Tool.findById(toolID) |
Check failure
Code scanning / CodeQL
Database query built from user-controlled sources High
user-provided value
This query object depends on a
user-provided value
async function updateToolHistory(toolID) { | ||
const oldTool = await Tool.findById(toolID) | ||
await ToolHistory.findByIdAndUpdate( | ||
{ _id: toolID }, |
Check failure
Code scanning / CodeQL
Database query built from user-controlled sources High
user-provided value
This query object depends on a
user-provided value
updateToolHistory(id[i]) | ||
newTools.push( | ||
await Tool.findByIdAndUpdate( | ||
{ _id: id[i] }, |
Check failure
Code scanning / CodeQL
Database query built from user-controlled sources High
user-provided value
{ | ||
serviceAssignment: newServiceAssignment[i], | ||
$inc: { __v: 1 }, | ||
$set: { updatedAt: Date.now() } | ||
}, |
Check failure
Code scanning / CodeQL
Database query built from user-controlled sources High
user-provided value
const { | ||
serialNumber, | ||
modelNumber, | ||
barcode, | ||
description, | ||
toolID, | ||
serviceAssignment, | ||
category, | ||
manufacturer, | ||
width, | ||
height, | ||
length, | ||
weight | ||
} = req.body |
Check failure
Code scanning / CodeQL
Type confusion through parameter tampering Critical
this HTTP request parameter
const { | ||
id, | ||
modelNumber, | ||
description, | ||
toolID, | ||
serviceAssignment, | ||
category, | ||
manufacturer, | ||
width, | ||
height, | ||
length, | ||
weight | ||
} = req.body |
Check failure
Code scanning / CodeQL
Type confusion through parameter tampering Critical
this HTTP request parameter
weight | ||
} = req.body | ||
const updatedTool = await Tool.findByIdAndUpdate( | ||
{ $eq: id }, |
Check failure
Code scanning / CodeQL
Database query built from user-controlled sources High
user-provided value
{ | ||
modelNumber, | ||
barcode, | ||
description, | ||
toolID, | ||
serviceAssignment, | ||
category, | ||
serviceAssignment: serviceAssignment, | ||
category: category, | ||
manufacturer, | ||
size: { | ||
height, | ||
width, | ||
height, | ||
length, | ||
weight | ||
}, | ||
updatedBy: req.user._id, | ||
createdBy: req.user._id | ||
}) | ||
if (!newTool) { | ||
throw new Error({ message: 'Could not create tool', status: 500 }) | ||
} | ||
await ToolHistory.create({ | ||
_id: newTool._id, | ||
history: [newTool] | ||
}) | ||
res.locals.message = 'Successfully Made A New Tool' | ||
res.locals.tools = [newTool] | ||
res.locals.pagination = { pageCount: 1 } | ||
res.status(201) | ||
console.info(`[MW] Tool Successfully Created ${newTool._id}`.green) | ||
console.info('[MW] createTool-out-3'.bgWhite.blue) | ||
next() | ||
} catch (error) { | ||
res.locals.message = error.message | ||
res.status(error.status || 500).redirect('back') | ||
} | ||
} | ||
|
||
async function updateToolHistory(toolID) { | ||
const oldTool = await Tool.findById(toolID) | ||
await ToolHistory.findByIdAndUpdate( | ||
{ _id: toolID }, | ||
{ | ||
$push: { history: oldTool }, | ||
$inc: { __v: 1 }, | ||
$set: { updatedAt: Date.now() } | ||
} | ||
}, |
Check failure
Code scanning / CodeQL
Database query built from user-controlled sources High
Refactored code in
tool.js
to enhance readability, maintainability, and efficiency. Standardized functions for checking in and out tools, searching tools, creating and updating tool entries, and archiving tools. Improved error handling and validation across the board to ensure robustness. Default values forserviceAssignment
andcategory
inTool.model.js
were set to prevent issues with tool creation where these fields might be undefined, improving data integrity and user experience when interacting with the tool management system. Additionally, introduced a bulk update mechanism and optimized tool lookup to reduce load times and improve efficiency when processing large sets of tools. These changes aim to streamline the tool management process, making it more intuitive and less error-prone for users.serviceAssignment
andcategory
inTool
model to improve tool creation UX.These improvements directly address usability concerns and potential data inconsistencies, markedly enhancing the application's overall functionality and user satisfaction.
This change is