Skip to content

Commit

Permalink
Merge pull request #578 from OneCommunityGlobal/development
Browse files Browse the repository at this point in the history
Backend Release to Main [1.10]
  • Loading branch information
one-community authored Oct 19, 2023
2 parents 2351efb + 1df6d73 commit 0e8d59e
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 76 deletions.
1 change: 0 additions & 1 deletion src/constants/suggestionModalData.json

This file was deleted.

109 changes: 37 additions & 72 deletions src/controllers/dashBoardController.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const dashboardcontroller = function () {
<p>${actual}</p>
<p>Visual Proof (screenshots, videos, text)</p>
<p>${visual}</p>
<p>Severity/Priority (How Bad is the Bug?</p>
<p>Severity/Priority (How Bad is the Bug?)</p>
<p>${severity}</p>
<p>Thank you,<br />
One Community</p>`;
Expand Down Expand Up @@ -146,58 +146,38 @@ const dashboardcontroller = function () {
}
};

const getSuggestionFilePath = async () => {
// Define a base path based on the process.cwd()
const basePath = process.cwd();
console.log(basePath, "basePath");

// Define the relative path to the JSON file (adjust as needed)
const relativePath = "src/constants/suggestionModalData.json";

// Combine the base path and relative path to create the full path
const fullPath = path.join(basePath, relativePath);

return fullPath;
};

const readSuggestionFile = async () => {
// Specify the absolute path to the JSON file
const filepath = await getSuggestionFilePath();

try {
// Check if the file exists
await fs.access(filepath);

// Read and parse the file
const readfile = await fs.readFile(filepath, "utf8");
const parsedData = JSON.parse(readfile);
return parsedData;
} catch (err) {
console.error("Error reading suggestionModalData.json:", err);
return null; // Handle the error appropriately
}
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",
"Understand people's needs and how we can help them achieve their goals",
"Other",
],
field: [],
};

// create suggestion emailbody
const getsuggestionEmailBody = async (...args) => {
const readfile = await readSuggestionFile();
let fieldaaray = [];
if (readfile.field.length) {
fieldaaray = readfile.field.map(
if (suggestionData.field.length) {
fieldaaray = suggestionData.field.map(
(item) => `<p>${item}</p>
<p>${args[3][item]}</p>`
<p>${args[3][item]}</p>`
);
}
const text = `New Suggestion:
<p>Suggestion Category:</p>
<p>${args[0]}</p>
<p>Suggestion:</p>
<p>${args[1]}</p>
${fieldaaray.length > 0 ? fieldaaray : ""}
<p>Wants Feedback:</p>
<p>${args[2]}</p>
<p>Thank you,<br />
One Community</p>`;
<p>Suggestion Category:</p>
<p>${args[0]}</p>
<p>Suggestion:</p>
<p>${args[1]}</p>
${fieldaaray.length > 0 ? fieldaaray : ""}
<p>Wants Feedback:</p>
<p>${args[2]}</p>
<p>Thank you,<br />
One Community</p>`;

return text;
};
Expand Down Expand Up @@ -225,54 +205,39 @@ const dashboardcontroller = function () {

const getSuggestionOption = async (req, res) => {
try {
const readfile = await readSuggestionFile();
if (readfile) {
res.status(200).send(readfile);
if (suggestionData) {
res.status(200).send(suggestionData);
} else {
res.status(404).send("Suggestion file not found.");
res.status(404).send("Suggestion data not found.");
}
} catch (error) {
console.error("Error reading suggestion file:", error);
console.error("Error getting suggestion data:", error);
res.status(500).send("Internal Server Error");
}
};

// add new suggestion category or field
const editSuggestionOption = async (req, res) => {
try {
// Read the current suggestion data
let readfile = await readSuggestionFile();

if (req.body.suggestion) {
if (req.body.action === "add") {
readfile.suggestion.unshift(req.body.newField);
suggestionData.suggestion.unshift(req.body.newField);
}
if (req.body.action === "delete") {
readfile = {
...readfile,
suggestion: readfile.suggestion.filter(
(item, index) => index + 1 !== +req.body.newField
),
};
suggestionData.suggestion = suggestionData.suggestion.filter(
(item, index) => index + 1 !== +req.body.newField
);
}
} else {
if (req.body.action === "add") {
readfile.field.unshift(req.body.newField);
suggestionData.field.unshift(req.body.newField);
}
if (req.body.action === "delete") {
readfile = {
...readfile,
field: readfile.field.filter((item) => item !== req.body.newField),
};
suggestionData.field = suggestionData.field.filter(
(item) => item !== req.body.newField
);
}
}

// Get the file path
const filepath = await getSuggestionFilePath();

// Write the updated data back to the file
await fs.writeFile(filepath, JSON.stringify(readfile, null, 2));

res.status(200).send("success");
} catch (error) {
console.error("Error editing suggestion option:", error);
Expand Down
41 changes: 38 additions & 3 deletions src/controllers/profileInitialSetupController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const moment = require("moment-timezone");
const jwt = require("jsonwebtoken");
const emailSender = require("../utilities/emailSender");
const config = require("../config");
const cache = require('../utilities/nodeCache')();

// returns the email body that includes the setup link for the recipient.
function sendLinkMessage(Link) {
Expand All @@ -25,7 +26,6 @@ function informManagerMessage(user) {
<p>New User <b style="text-transform: capitalize;">${user.firstName} ${user.lastName}</b> has completed their part of setup.</p>
<p>These areas need to now be completed by an Admin:</p>
<ul style="padding-left: 20px;padding-bottom:10px;">
<li>Weekly Committed Hours</li>
<li>Admin Document</li>
<li>Link to Media Files</li>
<li>Assign Projects</li>
Expand Down Expand Up @@ -57,6 +57,10 @@ function informManagerMessage(user) {
<td><strong>Job Title:</strong></td>
<td>${user.jobTitle}</td>
</tr>
<tr>
<td><strong>Weekly Commited Hours:</strong></td>
<td>${user.weeklycommittedHours}</td>
</tr>
<tr>
<td><strong>Time Zone:</strong></td>
<td>${user.timeZone}</td>
Expand Down Expand Up @@ -87,7 +91,7 @@ const profileInitialSetupController = function (
- Generates a link using the token and emails it to the recipient.
*/
const getSetupToken = async (req, res) => {
let { email, baseUrl } = req.body;
let { email, baseUrl,weeklyCommittedHours } = req.body;
email = email.toLowerCase();
const token = uuidv4();
const expiration = moment().tz("America/Los_Angeles").add(1, "week");
Expand All @@ -103,6 +107,7 @@ const profileInitialSetupController = function (
const newToken = new ProfileInitialSetupToken({
token,
email,
weeklyCommittedHours,
expiration: expiration.toDate(),
});

Expand Down Expand Up @@ -187,7 +192,13 @@ const profileInitialSetupController = function (
newUser.jobTitle = req.body.jobTitle;
newUser.phoneNumber = req.body.phoneNumber;
newUser.bio = "";
newUser.weeklycommittedHours = req.body.weeklycommittedHours;
newUser.weeklycommittedHours = foundToken.weeklyCommittedHours;
newUser.weeklycommittedHoursHistory = [
{
hours: newUser.weeklycommittedHours,
dateChanged: Date.now(),
},
];
newUser.personalLinks = [];
newUser.adminLinks = [];
newUser.teams = Array.from(new Set([]));
Expand All @@ -201,11 +212,17 @@ const profileInitialSetupController = function (
newUser.collaborationPreference = req.body.collaborationPreference;
newUser.timeZone = req.body.timeZone || "America/Los_Angeles";
newUser.location = req.body.location;
newUser.permissions = {
frontPermissions: [],
backPermissions: []
}
newUser.bioPosted = "default";
newUser.privacySettings.email = req.body.privacySettings.email;
newUser.privacySettings.phoneNumber =
req.body.privacySettings.phoneNumber;
newUser.teamCode = "";
newUser.isFirstTimelog = true;

const savedUser = await newUser.save();

emailSender(
Expand All @@ -230,6 +247,24 @@ const profileInitialSetupController = function (
const token = jwt.sign(jwtPayload, JWT_SECRET);

res.send({ token }).status(200);

const NewUserCache = {
permissions: savedUser.permissions,
isActive: true,
weeklycommittedHours: savedUser.weeklycommittedHours,
createdDate: savedUser.createdDate.toISOString(),
_id: savedUser._id,
role: savedUser.role,
firstName: savedUser.firstName,
lastName: savedUser.lastName,
email: savedUser.email,
};

const allUserCache = JSON.parse(cache.getCache("allusers"));
allUserCache.push(NewUserCache);
cache.setCache("allusers", JSON.stringify(allUserCache));


} else {
res.status(400).send("Token is expired");
}
Expand Down
5 changes: 5 additions & 0 deletions src/models/profileInitialSetupToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const profileInitialSetupTokenSchema = new mongoose.Schema({
type: String,
required: true,
},
weeklyCommittedHours : {
type: Number,
required: true,
default: 10,
},
expiration: {
type: Date,
required: true,
Expand Down

0 comments on commit 0e8d59e

Please sign in to comment.