-
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 pull request #989 from OneCommunityGlobal/Abdel-modal-assign-bl…
…ue-square-emails Abdel modal assign blue square emails
- Loading branch information
Showing
5 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
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,67 @@ | ||
const BlueSquareEmailAssignmentController = function (BlueSquareEmailAssignment, userProfile) { | ||
const getBlueSquareEmailAssignment = async function (req, res) { | ||
try { | ||
const assignments = await BlueSquareEmailAssignment.find().populate('assignedTo').exec() | ||
res.status(200).send(assignments); | ||
} catch (error) { | ||
console.log(error) | ||
res.status(500).send(error); | ||
} | ||
}; | ||
|
||
const setBlueSquareEmailAssignment = async function (req, res) { | ||
try { | ||
const { email } = req.body; | ||
|
||
if (!email) { | ||
res.status(400).send('bad request'); | ||
return; | ||
} | ||
|
||
const user = await userProfile.findOne({ email }); | ||
if (!userProfile) { | ||
return res.status(400).send('User profile not found'); | ||
} | ||
|
||
const newAssignment = new BlueSquareEmailAssignment({ | ||
email, | ||
assignedTo: user._id, | ||
}); | ||
await newAssignment.save(); | ||
const assignment = await BlueSquareEmailAssignment.find({email}).populate('assignedTo').exec() | ||
|
||
res.status(200).send(assignment[0]); | ||
} catch (error) { | ||
res.status(500).send(error); | ||
} | ||
}; | ||
|
||
const deleteBlueSquareEmailAssignment = async function (req, res) { | ||
try { | ||
const { id } = req.params; | ||
|
||
if (!id) { | ||
res.status(400).send('bad request'); | ||
return; | ||
} | ||
|
||
const deletedAssignment = await BlueSquareEmailAssignment.findOneAndDelete({ _id: id }); | ||
if (!deletedAssignment) { | ||
res.status(404).send('Assignment not found'); | ||
return; | ||
} | ||
|
||
res.status(200).send({id}); | ||
} catch (error) { | ||
res.status(500).send(error); | ||
} | ||
}; | ||
|
||
return { | ||
getBlueSquareEmailAssignment, | ||
setBlueSquareEmailAssignment, | ||
deleteBlueSquareEmailAssignment, | ||
}; | ||
}; | ||
|
||
module.exports = BlueSquareEmailAssignmentController; |
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 |
---|---|---|
|
@@ -22,6 +22,7 @@ const reportHelper = require('./reporthelper')(); | |
const emailSender = require('../utilities/emailSender'); | ||
const logger = require('../startup/logger'); | ||
const token = require('../models/profileInitialSetupToken'); | ||
const BlueSquareEmailAssignment = require('../models/BlueSquareEmailAssignment'); | ||
const cache = require('../utilities/nodeCache')(); | ||
const timeOffRequest = require('../models/timeOffRequest'); | ||
const notificationService = require('../services/notificationService'); | ||
|
@@ -726,11 +727,27 @@ const userHelper = function () { | |
administrativeContent, | ||
); | ||
} | ||
|
||
let emailsBCCs; | ||
const blueSquareBCCs = await BlueSquareEmailAssignment.find() | ||
.populate('assignedTo') | ||
.exec(); | ||
if (blueSquareBCCs.length > 0) { | ||
emailsBCCs = blueSquareBCCs.map((assignment) => { | ||
if (assignment.assignedTo.isActive === true) { | ||
return assignment.email | ||
} | ||
}); | ||
} else { | ||
emailsBCCs = null; | ||
} | ||
|
||
|
||
emailSender( | ||
status.email, | ||
'New Infringement Assigned', | ||
emailBody, | ||
null, | ||
emailsBCCs, | ||
'[email protected]', | ||
status.email, | ||
null, | ||
|
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,10 @@ | ||
const mongoose = require("mongoose"); | ||
|
||
const { Schema } = mongoose; | ||
|
||
const BlueSquareEmailAssignmentSchema = new Schema({ | ||
email: { type: String, required: true, unique: true }, | ||
assignedTo: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile', required: true } | ||
}); | ||
|
||
module.exports = mongoose.model("BlueSquareEmailAssignment", BlueSquareEmailAssignmentSchema, "BlueSquareEmailAssignments"); |
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,18 @@ | ||
const express = require('express'); | ||
|
||
const routes = function (BlueSquareEmailAssignment,userProfile) { | ||
const BlueSquareEmailAssignmentRouter = express.Router(); | ||
const controller = require('../controllers/BlueSquareEmailAssignmentController')(BlueSquareEmailAssignment,userProfile); | ||
|
||
BlueSquareEmailAssignmentRouter.route('/AssignBlueSquareEmail') | ||
.get(controller.getBlueSquareEmailAssignment) | ||
.post(controller.setBlueSquareEmailAssignment) | ||
|
||
BlueSquareEmailAssignmentRouter.route('/AssignBlueSquareEmail/:id') | ||
.delete(controller.deleteBlueSquareEmailAssignment); | ||
|
||
|
||
return BlueSquareEmailAssignmentRouter; | ||
}; | ||
|
||
module.exports = routes; |
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