Skip to content

Commit 7210584

Browse files
authored
fix: various fixes (#8)
* fix: return appropriate count for gallery images * fix: remove unnecessary console.log * fix: avoid sending theme in gallery and user arts endpoints * fix: remove files after art has been deleted
2 parents 3f6948c + 28c5348 commit 7210584

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

art-gallery/app/controllers/art.controller.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ const gallery = async (req, res) => {
4141
let { page, limit } = req.query;
4242
page = page || 1;
4343
limit = limit || 10;
44-
const count = await Art.countDocuments();
44+
const count = await Art.countDocuments({ published: true, reviewed: true });
4545

4646
const arts = await Art.find({ published: true, reviewed: true })
4747
.populate({ path: "artist", select: "id name" })
48-
.populate("theme")
4948
.skip((page - 1) * limit)
5049
.limit(limit);
5150

@@ -67,8 +66,6 @@ const gallery = async (req, res) => {
6766
};
6867

6968
const userArts = async (req, res) => {
70-
console.log("hi");
71-
7269
try {
7370
let { page, limit } = req.query;
7471
const { id } = req.params;
@@ -90,7 +87,6 @@ const userArts = async (req, res) => {
9087
const count = await Art.countDocuments({ artist: id });
9188
const arts = await Art.find({ artist: id })
9289
.populate({ path: "artist", select: "id name" })
93-
.populate("theme")
9490
.skip((page - 1) * limit)
9591
.limit(limit);
9692

@@ -423,6 +419,10 @@ const remove = async (req, res) => {
423419
message: "You are not authorized to perform this action.",
424420
});
425421
}
422+
423+
const filePath = path.join('public', art.image);
424+
fs.unlinkSync(filePath);
425+
426426
await Art.findOneAndDelete({ slug });
427427

428428
res.set('Content-Type', 'application/json');

0 commit comments

Comments
 (0)