email notification on message submission working

parent ddf9d638
...@@ -39,14 +39,15 @@ module.exports = { ...@@ -39,14 +39,15 @@ module.exports = {
.then((msg) => { .then((msg) => {
// Send sockets notification // Send sockets notification
sails.sockets.broadcast('studentRoom' + params.id_stu, 'chatmessage', msg.toJSON(), req.socket); sails.sockets.broadcast('studentRoom' + params.id_stu, 'chatmessage', msg.toJSON(), req.socket);
return StuSup.find({id_stu: params.id_stu, id_sup: params.id_sup}).populate('supervisor'); return ([Promise.resolve(msg), StuSup.find({id_stu: params.id_stu}).populate('supervisor')]);
}) })
.then((stusups) => { .spread((msg, stusups) => {
var emails = ""; var emails = "";
for (var i=0; i<stusups.length; i++) { for (var i=0; i<stusups.length; i++) {
if (stusups[i].supervisor.id != params.id_sup) if (stusups[i].supervisor.id !== params.id_sup)
emails += " " + stusups[i].supervisor.email; emails = emails + " " + stusups[i].supervisor.email;
} }
// Email body // Email body
var message = sails.__( var message = sails.__(
{ {
...@@ -54,10 +55,10 @@ module.exports = { ...@@ -54,10 +55,10 @@ module.exports = {
locale: msg.supervisor.lang locale: msg.supervisor.lang
}, },
{ {
stuName: msg.student.name, stuname: msg.student.name,
stuSurname: msg.student.surname, stusurname: msg.student.surname,
supName: msg.supervisor.name, supname: msg.supervisor.name,
supSurname: msg.supervisor.surname, supsurname: msg.supervisor.role == 'office' ? "" : msg.supervisor.surname,
content: msg.content content: msg.content
}); });
...@@ -78,11 +79,10 @@ module.exports = { ...@@ -78,11 +79,10 @@ module.exports = {
.catch((err) => {}); .catch((err) => {});
// Ready, we respond with an Ok! // Ready, we respond with an Ok!
return res.ok(obj); return res.ok(msg);
}) })
.catch((err) => { .catch((err) => {
console.log("Error adding new message: " + err);
return res.serverError('Message not saved'); return res.serverError('Message not saved');
}); });
} }
......
...@@ -500,6 +500,7 @@ ...@@ -500,6 +500,7 @@
"type_your_message_here": "Type your message here", "type_your_message_here": "Type your message here",
"unlink": "Unlink", "unlink": "Unlink",
"up": "Up", "up": "Up",
"unable_to_send_message": "Unable to send message",
"undefined": "Undefined", "undefined": "Undefined",
"unlimited": "Unlimited", "unlimited": "Unlimited",
"update_office": "Update office", "update_office": "Update office",
......
...@@ -496,6 +496,7 @@ ...@@ -496,6 +496,7 @@
"tutor_not_found": "No hay ningún tutor en Pictogram con ese correo electrónico", "tutor_not_found": "No hay ningún tutor en Pictogram con ese correo electrónico",
"tutors": "Tutores", "tutors": "Tutores",
"type_your_message_here": "Escriba el mensaje aquí", "type_your_message_here": "Escriba el mensaje aquí",
"unable_to_send_message": "No se ha podido enviar el mensaje",
"undefined": "Sin definir", "undefined": "Sin definir",
"unlink": "Desvincular", "unlink": "Desvincular",
"unlimited": "Ilimitada", "unlimited": "Ilimitada",
......
...@@ -49,7 +49,7 @@ dashboardControllers.controller('StudentChatCtrl', function StudentInstructionsC ...@@ -49,7 +49,7 @@ dashboardControllers.controller('StudentChatCtrl', function StudentInstructionsC
$scope.$apply(); $scope.$apply();
} }
else else
console.log("Error from API: " + resData); ngToast.danger($translate.instant('unable_to_send_message'));
}); });
}; };
......
...@@ -593,9 +593,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec ...@@ -593,9 +593,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
grid: data grid: data
}, function () {}); }, function () {});
$translate('grid_added').then(function (translation) { ngToast.success($translate.instant('grid_added'));
ngToast.success({ content: translation });
});
$scope.loadGridsList(); $scope.loadGridsList();
......
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
"license_annual": "Pictogram 12-months License", "license_annual": "Pictogram 12-months License",
"license_pro": "Pictogram PRO license", "license_pro": "Pictogram PRO license",
"login": "login", "login": "login",
"new_chat_message": "A new message was sent by {{ supName }} {{ supSurname }} about the student {{ stuName }} {{ stuSurname }}:\n "new_chat_message": "A new message was sent by {{{ supName }}} {{{ supSurname }}} about the student {{{ stuName }}} {{{ stuSurname }}}:\n>>>\n{{{ content }}}\n<<<\n\n -- Pictogram chat service notification",
\" {{ content }} \"\n\n -- Pictogram chat service notification",
"notification_from_pictogram": "Notification from Pictogram", "notification_from_pictogram": "Notification from Pictogram",
"no_name": "No name", "no_name": "No name",
"no_surname": "No surname", "no_surname": "No surname",
......
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
"license_annual": "Pictogram licencia 12 meses", "license_annual": "Pictogram licencia 12 meses",
"license_pro": "Pictogram licencia PRO", "license_pro": "Pictogram licencia PRO",
"login": "acceder", "login": "acceder",
"new_chat_message": "Un nuevo mensaje ha sido enviado por {{ supName }} {{ supSurname }} acerca del estudiante {{ stuName }} {{ stuSurname }}:\n "new_chat_message": "Un nuevo mensaje ha sido enviado por {{{ supname }}} {{{ supsurname }}} acerca del estudiante {{{ stuname }}} {{{ stusurname }}}:\n>>>\n{{{ content }}}\n<<<\n\n -- Notificación del servicio de chat de Pictogram",
\" {{ content }} \"\n\n -- Notificación del servicio de chat de Pictogram",
"notification_from_pictogram": "Notificación desde Pictogram", "notification_from_pictogram": "Notificación desde Pictogram",
"no_name": "Sin nombre", "no_name": "Sin nombre",
"no_surname": "Sin apellidos", "no_surname": "Sin apellidos",
......
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