-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #738 from OneCommunityGlobal/development
Backend Release to Main [1.42]
- Loading branch information
Showing
8 changed files
with
162 additions
and
88 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
const path = require('path'); | ||
const fs = require('fs/promises'); | ||
const mongoose = require('mongoose'); | ||
const dashboardhelper = require('../helpers/dashboardhelper')(); | ||
const emailSender = require('../utilities/emailSender'); | ||
const AIPrompt = require('../models/weeklySummaryAIPrompt'); | ||
/* eslint-disable quotes */ | ||
const path = require("path"); | ||
const fs = require("fs/promises"); | ||
const mongoose = require("mongoose"); | ||
const dashboardhelper = require("../helpers/dashboardhelper")(); | ||
const emailSender = require("../utilities/emailSender"); | ||
const AIPrompt = require("../models/weeklySummaryAIPrompt"); | ||
const User = require("../models/userProfile"); | ||
|
||
const dashboardcontroller = function () { | ||
const dashboarddata = function (req, res) { | ||
|
@@ -15,38 +17,72 @@ const dashboardcontroller = function () { | |
res.status(200).send(results); | ||
}); | ||
}; | ||
|
||
// The Code below updates the time the AiPrompt was copied by the user - Sucheta | ||
// eslint-disable-next-line space-before-blocks | ||
const updateCopiedPrompt = function (req, res) { | ||
return User.findOneAndUpdate( | ||
{ _id: req.params.userId }, | ||
{ copiedAiPrompt: Date.now() }, | ||
{ new: true }, | ||
) | ||
.then((user) => { | ||
if (user) { | ||
res.status(200).send('Copied AI prompt'); | ||
} else { | ||
res.status(404).send({ message: 'User not found ' }); | ||
} | ||
}) | ||
.catch((error) => { | ||
res.status(500).send(error); | ||
}); | ||
}; | ||
const getPromptCopiedDate = function (req, res) { | ||
return User.findOne({ _id: req.params.userId }).then((user) => { | ||
if (user) { | ||
res.status(200).send({ message: user.copiedAiPrompt }); | ||
} | ||
}); | ||
}; | ||
const updateAIPrompt = function (req, res) { | ||
if (req.body.requestor.role === 'Owner') { | ||
AIPrompt.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)); | ||
if (req.body.requestor.role === "Owner") { | ||
AIPrompt.findOneAndUpdate( | ||
{ _id: "ai-prompt" }, | ||
{ | ||
...req.body, | ||
aIPromptText: req.body.aIPromptText, | ||
modifiedDatetime: Date.now(), | ||
}, | ||
) | ||
.then(() => { | ||
res.status(200).send("Successfully saved AI prompt."); | ||
}) | ||
.catch(error => res.status(500).send(error)); | ||
} | ||
}; | ||
|
||
const getAIPrompt = function (req, res) { | ||
AIPrompt.findById({ _id: 'ai-prompt' }) | ||
.then((result) => { | ||
if (result) { | ||
// If the GPT prompt exists, send it back. | ||
res.status(200).send(result); | ||
} else { | ||
// If the GPT prompt does not exist, create it. | ||
const defaultPrompt = { | ||
_id: 'ai-prompt', | ||
aIPromptText: "Please edit the following summary of my week's work. Make sure it is professionally written in 3rd person format.\nWrite it as only one paragraph. It must be only one paragraph. Keep it less than 500 words. Start the paragraph with 'This week'.\nMake sure the paragraph contains no links or URLs and write it in a tone that is matter-of-fact and without embellishment.\nDo not add flowery language, keep it simple and factual. Do not add a final summary sentence. Apply all this to the following:", | ||
}; | ||
AIPrompt.create(defaultPrompt) | ||
.then((newResult) => { | ||
res.status(200).send(newResult); | ||
}) | ||
.catch((creationError) => { | ||
res.status(500).send(creationError); | ||
}); | ||
} | ||
}) | ||
.catch(error => res.status(500).send(error)); | ||
AIPrompt.findById({ _id: "ai-prompt" }) | ||
.then((result) => { | ||
if (result) { | ||
// If the GPT prompt exists, send it back. | ||
res.status(200).send(result); | ||
} else { | ||
// If the GPT prompt does not exist, create it. | ||
const defaultPrompt = { | ||
_id: "ai-prompt", | ||
aIPromptText: | ||
"Please edit the following summary of my week's work. Make sure it is professionally written in 3rd person format.\nWrite it as only one paragraph. It must be only one paragraph. Keep it less than 500 words. Start the paragraph with 'This week'.\nMake sure the paragraph contains no links or URLs and write it in a tone that is matter-of-fact and without embellishment.\nDo not add flowery language, keep it simple and factual. Do not add a final summary sentence. Apply all this to the following:", | ||
}; | ||
AIPrompt.create(defaultPrompt) | ||
.then((newResult) => { | ||
res.status(200).send(newResult); | ||
}) | ||
.catch((creationError) => { | ||
res.status(500).send(creationError); | ||
}); | ||
} | ||
}) | ||
.catch(error => res.status(500).send(error)); | ||
}; | ||
|
||
const monthlydata = function (req, res) { | ||
|
@@ -60,7 +96,7 @@ const dashboardcontroller = function () { | |
if (!results || results.length === 0) { | ||
const emptyresult = [ | ||
{ | ||
projectName: '', | ||
projectName: "", | ||
timeSpent_hrs: 0, | ||
}, | ||
]; | ||
|
@@ -169,27 +205,27 @@ const dashboardcontroller = function () { | |
|
||
try { | ||
emailSender( | ||
'[email protected]', | ||
"[email protected]", | ||
`Bug Rport from ${firstName} ${lastName}`, | ||
emailBody, | ||
email, | ||
); | ||
res.status(200).send('Success'); | ||
res.status(200).send("Success"); | ||
} catch { | ||
res.status(500).send('Failed'); | ||
res.status(500).send("Failed"); | ||
} | ||
}; | ||
|
||
const suggestionData = { | ||
suggestion: [ | ||
'Identify and remedy poor client and/or user service experiences', | ||
'Identify bright spots and enhance positive service experiences', | ||
'Make fundamental changes to our programs and/or operations', | ||
'Inform the development of new programs/projects', | ||
'Identify where we are less inclusive or equitable across demographic groups', | ||
'Strengthen relationships with the people we serve', | ||
"Identify and remedy poor client and/or user service experiences", | ||
"Identify bright spots and enhance positive service experiences", | ||
"Make fundamental changes to our programs and/or operations", | ||
"Inform the development of new programs/projects", | ||
"Identify where we are less inclusive or equitable across demographic groups", | ||
"Strengthen relationships with the people we serve", | ||
"Understand people's needs and how we can help them achieve their goals", | ||
'Other', | ||
"Other", | ||
], | ||
field: [], | ||
}; | ||
|
@@ -212,7 +248,7 @@ const dashboardcontroller = function () { | |
<p>${args[0]}</p> | ||
<b> ⚹ Suggestion:</b> | ||
<p>${args[1]}</p> | ||
${fieldaaray.length > 0 ? fieldaaray : ''} | ||
${fieldaaray.length > 0 ? fieldaaray : ""} | ||
<b> ⚹ Name of Suggester:</b> | ||
<p>${args[3].firstName} ${args[3].lastName}</p> | ||
<b> ⚹ Email of Suggester:</b> | ||
|
@@ -239,17 +275,17 @@ const dashboardcontroller = function () { | |
); | ||
try { | ||
emailSender( | ||
'[email protected]', | ||
'A new suggestion', | ||
"[email protected]", | ||
"A new suggestion", | ||
emailBody, | ||
null, | ||
null, | ||
email, | ||
null, | ||
); | ||
res.status(200).send('Success'); | ||
res.status(200).send("Success"); | ||
} catch { | ||
res.status(500).send('Failed'); | ||
res.status(500).send("Failed"); | ||
} | ||
}; | ||
|
||
|
@@ -258,40 +294,40 @@ const dashboardcontroller = function () { | |
if (suggestionData) { | ||
res.status(200).send(suggestionData); | ||
} else { | ||
res.status(404).send('Suggestion data not found.'); | ||
res.status(404).send("Suggestion data not found."); | ||
} | ||
} catch (error) { | ||
console.error('Error getting suggestion data:', error); | ||
res.status(500).send('Internal Server Error'); | ||
console.error("Error getting suggestion data:", error); | ||
res.status(500).send("Internal Server Error"); | ||
} | ||
}; | ||
|
||
const editSuggestionOption = async (req, res) => { | ||
try { | ||
if (req.body.suggestion) { | ||
if (req.body.action === 'add') { | ||
if (req.body.action === "add") { | ||
suggestionData.suggestion.unshift(req.body.newField); | ||
} | ||
if (req.body.action === 'delete') { | ||
if (req.body.action === "delete") { | ||
suggestionData.suggestion = suggestionData.suggestion.filter( | ||
(item, index) => index + 1 !== +req.body.newField, | ||
); | ||
} | ||
} else { | ||
if (req.body.action === 'add') { | ||
if (req.body.action === "add") { | ||
suggestionData.field.unshift(req.body.newField); | ||
} | ||
if (req.body.action === 'delete') { | ||
if (req.body.action === "delete") { | ||
suggestionData.field = suggestionData.field.filter( | ||
item => item !== req.body.newField, | ||
); | ||
} | ||
} | ||
|
||
res.status(200).send('success'); | ||
res.status(200).send("success"); | ||
} catch (error) { | ||
console.error('Error editing suggestion option:', error); | ||
res.status(500).send('Internal Server Error'); | ||
console.error("Error editing suggestion option:", error); | ||
res.status(500).send("Internal Server Error"); | ||
} | ||
}; | ||
|
||
|
@@ -307,6 +343,8 @@ const dashboardcontroller = function () { | |
getSuggestionOption, | ||
editSuggestionOption, | ||
sendMakeSuggestion, | ||
updateCopiedPrompt, | ||
getPromptCopiedDate, | ||
}; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.