-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
BugError or unexpected behaviorsError or unexpected behaviors
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:
- Navigate to
server/controllers/collection/collection.controller/removeCollection.js - Observe that the exported function is named
createCollection - 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);
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugError or unexpected behaviorsError or unexpected behaviors