Skip to content

Commit

Permalink
Merge pull request #153 from dali-lab/add-blog-endpoint
Browse files Browse the repository at this point in the history
fix: fix removing image when post update was made without changing an image
  • Loading branch information
wu-ciesielska authored Nov 27, 2023
2 parents 5306afd + 46ac1c3 commit 3df7fb4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/controllers/blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ export const updateBlogPost = async (id, fields, uploadedFile) => {
try {
const postId = new mongoose.Types.ObjectId(id);

await Blog.updateOne(
{ _id: postId },
{ ...fields, image: uploadedFile?.path || null },
);
if (uploadedFile) {
const imagePath = getFilePath(uploadedFile?.path);
await Blog.updateOne({ _id: postId }, { ...fields, image: imagePath });
} else {
await Blog.updateOne({ _id: postId }, fields);
}

const blogPost = await Blog.findById(postId);

Expand Down

0 comments on commit 3df7fb4

Please sign in to comment.