p5.js-web-editor icon indicating copy to clipboard operation
p5.js-web-editor copied to clipboard

Misleading function name in removeCollection controller

Open jjnawaaz opened this issue 10 months ago • 3 comments

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);
}


jjnawaaz avatar Jan 21 '26 16:01 jjnawaaz

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already.

welcome[bot] avatar Jan 21 '26 16:01 welcome[bot]

hey i want to fix this issue can you pls assign me this issue

msudipta888 avatar Jan 27 '26 05:01 msudipta888

hi @raclim , if this issue is still being assigned, I would love to work on this

Kavya-Goyal-kcoder005 avatar Sep 11 '26 06:09 Kavya-Goyal-kcoder005