Skip to content

Commit

Permalink
feat(entry): listAll route is made and it gives a user all their entr…
Browse files Browse the repository at this point in the history
…ies and the overall mood for each one
  • Loading branch information
Ali-Aftab committed Feb 16, 2021
1 parent e9d521a commit 5721bdf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
22 changes: 21 additions & 1 deletion server/controllers/entry.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ exports.postNewEntry = async (req, res) => {
});
} catch (error) {
console.log(error);
return res.json({ message: "Error occured when saving new Entry post" });
return res.json({
message: "Error occured when saving new Entry post",
error,
});
}
};

exports.listAllUserEntry = async (req, res) => {
try {
const { count, rows } = await EntryTone.findAndCountAll({
where: {
userId: req.userId,
},
});
res.json({ message: `You have ${count} entries!`, data: rows });
} catch (error) {
console.log(error);
res.json({
error,
message: "Error occured when grabbing all of your diary entries",
});
}
};
7 changes: 6 additions & 1 deletion server/routes/entry.route.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const { postNewEntry } = require("../controllers/entry.controller");
const {
postNewEntry,
listAllUserEntry,
} = require("../controllers/entry.controller");
const { authJwt, sendEntryToIBM } = require("../middleware");

module.exports = function (app) {
Expand All @@ -16,4 +19,6 @@ module.exports = function (app) {
sendEntryToIBM,
postNewEntry
);

app.get("/api/entry/listAll", [authJwt.verifyToken], listAllUserEntry);
};

0 comments on commit 5721bdf

Please sign in to comment.