Skip to content

Conversation

@pskodr
Copy link

@pskodr pskodr commented Jan 24, 2026

P1B: Starter Task: Refactoring PR

1. Issue

Link to Issue

Full path to refactored file:
src/controllers/search.js

What do you think this file does?
*This file contains the controller that handles search requests from NodeBB. It validates/checks the search parameters or input, as well as checks user access permissions for different types of search. It then calls the actual search file, and creates the view for the /search page. *

What is the scope of your refactoring within that file?
*I made refactors in the searchController.search function in the search.js file, which handles the user permissions of whether the user's priviledges permit the type of search performed. *

Which Qlty‑reported issue did you address?
complex binary expression: 36
complex binary expression: 37

2. Refactoring

How did the specific issue you chose impact the codebase’s maintainability?
The specific issue I chose was not a logical issue, but rather a restructuring one. Initially, it used several conditional statements in one single line, which could potentially increase memory run time, and has unclear logic, which leads to the triggering of the complex binary expression code smell, thus contributing to less maintainability.

What changes did you make to resolve the issue?
I split the conditional statements into individual scope checks, by declaring constant variables with descriptive names (inUsers, inTags, etc.) to help distinguish the checks used in the conditional statement. Then, I simply checked all the conditions with the variable 'allowed', and check it with a simple if(!allowed) statement.

How do your changes improve maintainability? Did you consider alternatives?
My code changes improve maintainability be eliminating the complex binary expression smell, breaking down the conditional statement check into intuitively named constants, which are then combined for a simple conditional check. I think this was an efficient way to solve the problem, as it keeps the logic the same, but simply makes it more intuitive to read and reduces the load in the statement.

3. Validation

How did you trigger the refactored code path from the UI?

  • Log into NodeBB account
  • go to http://localhost:4567/search (trigger by replacing link in address bar)
  • enter any input text into search bar in the "Type to Search" area.
  • press enter or search button

Attach a screenshot of the logs and UI demonstrating the trigger.
Relevant UI:
pchivatx-ui
Logs: (Phasakorn Chivatxaranukul printed when search is made)
console-log
Qlty Smells Output: (complex binary expression: 36, 37 are not in the output anymore)
qlty-smells-output

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.

1 participant