Skip to content

Commit

Permalink
fix(controllers): adjusted backend controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
HoseaCodes committed Mar 20, 2022
1 parent 30eed81 commit 27360a1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
14 changes: 3 additions & 11 deletions controllers/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ async function getArticle(req, res) {
status: 'success',
articles: articles,
result: articles.length,
location: 'main',

})
} catch (err) {

Expand Down Expand Up @@ -155,6 +157,7 @@ async function updateArticleComment(req, res) {
async function updateArticle(req, res) {
try {
const { title, subtitle, description, content, images, category } = req.body;
res.clearCookie('articles-cache');

if (!images) {

Expand Down Expand Up @@ -197,17 +200,6 @@ async function archiveArticle(req, res) {

logger.info(preparedLog);

res.cookie('archivedArticle-cache', archive.length + "archive", {
maxAge: 1000 * 60 * 60, // would expire after an hour
httpOnly: true, // The cookie only accessible by the web server
})

cache.set( archive.length + "archive", {
status: 'success',
archive: archive,
result: archive.length,
location: 'cache',
});
res.json({ msg: `Moved ${req.params.id} to archive`})
} catch (err) {

Expand Down
8 changes: 7 additions & 1 deletion controllers/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ async function getPayments(req, res) {
location: 'cache',
});

res.json(payments);
res.json(
{
status: 'success',
payments: payments,
result: payments.length,
location: 'main'
});
} catch (err) {
return res.status(500).json({ msg: err.message });
}
Expand Down
4 changes: 3 additions & 1 deletion controllers/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ async function getProducts(req, res) {

res.json({
status: 'success',
products: products,
result: products.length,
products: products
location: 'main',

})
} catch (err) {
return res.status(500).json({ msg: err.message })
Expand Down
3 changes: 3 additions & 0 deletions controllers/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ async function getAllUploads(req, res) {

res.json({
status: 'success',
location: 'main',
result: result,
});
});
Expand Down Expand Up @@ -88,6 +89,8 @@ async function destoryImage(req, res) {

if (!public_id) return res.status(400).json({ msg: 'No images Selected' });

res.clearCookie('cloudinary-cache');

await cloudinary.v2.uploader.destroy(public_id, async (err, result) => {
if (err) throw err;

Expand Down
15 changes: 13 additions & 2 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ async function getAllUsers(req, res) {
status: 'success',
users: users,
result: users.length,
location: 'main',

})
} catch (err) {

Expand Down Expand Up @@ -169,7 +171,11 @@ async function history(req, res) {
result: history,
location: 'cache',
});
return res.json(history);
return res.json({
status: 'success',
result: history,
location: 'main',
});
} catch (err) {
return res.status(500).json({ msg: err.message });
}
Expand All @@ -192,7 +198,12 @@ async function getUser(req, res) {
location: 'cache',
});

res.json(user);
res.json({
status: 'success',
users: user,
result: user.length,
location: 'main',
});
} catch (err) {
return res.status(500).json({ msg: err.message });
}
Expand Down

0 comments on commit 27360a1

Please sign in to comment.