-
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 branch 'development' into Xiao-F-Create-way-for-owner-to-edit-u…
…pdate-ChatGPT-prompt-text
- Loading branch information
Showing
22 changed files
with
279 additions
and
339 deletions.
There are no files selected for viewing
This file was deleted.
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
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// TODO: uncomment when executing auth checks | ||
// const jwt = require('jsonwebtoken'); | ||
// const config = require('../../config'); | ||
|
||
const bmMProjectController = function (BuildingProject) { | ||
// TODO: uncomment when executing auth checks | ||
// const { JWT_SECRET } = config; | ||
|
||
const fetchAllProjects = async (req, res) => { | ||
//! Note: for easier testing this route currently returns all projects from the db | ||
// TODO: uncomment the lines below to return only projects where field buildingManager === userid | ||
// const token = req.headers.authorization; | ||
// const { userid } = jwt.verify(token, JWT_SECRET); | ||
try { | ||
const projectData = await BuildingProject | ||
// TODO: uncomment this line to filter by buildingManager field | ||
// .find({ buildingManager: userid }) | ||
.find() | ||
.populate([ | ||
{ | ||
path: 'buildingManager', | ||
select: '_id firstName lastName email', | ||
}, | ||
{ | ||
path: 'team', | ||
select: '_id firstName lastName email', | ||
}, | ||
]) | ||
.exec() | ||
.then(result => result) | ||
.catch(error => res.status(500).send(error)); | ||
res.status(200).send(projectData); | ||
} catch (err) { | ||
res.json(err); | ||
} | ||
}; | ||
|
||
// fetches single project by project id | ||
const fetchSingleProject = async (req, res) => { | ||
//! Note: for easier testing this route currently returns the project without an auth check | ||
// TODO: uncomment the lines below to check the user's ability to view the current project | ||
// const token = req.headers.authorization; | ||
// const { userid } = jwt.verify(token, JWT_SECRET); | ||
const { projectId } = req.params; | ||
try { | ||
BuildingProject | ||
.findById(projectId) | ||
.populate([ | ||
{ | ||
path: 'buildingManager', | ||
select: '_id firstName lastName email', | ||
}, | ||
{ | ||
path: 'team', | ||
select: '_id firstName lastName email', | ||
}, | ||
]) | ||
.exec() | ||
.then(project => res.status(200).send(project)) | ||
// TODO: uncomment this block to execute the auth check | ||
// authenticate request by comparing userId param with buildingManager id field | ||
// Note: _id has type object and must be converted to string | ||
// .then((project) => { | ||
// if (userid !== project.buildingManager._id.toString()) { | ||
// return res.status(403).send({ | ||
// message: 'You are not authorized to view this record.', | ||
// }); | ||
// } | ||
// return res.status(200).send(project); | ||
// }) | ||
.catch(error => res.status(500).send(error)); | ||
} catch (err) { | ||
res.json(err); | ||
} | ||
}; | ||
return { fetchAllProjects, fetchSingleProject }; | ||
}; | ||
|
||
module.exports = bmMProjectController; |
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,6 +1,6 @@ | ||
const mongoose = require("mongoose"); | ||
const path = require("path"); | ||
const fs = require("fs/promises"); | ||
const mongoose = require("mongoose"); | ||
const dashboardhelper = require("../helpers/dashboardhelper")(); | ||
const emailSender = require("../utilities/emailSender"); | ||
const DashboardData = require('../models/dashBoardData'); | ||
|
@@ -202,34 +202,45 @@ const dashboardcontroller = function () { | |
<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>`; | ||
const text = `New Suggestion From <b>${args[3].firstName} ${ | ||
args[3].lastName | ||
} | ||
</b>: | ||
<b> ⚹ Suggestion Category:</b> | ||
<p>${args[0]}</p> | ||
<b> ⚹ Suggestion:</b> | ||
<p>${args[1]}</p> | ||
${fieldaaray.length > 0 ? fieldaaray : ""} | ||
<b> ⚹ Name of Suggester:</b> | ||
<p>${args[3].firstName} ${args[3].lastName}</p> | ||
<b> ⚹ Email of Suggester:</b> | ||
<p>${args[4]}</p> | ||
<b> ⚹ Wants Feedback:</b> | ||
<p>${args[2]}</p> | ||
<b>Thank you,<br /> | ||
One Community</b>`; | ||
|
||
return text; | ||
}; | ||
|
||
// send suggestion email | ||
const sendMakeSuggestion = async (req, res) => { | ||
const { suggestioncate, suggestion, confirm, ...rest } = req.body; | ||
const { suggestioncate, suggestion, confirm, email, ...rest } = req.body; | ||
const emailBody = await getsuggestionEmailBody( | ||
suggestioncate, | ||
suggestion, | ||
confirm, | ||
rest | ||
rest, | ||
); | ||
try { | ||
emailSender( | ||
"[email protected]", | ||
"A new suggestion", | ||
emailBody | ||
emailBody, | ||
null, | ||
null, | ||
); | ||
res.status(200).send("Success"); | ||
} catch { | ||
|
Oops, something went wrong.