Skip to content

Commit

Permalink
Tried to fix old approach
Browse files Browse the repository at this point in the history
  • Loading branch information
tsunami776 committed Nov 1, 2023
1 parent c57e2ad commit 8036f37
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/controllers/dashBoardController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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(
Expand Down Expand Up @@ -247,6 +265,8 @@ const dashboardcontroller = function () {

return {
dashboarddata,
getDashBoardData,
updateDashboardData,
monthlydata,
weeklydata,
leaderboarddata,
Expand Down
10 changes: 10 additions & 0 deletions src/models/dashBoardData.js
Original file line number Diff line number Diff line change
@@ -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');
4 changes: 4 additions & 0 deletions src/routes/dashboardRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/startup/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ 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');
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);
Expand Down

0 comments on commit 8036f37

Please sign in to comment.