Skip to content
This repository has been archived by the owner on Sep 3, 2020. It is now read-only.

Code Challenge, Response to "Notification of Assignment of Opportunity #251" #306

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions modules/core/server/email_templates/opportunity-assigned-body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{#markdown this}}
![BC Dev Exchange](https://bcdevexchange.org/modules/core/client/img/logo/new-logo-220px.png)

### An opportunity has been assigned

[See the details for {{ data.opportunity.name }}]({{ data.domain }}/opportunities/cwu/{{ data.opportunity.code }})

Unique ID: {{ data.opportunity.id }}
Vendor's legal name: {{ data.vendor.name }}
Vendor's legal address: {{ data.vendor.address }}
Vendor's business number: {{ data.vendor.business_number }}
Contact (email): {{ data.vendor.email }}


-----------------------------
BC Developers' Exchange and DevOps
Ministry of Technology, Innovation and Citizens' Services
[BCDevExchange.org](http://bcdevexchange.org)
{{/markdown}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Opportunity {{data.opportunity.name}} has been assigned
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,22 @@
function (response) {
ppp.proposal = response;
Notification.success({ message: '<i class="fa fa-3x fa-check-circle"></i> Company has been assigned'});
if (ppp.opportunity.opportunityTypeCd === 'sprint-with-us') {
$state.go ('opportunities.viewswu',{opportunityId:ppp.opportunity.code});
} else {
$state.go ('opportunities.viewcwu',{opportunityId:ppp.opportunity.code});
}
// NB: I would have thought that kicking off the notification to branch financial staff
// would be something that should be done on the server side (proposals.server.controller).
// I have however placed the logic here due to the specific request: "Ensure that you use a
// REST endpoint to send the email notification"
ProposalsService.notifyBranchFinancialStaff({_id: ppp.proposal._id})
.$promise
.then()
.finally(function() {
// By placing this section in "finally", we ensure that the flow won't
// be interrupted by a failure to send a notification email.
if (ppp.opportunity.opportunityTypeCd === 'sprint-with-us') {
$state.go ('opportunities.viewswu',{opportunityId:ppp.opportunity.code});
} else {
$state.go ('opportunities.viewcwu',{opportunityId:ppp.opportunity.code});
}
});
},
function (error) {
Notification.error ({ message: error.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Proposal Assignment failed!' });
Expand Down
4 changes: 4 additions & 0 deletions modules/proposals/client/services/proposals.client.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
method: 'PUT',
url: '/api/assign/proposal/:proposalId'
},
notifyBranchFinancialStaff: {
method: 'PUT',
url: '/api/assign/proposal/:proposalId/notifyFinance'
},
forOpportunity: {
method: 'GET',
url: '/api/proposals/for/opportunity/:opportunityId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,71 @@ exports.assign = function (req, res) {
.then (function () {
return Opportunities.assign (proposal.opportunity._id, proposal._id, proposal.user, req.user);
})
// Note: I would have placed the call to Notify Branch Financial Staff Opportunities
// here if not for the specific instruction to hit a REST service. Doing something as
// follows:
// .then (function () {
// notifyBranchFinancialStaff({...blah blah...});
// })
// It doesn't make sense to me to break back to a REST service at this point, so I'm
// assuming it's wanted in the front end.
.then (function () {res.json (proposal); })
.catch (function (e) {res.status(422).send ({ message: errorHandler.getErrorMessage(e) }); });
};
exports.notifyBranchFinancialStaff = function (req, res) {
Proposal.findById(req.params.proposalId)
.populate('user')
.populate('opportunity')
.exec(function (err, proposal) {
if (err) {
res.status(500).send({ message: errorHandler.getErrorMessage(err)});
}
else if (!proposal) {
res.status(404).send({ message: 'Could not load proposal ' + req.params.proposalId});
}
else {
var data = {
useremail: '[email protected]', // TODO: Assumes https://github.com/BCDevExchange/devex/issues/236 has been completed.
opportunity: {
name: proposal.opportunity.name,
id: proposal.opportunity._id,
code: proposal.opportunity.code
},
vendor: proposal.isCompany ?
{
name: proposal.businessName,
address: proposal.businessAddress,
business_number: proposal.businessContactPhone,
email: proposal.businessContactEmail
} :
{
name: proposal.user.firstName + ' ' + proposal.user.lastName,
address: proposal.user.address,
business_number: proposal.user.phone,
email: proposal.user.email
}
}
try {
Notifications.notifyUserAdHoc('opportunity-assigned', data).then(
function(success) {
console.log(success);
res.json({}).send();
},
function(error) {
console.log('error', error);
res.status(500).send(error);
}
).catch(function (e) {
res.status(500).send({ message: errorHandler.getErrorMessage(e) });
});
} catch (e) {
res.status(500).send({ message: errorHandler.getErrorMessage(e) });
}
}
}).catch(function (e) {
res.status(500).send({ message: errorHandler.getErrorMessage(e) });
});
};
// -------------------------------------------------------------------------
//
// unassign gets called from the opportunity side, so just do the work
Expand Down
3 changes: 3 additions & 0 deletions modules/proposals/server/policies/proposals.server.policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ exports.invokeRolesPolicies = function () {
}, {
resources: '/api/proposals/:proposalId',
permissions: '*'
}, {
resources: '/api/assign/proposal/:proposalId/notifyFinance',
permissions: '*'
}]
}, {
roles: ['user'],
Expand Down
2 changes: 2 additions & 0 deletions modules/proposals/server/routes/proposals.server.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module.exports = function(app) {
.put(proposals.submit);
app.route('/api/assign/proposal/:proposalId').all(proposalsPolicy.isAllowed)
.put(proposals.assign);
app.route('/api/assign/proposal/:proposalId/notifyFinance').all(proposalsPolicy.isAllowed)
.put(proposals.notifyBranchFinancialStaff)
//
// proposals for opportunity
//
Expand Down