Skip to content

Commit

Permalink
Merge branch 'development' into Xiao-F-Create-way-for-owner-to-edit-u…
Browse files Browse the repository at this point in the history
…pdate-ChatGPT-prompt-text
  • Loading branch information
tsunami776 committed Nov 15, 2023
2 parents fa3b768 + fa2589d commit 8ee7b3b
Show file tree
Hide file tree
Showing 22 changed files with 279 additions and 339 deletions.
155 changes: 0 additions & 155 deletions src/controllers/REAL_TIME_timerController.js

This file was deleted.

3 changes: 3 additions & 0 deletions src/controllers/badgeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const mongoose = require('mongoose');
const UserProfile = require('../models/userProfile');
const { hasPermission } = require('../utilities/permissions');
const escapeRegex = require('../utilities/escapeRegex');
const cache = require('../utilities/nodeCache')();

const badgeController = function (Badge) {
const getAllBadges = async function (req, res) {
Expand Down Expand Up @@ -47,6 +48,8 @@ const badgeController = function (Badge) {
if (result) {
record.badgeCollection = req.body.badgeCollection;

if (cache.hasCache(`user-${userToBeAssigned}`)) cache.removeCache(`user-${userToBeAssigned}`);

record.save()
.then(results => res.status(201).send(results._id))
.catch(errors => res.status(500).send(errors));
Expand Down
24 changes: 12 additions & 12 deletions src/controllers/bmdashboard/bmMaterialsController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose')
const mongoose = require('mongoose');

const bmMaterialsController = function (ItemMaterial) {
const bmMaterialsList = async function _matsList(req, res) {
Expand All @@ -7,42 +7,42 @@ const bmMaterialsController = function (ItemMaterial) {
.populate([
{
path: 'project',
select: '_id projectName'
select: '_id projectName',
},
{
path: 'inventoryItemType',
select: '_id name uom totalStock totalAvailable'
select: '_id name uom totalStock totalAvailable',
},
{
path: 'usageRecord',
populate: {
path: 'createdBy',
select: '_id firstName lastName'
}
select: '_id firstName lastName',
},
},
{
path: 'updateRecord',
populate: {
path: 'createdBy',
select: '_id firstName lastName'
}
select: '_id firstName lastName',
},
},
{
path: 'purchaseRecord',
populate: {
path: 'createdBy',
select: '_id firstName lastName'
}
}
select: '_id firstName lastName',
},
},
])
.exec()
.then(results => res.status(200).send(results))
.catch(error => res.status(500).send(error))
.catch(error => res.status(500).send(error));
} catch (err) {
res.json(err);
}
};
return { bmMaterialsList };
};

module.exports = bmMaterialsController;
module.exports = bmMaterialsController;
79 changes: 79 additions & 0 deletions src/controllers/bmdashboard/bmProjectController.js
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;
39 changes: 25 additions & 14 deletions src/controllers/dashBoardController.js
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');
Expand Down Expand Up @@ -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> &#9913; Suggestion Category:</b>
<p>${args[0]}</p>
<b> &#9913; Suggestion:</b>
<p>${args[1]}</p>
${fieldaaray.length > 0 ? fieldaaray : ""}
<b> &#9913; Name of Suggester:</b>
<p>${args[3].firstName} ${args[3].lastName}</p>
<b> &#9913; Email of Suggester:</b>
<p>${args[4]}</p>
<b> &#9913; 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,
email
);
try {
emailSender(
"[email protected]",
"A new suggestion",
emailBody
emailBody,
null,
null,
email
);
res.status(200).send("Success");
} catch {
Expand Down
Loading

0 comments on commit 8ee7b3b

Please sign in to comment.