fixed issue #951

parent a1506b4d
...@@ -260,7 +260,8 @@ module.exports = { ...@@ -260,7 +260,8 @@ module.exports = {
*/ */
create: function (req, res) { create: function (req, res) {
var params = req.params.all(); var params = req.params.all();
var supervisor;
// Send email confirmation // Send email confirmation
function sendConfirmationMail(cb) { function sendConfirmationMail(cb) {
...@@ -316,6 +317,8 @@ module.exports = { ...@@ -316,6 +317,8 @@ module.exports = {
if (!sup) if (!sup)
return res.serverError("Supervisor created but returned null"); return res.serverError("Supervisor created but returned null");
supervisor = sup;
if (params.role === 'therapist_office' || params.role === 'tutor_office') { if (params.role === 'therapist_office' || params.role === 'tutor_office') {
sendConfirmationMail((err) => { sendConfirmationMail((err) => {
if (err) throw err; if (err) throw err;
...@@ -327,16 +330,17 @@ module.exports = { ...@@ -327,16 +330,17 @@ module.exports = {
.then((off) => { .then((off) => {
// link supervisor with office // link supervisor with office
console.log("supervisor: \n" + JSON.stringify(supervisor)); console.log("supervisor: \n" + JSON.stringify(sup));
sup.id_off = off.id; sup.id_off = off.id;
delete sup.password; delete sup.password;
sup.save(); sup.save();
console.log("supervisor: \n" + JSON.stringify(supervisor)); console.log("supervisor: \n" + JSON.stringify(sup));
// set supervisor as admin in the office // set supervisor as admin in the office
off.admin = supervisor.id; off.admin = sup.id;
off.save(); off.save();
supervisor = sup;
sendConfirmationMail((err) => { sendConfirmationMail((err) => {
if (err) throw err; if (err) throw err;
return res.ok(); return res.ok();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment