processing / processing/p5.js-web-editor

Misleading function name in removeCollection controller

Open Beginner friendly
#3,806 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug
Dominant language
JavaScript
Stars
1.7k
Forks
1.7k
Avg merge
3d 4h
Merged PRs (30d)
8

Description

p5.js version

p5.js Web Editor (repository: p5.js-web-editor)

What is your operating system?

Mac OS

Web browser and version

Chrome / Firefox (any) — not browser-specific

Actual Behavior

In the backend collections controller, the file removeCollection.js
exports a function named createCollection.

However, the function:

  • Reads a collection ID from req.params
  • Finds an existing collection owned by the user
  • Calls deleteOne() on the collection

There is no collection creation logic in this function. The name
createCollection is misleading and does not reflect the actual behavior.

Expected Behavior

The controller function name should clearly reflect its behavior.
In this case, the function name should indicate that it removes (deletes)
a collection, matching the file name and route usage.

Steps to reproduce
Steps:
  1. Navigate to server/controllers/collection/collection.controller/removeCollection.js
  2. Observe that the exported function is named createCollection
  3. Review the function logic and note that it deletes an existing collection using deleteOne()
Snippet:
import Collection from '../../models/collection';

export default function createCollection(req, res) {
  const { id: collectionId } = req.params;
  const owner = req.user._id;

  function sendFailure({ code = 500, message = 'Something went wrong' }) {
    res.status(code).json({ success: false, message });
  }

  function sendSuccess() {
    res.status(200).json({ success: true });
  }

  function removeCollection(collection) {
    if (collection == null) {
      sendFailure({
        code: 404,
        message: 'Not found, or you user does not own this collection'
      });
      return null;
    }

    return collection.deleteOne();
  }

  function findCollection() {
    // Only returned if owner matches current user
    return Collection.findOne({ _id: collectionId, owner }).exec();
  }

  return findCollection()
    .then(removeCollection)
    .then(sendSuccess)
    .catch(sendFailure);
}


Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with server/controllers/collection/collection.controller/removeCollection.js and inspect its export and route usage. Confirm the function finds the owned collection and calls deleteOne(), then rename the exported function to reflect removal without changing its behavior. Done means the name matches the file and route references remain consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
85/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.