NexGenStudioDev / NexGenStudioDev/Ciitm-Backend

Update Album Delete Endpoint to Remove All Related Images

Open
#47 7 comments 0 reactions 1 assignee View on GitHub

@xt42io is already working on this.

Since Jul 30, 2025.

API auth backend duplicate enhancement good first issue jest onlydust-wave testing
Dominant language
JavaScript
Stars
1
Forks
17
PR merge metrics
No merged PRs in 30d

Description

📌 Description

We need to update the album delete API endpoint so that when a user deletes an album:

  • ✅ The album gets deleted from the database
  • ✅ All images related to that album are also removed from the database
  • ✅ All images are also deleted from Cloudinary (where they are hosted)

📂 Current Problem

  • When an album is deleted, the album gets removed.
  • But the images related to that album may still stay in the database or remain in Cloudinary.
  • This causes unnecessary storage use and data inconsistency.

✅ What Needs to Be Done

  1. Find all images related to the album in the database using the album ID or reference.
  2. Delete those images from Cloudinary using their public IDs.
  3. Delete those image documents from the database.
  4. Finally, delete the album from the database.

🧠 Logic (Simple Steps):

// Example (pseudo-code)
const album = await Album.findById(albumId);
const images = await Image.find({ album: albumId });

// 1. Delete images from Cloudinary
for (let image of images) {
  await cloudinary.uploader.destroy(image.public_id);
}

// 2. Delete image records from DB
await Image.deleteMany({ album: albumId });

// 3. Delete album from DB
await Album.findByIdAndDelete(albumId);


🧪 How to Test

Create an album and upload multiple images to it.

  • Then call the delete album endpoint.

  • ✅ Check if the album is removed from the DB.

  • ✅ Check if related images are deleted from both the DB and Cloudinary.

💡 Additional Suggestions

  • Add error handling for:

  • Cloudinary failures (e.g., retry or log)

  • Missing images or album

  • Optional: Add a confirmation step or warning before permanent deletion (for UI).

  • Optional: Add logging for deleted files (filename, public ID, etc.)

⏰ Priority: High

This is important to prevent junk data and unnecessary Cloudinary usage, which can increase storage cost.

#£ 🔁 Related Endpoints

DELETE /api/v1/admin/album/delete/AlbumId=

DELETE /api/images (or wherever images are stored)

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.