Skip to content
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

Merged
merged 1 commit into from
May 18, 2024

Conversation

DaveLuhman
Copy link
Owner

@DaveLuhman DaveLuhman commented May 18, 2024

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.


This change is Reviewable

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.
@DaveLuhman DaveLuhman merged commit 9c409f0 into master May 18, 2024
2 of 5 checks passed
Copy link
Contributor

deepsource-io bot commented May 18, 2024

Here's the code health analysis summary for commits e6f0eba..59b3874. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource JavaScript LogoJavaScript❌ Failure
❗ 10 occurences introduced
🎯 4 occurences resolved
View Check ↗
DeepSource Docker LogoDocker✅ SuccessView Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

}

async function updateToolHistory(toolID) {
const oldTool = await Tool.findById(toolID)

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query object depends on a
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

This query object depends on a
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

This query object depends on a
user-provided value
.
Comment on lines +422 to +426
{
serviceAssignment: newServiceAssignment[i],
$inc: { __v: 1 },
$set: { updatedAt: Date.now() }
},

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query object depends on a
user-provided value
.
Comment on lines +168 to +181
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

Potential type confusion as
this HTTP request parameter
may be either an array or a string.
Comment on lines +259 to +271
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

Potential type confusion as
this HTTP request parameter
may be either an array or a string.
weight
} = req.body
const updatedTool = await Tool.findByIdAndUpdate(
{ $eq: id },

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query object depends on a
user-provided value
.
Comment on lines +274 to +289
{
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

This query object depends on a
user-provided value
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The server will crash on various error cases and does not inform the user what happened
1 participant