From 2438f117f00475a7869c71a1068f443ed4536bab Mon Sep 17 00:00:00 2001 From: Fig Yogurt Date: Wed, 17 Feb 2021 03:21:24 -0500 Subject: [PATCH] feat(analyze): added route and functionality to find sentences that match to the emotion you requested. --- server/controllers/analyze.controller.js | 28 ++++++++++++++++++++++++ server/routes/analyze.route.js | 6 +++++ 2 files changed, 34 insertions(+) diff --git a/server/controllers/analyze.controller.js b/server/controllers/analyze.controller.js index 8d75545..0d1fade 100644 --- a/server/controllers/analyze.controller.js +++ b/server/controllers/analyze.controller.js @@ -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, + }); + } +}; diff --git a/server/routes/analyze.route.js b/server/routes/analyze.route.js index b73f152..9a20c4c 100644 --- a/server/routes/analyze.route.js +++ b/server/routes/analyze.route.js @@ -2,6 +2,7 @@ const { searchEntries, searchSentences, detectAverageTone, + findSenToneMatch, } = require("../controllers/analyze.controller"); const { authJwt } = require("../middleware"); @@ -22,4 +23,9 @@ module.exports = function (app) { ); app.get("/api/analyze/averagetone", [authJwt.verifyToken], detectAverageTone); + app.get( + "/api/analyze/findToneMatch", + [authJwt.verifyToken], + findSenToneMatch + ); };