Skip to content

Commit

Permalink
Merge branch 'development' into shivansh_custom_blue_tick_email_for_c…
Browse files Browse the repository at this point in the history
…ore_team
  • Loading branch information
shiva2096 authored Sep 17, 2023
2 parents a56b80d + 40e6398 commit e58d436
Show file tree
Hide file tree
Showing 50 changed files with 5,683 additions and 1,917 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
*.css linguist-vendored eol=lf
*.scss linguist-vendored eol=lf
*.js linguist-vendored eol=lf
CHANGELOG.md export-ignore
CHANGELOG.md export-ignore
4,121 changes: 3,447 additions & 674 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
"@types/express": "^4.17.6",
"@types/node": "^8.10.61",
"babel-eslint": "^10.1.0",
"eslint": "^5.9.0",
"eslint": "^8.47.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-import-resolver-babel-module": "^5.3.1",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.33.1",
"eslint-plugin-react-hooks": "^4.6.0",
"lint-staged": "^13.0.3",
"pre-commit": "^1.2.2"
},
Expand Down
1 change: 1 addition & 0 deletions src/constants/suggestionModalData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"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":[]}
24 changes: 13 additions & 11 deletions src/controllers/badgeController.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const mongoose = require('mongoose');
const UserProfile = require('../models/userProfile');
const hasPermission = require('../utilities/permissions');
const { hasPermission } = require('../utilities/permissions');
const escapeRegex = require('../utilities/escapeRegex');

const badgeController = function (Badge) {
const getAllBadges = function (req, res) {
if (!hasPermission(req.body.requestor.role, 'seeBadges')) {
const getAllBadges = async function (req, res) {
if (!await hasPermission(req.body.requestor.role, 'seeBadges')) {
res.status(403).send('You are not authorized to view all badge data.');
return;
}

Badge.find(
{},
'badgeName type multiple weeks months totalHrs people imageUrl category project ranking description',
'badgeName type multiple weeks months totalHrs people imageUrl category project ranking description showReport',
).populate({
path: 'project',
select: '_id projectName',
Expand All @@ -26,7 +26,7 @@ const badgeController = function (Badge) {
};

const assignBadges = async function (req, res) {
if (!hasPermission(req.body.requestor.role, 'assignBadges')) {
if (!await hasPermission(req.body.requestor.role, 'assignBadges')) {
res.status(403).send('You are not authorized to assign badges.');
return;
}
Expand Down Expand Up @@ -56,8 +56,8 @@ const badgeController = function (Badge) {
});
};

const postBadge = function (req, res) {
if (!hasPermission(req.body.requestor.role, 'createBadges')) {
const postBadge = async function (req, res) {
if (!await hasPermission(req.body.requestor.role, 'createBadges')) {
res.status(403).send({ error: 'You are not authorized to create new badges.' });
return;
}
Expand All @@ -82,15 +82,16 @@ const badgeController = function (Badge) {
badge.imageUrl = req.body.imageUrl;
badge.ranking = req.body.ranking;
badge.description = req.body.description;
badge.showReport = req.body.showReport;

badge.save()
.then(results => res.status(201).send(results))
.catch(errors => res.status(500).send(errors));
});
};

const deleteBadge = function (req, res) {
if (!hasPermission(req.body.requestor.role, 'deleteBadges')) {
const deleteBadge = async function (req, res) {
if (!await hasPermission(req.body.requestor.role, 'deleteBadges')) {
res.status(403).send({ error: 'You are not authorized to delete badges.' });
return;
}
Expand All @@ -110,8 +111,8 @@ const badgeController = function (Badge) {
.catch((error) => { res.status(500).send(error); });
};

const putBadge = function (req, res) {
if (!hasPermission(req.body.requestor.role, 'updateBadges')) {
const putBadge = async function (req, res) {
if (!await hasPermission(req.body.requestor.role, 'updateBadges')) {
res.status(403).send({ error: 'You are not authorized to update badges.' });
return;
}
Expand Down Expand Up @@ -139,6 +140,7 @@ const badgeController = function (Badge) {
project: req.body.project,
imageUrl: imageUrl || req.body.imageUrl || req.body.imageURL,
ranking: req.body.ranking,
showReport: req.body.showReport,
};

Badge.findByIdAndUpdate(badgeId, data, (error, record) => {
Expand Down
82 changes: 81 additions & 1 deletion src/controllers/dashBoardController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const mongoose = require('mongoose');
const path = require('path');
const fs = require('fs/promises');
const dashboardhelper = require('../helpers/dashboardhelper')();
const emailSender = require('../utilities/emailSender');

Expand Down Expand Up @@ -83,7 +85,7 @@ const dashboardcontroller = function () {
const {
firstName, lastName, title, environment, reproduction, expected, actual, visual, severity, email,
} = req.body;
const emailBody = getBugReportEmailBody(firstName, lastName, title, environment, reproduction, expected, actual, visual, severity);
const emailBody = getBugReportEmailBody(firstName, lastName, title, environment, reproduction, expected, actual, visual, severity);

try {
emailSender(
Expand All @@ -97,7 +99,82 @@ const dashboardcontroller = function () {
res.status(500).send('Failed');
}
};
// read suggestion data from file
const readSuggestionFile = async () => {
const filepath = path.join(process.cwd(), 'src', 'constants', 'suggestionModalData.json');
let readfile = await fs.readFile(filepath).catch(err => console.log(err));
readfile = JSON.parse(readfile);
return readfile;
};
// create suggestion emailbody
const getsuggestionEmailBody = async (...args) => {
const readfile = await readSuggestionFile();
let fieldaaray = [];
if (readfile.field.length) {
fieldaaray = readfile.field.map(item => `<p>${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>`;

return text;
};

// send suggestion email
const sendMakeSuggestion = async (req, res) => {
const {
suggestioncate, suggestion, confirm, ...rest
} = req.body;
const emailBody = await getsuggestionEmailBody(suggestioncate, suggestion, confirm, rest);
try {
emailSender(
'[email protected]',
'A new suggestion',
emailBody,
);
res.status(200).send('Success');
} catch {
res.status(500).send('Failed');
}
};


const getSuggestionOption = async (req, res) => {
const readfile = await readSuggestionFile();
res.status(200).send(readfile);
};
// add new suggestion category or field
const editSuggestionOption = async (req, res) => {
let readfile = await readSuggestionFile();
if (req.body.suggestion) {
if (req.body.action === 'add') readfile.suggestion.unshift(req.body.newField);
if (req.body.action === 'delete') {
readfile = {
...readfile,
suggestion: readfile.suggestion.filter((item, index) => index + 1 !== +req.body.newField),
};
}
} else {
if (req.body.action === 'add') readfile.field.unshift(req.body.newField);
if (req.body.action === 'delete') {
readfile = {
...readfile,
field: readfile.field.filter(item => item !== req.body.newField),
};
}
}
const filepath = path.join(process.cwd(), 'src', 'constants', 'suggestionModalData.json');
await fs.writeFile(filepath, JSON.stringify(readfile)).catch(err => console.log(err));
res.status(200).send('success');
};

return {
dashboarddata,
Expand All @@ -106,6 +183,9 @@ const dashboardcontroller = function () {
leaderboarddata,
orgData,
sendBugReport,
getSuggestionOption,
editSuggestionOption,
sendMakeSuggestion,
};
};

Expand Down
54 changes: 54 additions & 0 deletions src/controllers/informationController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const mongoose = require('mongoose');
// const userProfile = require('../models/userProfile');
// const hasPermission = require('../utilities/permissions');
const escapeRegex = require('../utilities/escapeRegex');


const informationController = function (Information) {
const getInformations = function (req, res) {
Information.find({}, 'infoName infoContent visibility')
.then(results => res.status(200).send(results))
.catch(error => res.status(404).send(error));
};


const addInformation = function (req, res) {
Information.find({ infoName: { $regex: escapeRegex(req.body.infoName), $options: 'i' } })
.then((result) => {
if (result.length > 0) {
res.status(400).send({ error: `Info Name must be unique. Another infoName with name ${result[0].infoName} already exists. Please note that info names are case insensitive` });
return;
}
const _info = new Information();
_info.infoName = req.body.infoName;
_info.infoContent = req.body.infoContent || 'Unspecified';
_info.visibility = req.body.visibility || '0';
_info.save()
.then(newInformation => res.status(201).send(newInformation))
.catch(error => res.status(400).send(error));
})
.catch(error => res.status(500).send({ error }));
};
const deleteInformation = function (req, res) {
Information.findOneAndDelete({ _id: req.params.id })
.then(deletedInformation => res.status(200).send(deletedInformation))
.catch(error => res.status(400).send(error));
};

// Update existing information by id
const updateInformation = function (req, res) {
Information.findOneAndUpdate({ _id: req.params.id }, req.body, { new: true })
.then(updatedInformation => res.status(200).send(updatedInformation))
.catch(error => res.status(400).send(error));
};

return {
getInformations,
addInformation,
updateInformation,
deleteInformation,
};
};


module.exports = informationController;
Loading

0 comments on commit e58d436

Please sign in to comment.