Skip to content

Commit

Permalink
Merge pull request #623 from OneCommunityGlobal/xiaow_hotfix_of_canno…
Browse files Browse the repository at this point in the history
…t_create_team

XiaoW_Hot fix of cannot create new team
  • Loading branch information
one-community authored Nov 29, 2023
2 parents 662fec3 + 67b764a commit 9ef50eb
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 59 deletions.
96 changes: 49 additions & 47 deletions src/controllers/dashBoardController.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const path = require("path");
const fs = require("fs/promises");
const mongoose = require("mongoose");
const dashboardhelper = require("../helpers/dashboardhelper")();
const emailSender = require("../utilities/emailSender");
const path = require('path');
const fs = require('fs/promises');
const mongoose = require('mongoose');
const dashboardhelper = require('../helpers/dashboardhelper')();
const emailSender = require('../utilities/emailSender');

const dashboardcontroller = function () {
const dashboarddata = function (req, res) {
Expand All @@ -11,7 +11,7 @@ const dashboardcontroller = function () {
const snapshot = dashboardhelper.personaldetails(userId);

snapshot.then((results) => {
res.send(results).status(200);
res.status(200).send(results);
});
};

Expand All @@ -20,13 +20,13 @@ const dashboardcontroller = function () {
const laborthismonth = dashboardhelper.laborthismonth(
userId,
req.params.fromDate,
req.params.toDate
req.params.toDate,
);
laborthismonth.then((results) => {
if (!results || results.length === 0) {
const emptyresult = [
{
projectName: "",
projectName: '',
timeSpent_hrs: 0,
},
];
Expand All @@ -42,10 +42,10 @@ const dashboardcontroller = function () {
const laborthisweek = dashboardhelper.laborthisweek(
userId,
req.params.fromDate,
req.params.toDate
req.params.toDate,
);
laborthisweek.then((results) => {
res.send(results).status(200);
res.status(200).send(results);
});
};

Expand All @@ -63,7 +63,7 @@ const dashboardcontroller = function () {
});
}
})
.catch((error) => res.status(400).send(error));
.catch(error => res.status(400).send(error));
};

const orgData = function (req, res) {
Expand All @@ -73,7 +73,7 @@ const dashboardcontroller = function () {
.then((results) => {
res.status(200).send(results[0]);
})
.catch((error) => res.status(400).send(error));
.catch(error => res.status(400).send(error));
};

const getBugReportEmailBody = function (
Expand All @@ -85,7 +85,7 @@ const dashboardcontroller = function () {
expected,
actual,
visual,
severity
severity,
) {
const text = `New Bug Report From <b>${firstName} ${lastName}</b>:
<p>[Feature Name] Bug Title:</p>
Expand Down Expand Up @@ -130,32 +130,32 @@ const dashboardcontroller = function () {
expected,
actual,
visual,
severity
severity,
);

try {
emailSender(
"[email protected]",
'[email protected]',
`Bug Rport from ${firstName} ${lastName}`,
emailBody,
email
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: [],
};
Expand All @@ -164,8 +164,8 @@ const dashboardcontroller = function () {
let fieldaaray = [];
if (suggestionData.field.length) {
fieldaaray = suggestionData.field.map(
(item) => `<p>${item}</p>
<p>${args[3][item]}</p>`
item => `<p>${item}</p>
<p>${args[3][item]}</p>`,
);
}
const text = `New Suggestion From <b>${args[3].firstName} ${
Expand All @@ -178,7 +178,7 @@ const dashboardcontroller = function () {
<p>${args[0]}</p>
<b> &#9913; Suggestion:</b>
<p>${args[1]}</p>
${fieldaaray.length > 0 ? fieldaaray : ""}
${fieldaaray.length > 0 ? fieldaaray : ''}
<b> &#9913; Name of Suggester:</b>
<p>${args[3].firstName} ${args[3].lastName}</p>
<b> &#9913; Email of Suggester:</b>
Expand All @@ -193,27 +193,29 @@ const dashboardcontroller = function () {

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

Expand All @@ -222,40 +224,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
(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
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');
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/controllers/logincontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const logincontroller = function () {
new: true,
userId: user._id,
};
res.send(result).status(200);
res.status(200).send(result);
} else if (isPasswordMatch && !isNewUser) {
const jwtPayload = {
userid: user._id,
Expand All @@ -57,7 +57,7 @@ const logincontroller = function () {

const token = jwt.sign(jwtPayload, JWT_SECRET);

res.send({ token }).status(200);
res.status(200).send({ token });
} else {
res.status(403).send({
message: 'Invalid password.',
Expand Down
24 changes: 15 additions & 9 deletions src/controllers/teamController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,38 @@ const teamcontroller = function (Team) {
const getAllTeams = function (req, res) {
Team.find({})
.sort({ teamName: 1 })
.then(results => res.send(results).status(200))
.catch(error => res.send(error).status(404));
.then(results => res.status(200).send(results))
.catch(error => res.status(404).send(error));
};
const getTeamById = function (req, res) {
const { teamId } = req.params;

Team.findById(teamId)
.then(results => res.send(results).status(200))
.catch(error => res.send(error).status(404));
.then(results => res.status(200).send(results))
.catch(error => res.status(404).send(error));
};
const postTeam = async function (req, res) {
if (!await hasPermission(req.body.requestor, 'postTeam')) {
res.status(403).send({ error: 'You are not authorized to create teams.' });
return;
}

if (await Team.exists({ teamName: req.body.teamName })) {
res.status(403).send({ error: `Team Name "${req.body.teamName}" already exists` });
return;
}

const team = new Team();

team.teamName = req.body.teamName;
team.isACtive = req.body.isActive;
team.isACtive = true;
team.createdDatetime = Date.now();
team.modifiedDatetime = Date.now();

team
.save()
.then(results => res.send(results).status(200))
.catch(error => res.send(error).status(404));
.then(results => res.status(200).send(results))
.catch(error => res.status(404).send(error));
};
const deleteTeam = async function (req, res) {
if (!await hasPermission(req.body.requestor, 'deleteTeam')) {
Expand All @@ -49,7 +55,7 @@ const teamcontroller = function (Team) {
const deleteteam = record.remove();

Promise.all([removeteamfromprofile, deleteteam])
.then(res.status(200).send({ message: ' Team successfully deleted and user profiles updated' }))
.then(res.status(200).send({ message: 'Team successfully deleted and user profiles updated' }))
.catch((errors) => {
res.status(400).send(errors);
});
Expand Down Expand Up @@ -87,7 +93,7 @@ const teamcontroller = function (Team) {

record
.save()
.then(results => res.status(201).send(results._id))
.then(results => res.status(200).send(results._id))
.catch(errors => res.status(400).send(errors));
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/models/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const team = new Schema({
default: '',
validate: {
validator(v) {
const teamCoderegex = /^([a-zA-Z]-[a-zA-Z]{3}|[a-zA-Z]{5})$/;
const teamCoderegex = /^([a-zA-Z]-[a-zA-Z]{3}|[a-zA-Z]{5})$|^$/;
return teamCoderegex.test(v);
},
message:
Expand Down

0 comments on commit 9ef50eb

Please sign in to comment.