Skip to content

Commit

Permalink
feat(analyze): added route and functionality to find sentences that m…
Browse files Browse the repository at this point in the history
…atch to the emotion you requested.
  • Loading branch information
Ali-Aftab committed Feb 17, 2021
1 parent 0c20726 commit 2438f11
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions server/controllers/analyze.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,31 @@ module.exports.detectAverageTone = async (req, res) => {
});
}
};

module.exports.findSenToneMatch = async (req, res) => {
try {
const { userId } = req;
if (!req.body.tone) {
return res.json({ message: "Please type a proper tone in the body!" });
}
const allSentences = await SentenceTone.findAll({
where: {
userId,
[req.body.tone]: {
[Op.gte]: 0.5,
},
},
});
res.json({
message: `We have bits of your entires that you emit ${req.body.tone}`,
data: allSentences,
});
} catch (error) {
console.log(error);
res.json({
message:
"Error occured when trying to find sentences that match to the emotion!",
error,
});
}
};
6 changes: 6 additions & 0 deletions server/routes/analyze.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const {
searchEntries,
searchSentences,
detectAverageTone,
findSenToneMatch,
} = require("../controllers/analyze.controller");
const { authJwt } = require("../middleware");

Expand All @@ -22,4 +23,9 @@ module.exports = function (app) {
);

app.get("/api/analyze/averagetone", [authJwt.verifyToken], detectAverageTone);
app.get(
"/api/analyze/findToneMatch",
[authJwt.verifyToken],
findSenToneMatch
);
};

0 comments on commit 2438f11

Please sign in to comment.