From 8036f37181e6f41b064d702357d542d0b90aac45 Mon Sep 17 00:00:00 2001 From: tsunami776 <43768723+tsunami776@users.noreply.github.com> Date: Tue, 31 Oct 2023 20:07:56 -0500 Subject: [PATCH] Tried to fix old approach --- src/controllers/dashBoardController.js | 20 ++++++++++++++++++++ src/models/dashBoardData.js | 10 ++++++++++ src/routes/dashboardRouter.js | 4 ++++ src/startup/routes.js | 3 ++- 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/models/dashBoardData.js diff --git a/src/controllers/dashBoardController.js b/src/controllers/dashBoardController.js index c9cdbd588..3a203481f 100644 --- a/src/controllers/dashBoardController.js +++ b/src/controllers/dashBoardController.js @@ -3,6 +3,7 @@ const path = require("path"); const fs = require("fs/promises"); const dashboardhelper = require("../helpers/dashboardhelper")(); const emailSender = require("../utilities/emailSender"); +const DashboardData = require('../models/dashBoardData'); const dashboardcontroller = function () { const dashboarddata = function (req, res) { @@ -15,6 +16,23 @@ const dashboardcontroller = function () { }); }; + const updateDashboardData = function (req, res) { + if (req.body.requestor.role === 'Owner') { + DashboardData.findOneAndUpdate({ _id: 'ai-prompt' }, { ...req.body, aIPromptText: req.body.aIPromptText }) + .then(() => { + res.status(200).send('Successfully saved AI prompt.'); + }).catch(error => res.status(500).send(error)); + } + }; + + const getDashBoardData = function (req, res) { + DashboardData.findById({ _id: 'ai-prompt' }) + .then((results) => { + res.status(200).send(results); + }) + .catch(error => res.status(500).send(error)); + }; + const monthlydata = function (req, res) { const userId = mongoose.Types.ObjectId(req.params.userId); const laborthismonth = dashboardhelper.laborthismonth( @@ -247,6 +265,8 @@ const dashboardcontroller = function () { return { dashboarddata, + getDashBoardData, + updateDashboardData, monthlydata, weeklydata, leaderboarddata, diff --git a/src/models/dashBoardData.js b/src/models/dashBoardData.js new file mode 100644 index 000000000..2ae3a5482 --- /dev/null +++ b/src/models/dashBoardData.js @@ -0,0 +1,10 @@ +const mongoose = require('mongoose'); + +const { Schema } = mongoose; + +const DashboardData = new Schema({ + _id: { type: mongoose.Schema.Types.String }, + aIPromptText: { type: String }, +}); + +module.exports = mongoose.model('dashboardData', DashboardData, 'dashboard'); diff --git a/src/routes/dashboardRouter.js b/src/routes/dashboardRouter.js index 664c1c802..7b55fcb89 100644 --- a/src/routes/dashboardRouter.js +++ b/src/routes/dashboardRouter.js @@ -5,6 +5,10 @@ const route = function () { const Dashboardrouter = express.Router(); + Dashboardrouter.route('/dashboard/aiPrompt') + .get(controller.getDashBoardData) + .put(controller.updateDashboardData); + Dashboardrouter.route('/dashboard/:userId') .get(controller.dashboarddata); diff --git a/src/startup/routes.js b/src/startup/routes.js index 2fd7337a6..41b63a5ec 100644 --- a/src/startup/routes.js +++ b/src/startup/routes.js @@ -18,6 +18,7 @@ const role = require('../models/role'); const rolePreset = require('../models/rolePreset'); const ownerMessage = require('../models/ownerMessage'); const ownerStandardMessage = require('../models/ownerStandardMessage'); +const dashboardData = require('../models/dashBoardData'); const profileInitialSetuptoken = require('../models/profileInitialSetupToken'); const reason = require('../models/reason'); const mouseoverText = require('../models/mouseoverText'); @@ -25,7 +26,7 @@ const inventoryItemMaterial = require('../models/inventoryItemMaterial'); const userProfileRouter = require('../routes/userProfileRouter')(userProfile); const badgeRouter = require('../routes/badgeRouter')(badge); -const dashboardRouter = require('../routes/dashboardRouter')(); +const dashboardRouter = require('../routes/dashboardRouter')(dashboardData); const timeEntryRouter = require('../routes/timeentryRouter')(timeEntry); const projectRouter = require('../routes/projectRouter')(project); const informationRouter = require('../routes/informationRouter')(information);